Skip to content

Commit

Permalink
serde deserializaion support
Browse files Browse the repository at this point in the history
mdt safi (multicast distribution tree) added
Multiple addpath capabilities fixed
clippy fixes
  • Loading branch information
wladwm committed Oct 8, 2022
1 parent 85d8e21 commit 62a140e
Show file tree
Hide file tree
Showing 45 changed files with 1,844 additions and 1,160 deletions.
16 changes: 13 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
### 0.2.1 (2021-08-01)
### 0.3.0 (2022-10-08)

#### Features

* serde deserializaion support
* mdt safi (multicast distribution tree) added

#### Fixes

* Multiple addpath capabilities fixed
* clippy fixes

### 0.2.1 (2021-08-01)

#### Features

* multiple AddPath capabilities support

### 0.2.0 (2021-07-25)

Expand All @@ -12,7 +23,6 @@
* afi::BgpNet support for MAC prefixes
* extcommunity varieties extended


### 0.1.5 (2021-07-19)

#### Features
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zettabgp"
version = "0.2.1"
version = "0.3.0"
authors = ["Vladimir Melnikov <wlad.w.m@gmail.com>"]
edition = "2018"
license = "MIT OR Apache-2.0"
Expand All @@ -17,5 +17,5 @@ serialization = ["serde"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serde = { version="1.0.125", optional = true }
serde = { version="1.0.125", features = ["derive"], optional = true }

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ BMP - BGP Monitoring Protocol version 3.
* ipv4 labeled-unicast
* ipv4 multicast
* ipv4 mvpn
* ipv4 mdt
* vpnv4 unicast
* vpnv4 multicast
* ipv6 unicast
* ipv6 labeled-unicast
* ipv6 multicast
* ipv6 mdt
* vpnv6 unicast
* vpnv6 multicast
* vpls
Expand All @@ -47,6 +49,7 @@ BMP - BGP Monitoring Protocol version 3.
* Cluster list
* Originator ID
* Attribute set
* Connector
* some PMSI tunnels

## Usage
Expand Down
107 changes: 18 additions & 89 deletions src/afi/evpn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@
//! This module describes NLRI data structures for evpn https://tools.ietf.org/html/rfc7432

use crate::afi::*;
#[cfg(feature = "serialization")]
use serde::{Deserialize, Serialize};

//EVPN ESI field
///EVPN ESI field
#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[cfg(feature = "serialization")]
#[derive(Serialize, Deserialize)]
#[serde(transparent)]
pub struct EVPNESI {
pub v: Vec<u8>,
}
Expand All @@ -23,7 +28,7 @@ impl EVPNESI {
EVPNESI { v: src.to_vec() }
}
pub fn is_zero(&self) -> bool {
self.v.iter().find(|x| (**x) != 0).is_none()
!self.v.iter().any(|x| (*x) != 0)
}
}
impl std::fmt::Display for EVPNESI {
Expand All @@ -40,6 +45,8 @@ impl std::fmt::Display for EVPNESI {
}
//EVPN Ethernet Auto-Discovery (A-D) route
#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[cfg(feature = "serialization")]
#[derive(Serialize, Deserialize)]
pub struct BgpEVPN1 {
pub rd: BgpRD,
pub esi_type: u8,
Expand Down Expand Up @@ -84,6 +91,8 @@ impl std::fmt::Display for BgpEVPN1 {

//EVPN MAC/IP Advertisement Route
#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[cfg(feature = "serialization")]
#[derive(Serialize, Deserialize)]
pub struct BgpEVPN2 {
pub rd: BgpRD,
pub esi_type: u8,
Expand Down Expand Up @@ -201,6 +210,8 @@ impl std::fmt::Display for BgpEVPN2 {

#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
// EVPN Inclusive Multicast Ethernet Tag route
#[cfg(feature = "serialization")]
#[derive(Serialize, Deserialize)]
pub struct BgpEVPN3 {
pub rd: BgpRD,
pub ether_tag: u32,
Expand Down Expand Up @@ -246,8 +257,10 @@ impl std::fmt::Display for BgpEVPN3 {
}
}

/// EVPN Ethernet Segment Route
#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
// EVPN Ethernet Segment Route
#[cfg(feature = "serialization")]
#[derive(Serialize, Deserialize)]
pub struct BgpEVPN4 {
pub rd: BgpRD,
pub esi_type: u8,
Expand Down Expand Up @@ -300,6 +313,8 @@ impl std::fmt::Display for BgpEVPN4 {

/// EVPN route NLRI
#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[cfg(feature = "serialization")]
#[derive(Serialize, Deserialize)]
pub enum BgpEVPN {
EVPN1(BgpEVPN1),
EVPN2(BgpEVPN2),
Expand Down Expand Up @@ -354,89 +369,3 @@ impl BgpAddrItem<BgpEVPN> for BgpEVPN {
unimplemented!();
}
}

#[cfg(feature = "serialization")]
impl serde::Serialize for EVPNESI {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
let mut state = serializer.serialize_seq(Some(self.v.len()))?;
for l in self.v.iter() {
state.serialize_element(&l)?;
}
state.end()
}
}

#[cfg(feature = "serialization")]
impl serde::Serialize for BgpEVPN1 {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
let mut state = serializer.serialize_struct("BgpEVPN1", 5)?;
state.serialize_field("rd", &self.rd)?;
state.serialize_field("esi_type", &self.esi_type)?;
state.serialize_field("esi", &self.esi)?;
state.serialize_field("ether_tag", &self.ether_tag)?;
state.serialize_field("labels", &self.labels)?;
state.end()
}
}

#[cfg(feature = "serialization")]
impl serde::Serialize for BgpEVPN2 {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
let mut state = serializer.serialize_struct("BgpEVPN2", 7)?;
state.serialize_field("rd", &self.rd)?;
state.serialize_field("esi_type", &self.esi_type)?;
state.serialize_field("esi", &self.esi)?;
state.serialize_field("ether_tag", &self.ether_tag)?;
state.serialize_field("mac", &self.mac)?;
state.serialize_field("ip", &self.ip)?;
state.serialize_field("labels", &self.labels)?;
state.end()
}
}

#[cfg(feature = "serialization")]
impl serde::Serialize for BgpEVPN3 {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
let mut state = serializer.serialize_struct("BgpEVPN3", 3)?;
state.serialize_field("rd", &self.rd)?;
state.serialize_field("ether_tag", &self.ether_tag)?;
state.serialize_field("ip", &self.ip)?;
state.end()
}
}

#[cfg(feature = "serialization")]
impl serde::Serialize for BgpEVPN4 {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
let mut state = serializer.serialize_struct("BgpEVPN4", 4)?;
state.serialize_field("rd", &self.rd)?;
state.serialize_field("esi_type", &self.esi_type)?;
state.serialize_field("esi", &self.esi)?;
state.serialize_field("ip", &self.ip)?;
state.end()
}
}
#[cfg(feature = "serialization")]
impl serde::Serialize for BgpEVPN {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(format!("{}", self).as_str())
}
}
Loading

0 comments on commit 62a140e

Please sign in to comment.