- let _ = sender.try_send(Message::Open(Open {
- version: 4,
- peer_asn: 23456,
- hold_timer: 120,
- identifier: 0x453b1215, // 69.59.18.21
- parameters: vec![OpenParameter::Capabilities(vec![
- OpenCapability::MultiProtocol((AFI::IPV4, SAFI::Unicast)),
- OpenCapability::MultiProtocol((AFI::IPV6, SAFI::Unicast)),
- OpenCapability::FourByteASN(397444),
- OpenCapability::RouteRefresh,
- OpenCapability::AddPath(vec![
- (AFI::IPV4, SAFI::Unicast, AddPathDirection::ReceivePaths),
- (AFI::IPV6, SAFI::Unicast, AddPathDirection::ReceivePaths)]),
- ])]
- }));
- read.for_each(move |bgp_msg| {
- if client.shutdown.load(Ordering::Relaxed) {
- return future::err(std::io::Error::new(std::io::ErrorKind::Other, "Shutting Down"));
- }
- match bgp_msg {
- Message::Open(_) => {
- printer.add_line("Connected to BGP route provider".to_string(), true);
- },
- Message::KeepAlive => {
- let _ = sender.try_send(Message::KeepAlive);
- },
- Message::Update(mut upd) => {
- upd.normalize();
- let mut route_table = client.routes.lock().unwrap();
- for r in upd.withdrawn_routes {
- route_table.withdraw(r);
- }
- if let Some(path) = Self::map_attrs(upd.attributes) {
- let path_arc = Arc::new(path);
- for r in upd.announced_routes {
- route_table.announce(r, Arc::clone(&path_arc));
+ TimeoutStream::new_persistent(read, timeout).for_each(move |bgp_msg| {
+ if client.shutdown.load(Ordering::Relaxed) {
+ return future::err(std::io::Error::new(std::io::ErrorKind::Other, "Shutting Down"));
+ }
+ match bgp_msg {
+ Message::Open(_) => {
+ client.routes.lock().unwrap().v4_table.clear();
+ client.routes.lock().unwrap().v6_table.clear();
+ printer.add_line("Connected to BGP route provider".to_string(), false);
+ },
+ Message::KeepAlive => {
+ let _ = sender.try_send(Message::KeepAlive);
+ },
+ Message::Update(mut upd) => {
+ upd.normalize();
+ let mut route_table = client.routes.lock().unwrap();
+ for r in upd.withdrawn_routes {
+ route_table.withdraw(r);
+ }
+ if let Some(path) = Self::map_attrs(upd.attributes) {
+ for r in upd.announced_routes {
+ route_table.announce(r, path.clone());
+ }