This commit is contained in:
@ -81,6 +81,8 @@ message AnnouncementRequest {
|
||||
string peer_name = 1;
|
||||
Prefix prefix = 2;
|
||||
repeated string large_communities = 3;
|
||||
// When set to true inserts the route, when set to false withdraws the route.
|
||||
bool add = 4;
|
||||
}
|
||||
|
||||
message AnnouncementResponse {}
|
||||
|
||||
66
crates/route_client/src/connector.rs
Normal file
66
crates/route_client/src/connector.rs
Normal file
@ -0,0 +1,66 @@
|
||||
use std::str::FromStr;
|
||||
use std::time::Duration;
|
||||
|
||||
use bgp_packet::nlri::NLRI;
|
||||
use eyre::Result;
|
||||
use tonic::transport::{Channel, Endpoint, Uri};
|
||||
|
||||
use crate::proto::bgp_server_admin_service_client::BgpServerAdminServiceClient;
|
||||
use crate::proto::{AnnouncementRequest, Prefix};
|
||||
|
||||
pub struct Connector {
|
||||
client: BgpServerAdminServiceClient<Channel>,
|
||||
}
|
||||
|
||||
impl Connector {
|
||||
pub async fn new(addr: String) -> Result<Self> {
|
||||
let uri = Uri::from_str(addr.as_str()).unwrap();
|
||||
let endpoint = Endpoint::from(uri).keep_alive_timeout(Duration::from_secs(10));
|
||||
let client = BgpServerAdminServiceClient::connect(endpoint).await?;
|
||||
Ok(Self { client })
|
||||
}
|
||||
|
||||
pub async fn send_announce(&mut self, peer_name: String, prefix: NLRI) -> Result<()> {
|
||||
let request = AnnouncementRequest {
|
||||
peer_name,
|
||||
prefix: Some(Prefix {
|
||||
ip_prefix: prefix.prefix,
|
||||
prefix_len: prefix.prefixlen as i32,
|
||||
address_family: match prefix.afi {
|
||||
bgp_packet::constants::AddressFamilyIdentifier::Ipv4 => {
|
||||
crate::proto::AddressFamily::IPv4.into()
|
||||
}
|
||||
bgp_packet::constants::AddressFamilyIdentifier::Ipv6 => {
|
||||
crate::proto::AddressFamily::IPv6.into()
|
||||
}
|
||||
},
|
||||
}),
|
||||
large_communities: vec![],
|
||||
add: true,
|
||||
};
|
||||
self.client.announce_to_peer(request).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn send_withdraw(&mut self, peer_name: String, prefix: NLRI) -> Result<()> {
|
||||
let request = AnnouncementRequest {
|
||||
peer_name,
|
||||
prefix: Some(Prefix {
|
||||
ip_prefix: prefix.prefix,
|
||||
prefix_len: prefix.prefixlen as i32,
|
||||
address_family: match prefix.afi {
|
||||
bgp_packet::constants::AddressFamilyIdentifier::Ipv4 => {
|
||||
crate::proto::AddressFamily::IPv4.into()
|
||||
}
|
||||
bgp_packet::constants::AddressFamilyIdentifier::Ipv6 => {
|
||||
crate::proto::AddressFamily::IPv6.into()
|
||||
}
|
||||
},
|
||||
}),
|
||||
large_communities: vec![],
|
||||
add: false,
|
||||
};
|
||||
self.client.announce_to_peer(request).await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@ -12,6 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
pub mod connector;
|
||||
pub mod fib_state;
|
||||
pub mod netlink;
|
||||
pub mod southbound_interface;
|
||||
|
||||
@ -43,24 +43,16 @@ pub trait SouthboundInterface {
|
||||
|
||||
/// DummyVerifier is a SouthboundInterface that checks that routes are not added more than
|
||||
/// once and not removed when there are none.
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Default)]
|
||||
pub struct DummyVerifier {
|
||||
route_state: HashMap<NLRI, IpAddr>,
|
||||
}
|
||||
|
||||
impl std::default::Default for DummyVerifier {
|
||||
fn default() -> DummyVerifier {
|
||||
DummyVerifier {
|
||||
route_state: HashMap::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl SouthboundInterface for DummyVerifier {
|
||||
async fn get_all_routes(
|
||||
&mut self,
|
||||
address_family: AddressFamilyIdentifier,
|
||||
_address_family: AddressFamilyIdentifier,
|
||||
) -> Result<Vec<(NLRI, IpAddr)>> {
|
||||
todo!();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user