Cleanup clippy warnings.
Some checks failed
Rust / build (push) Has been cancelled

This commit is contained in:
Rayhaan Jaufeerally
2024-12-08 22:09:00 +00:00
parent cc3842b384
commit b0f2995ed8
18 changed files with 1547 additions and 189 deletions

View File

@ -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 {}

View 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(())
}
}

View File

@ -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;

View File

@ -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!();
}