File tree Expand file tree Collapse file tree 3 files changed +20
-6
lines changed
Expand file tree Collapse file tree 3 files changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ k8s-intf = { workspace = true }
1616
1717# external
1818derive_builder = { workspace = true , default-features = false , features = [" default" ] }
19+ ipnet = { workspace = true }
1920linkme = { workspace = true }
2021multi_index_map = { workspace = true , features = [" serde" ] }
2122ordermap = { workspace = true , features = [" std" ] }
Original file line number Diff line number Diff line change 11// SPDX-License-Identifier: Apache-2.0
22// Copyright Open Network Fabric Authors
33
4- use std:: net:: { IpAddr , Ipv4Addr } ;
4+ use std:: net:: IpAddr ;
55
6+ use ipnet:: Ipv4Net ;
67use k8s_intf:: gateway_agent_crd:: GatewayAgentGateway ;
78use lpm:: prefix:: { Prefix , PrefixString } ;
89use net:: eth:: mac:: SourceMac ;
@@ -97,9 +98,14 @@ fn add_bgp_config(
9798 "Gateway protocol IP not specified" . to_string ( ) ,
9899 ) ) ?;
99100
100- let router_id = protocol_ip. parse :: < Ipv4Addr > ( ) . map_err ( |e| {
101- FromK8sConversionError :: ParseError ( format ! ( "Invalid protocol IP {protocol_ip}: {e}" ) )
102- } ) ?;
101+ let router_id = protocol_ip
102+ . parse :: < Ipv4Net > ( )
103+ . map_err ( |e| {
104+ FromK8sConversionError :: ParseError ( format ! (
105+ "Invalid IPv4 protocol IP {protocol_ip}: {e}"
106+ ) )
107+ } ) ?
108+ . addr ( ) ;
103109
104110 let vtep_ip_raw = gateway
105111 . vtep_ip
@@ -190,7 +196,10 @@ mod test {
190196 // Check BGP configuration
191197 assert_eq ! ( gateway. asn, Some ( bgp_config. asn) ) ;
192198 assert_eq ! (
193- gateway. protocol_ip,
199+ gateway
200+ . protocol_ip
201+ . as_ref( )
202+ . map( |v| v. split( '/' ) . next( ) . unwrap( ) . to_string( ) ) ,
194203 bgp_config. router_id. map( |v| v. to_string( ) )
195204 ) ;
196205 let Some ( af_ipv4unicast) = bgp_config. af_ipv4unicast else {
Original file line number Diff line number Diff line change @@ -40,7 +40,11 @@ impl TypeGenerator for LegalValue<GatewayAgentGateway> {
4040 interfaces : Some ( interfaces) . filter ( |i| !i. is_empty ( ) ) ,
4141 neighbors : Some ( neighbors) . filter ( |n| !n. is_empty ( ) ) ,
4242 profiling : None , // FIXME(manishv) Add a proper implementation
43- protocol_ip : Some ( d. produce :: < UnicastIpv4Addr > ( ) ?. to_string ( ) ) ,
43+ protocol_ip : Some ( format ! (
44+ "{}/{}" ,
45+ d. produce:: <UnicastIpv4Addr >( ) ?,
46+ d. gen_u8( Bound :: Included ( & 0 ) , Bound :: Included ( & 32 ) ) ?
47+ ) ) ,
4448 vtep_ip : Some ( format ! (
4549 "{}/{}" ,
4650 d. produce:: <UnicastIpv4Addr >( ) ?,
You can’t perform that action at this time.
0 commit comments