Skip to content

Commit

Permalink
routing: introduce static routes implementation
Browse files Browse the repository at this point in the history
Example configuration (using the CLI):
```
routing control-plane-protocols control-plane-protocol ietf-routing:static main
 !
 static-routes ipv4 route 172.16.1.0/24
  next-hop outgoing-interface eth-rt2
  next-hop next-hop-address 10.0.1.2
 !
 static-routes ipv4 route 172.16.2.0/24
  !
  next-hop next-hop-list next-hop 1
   outgoing-interface eth-rt2
   next-hop-address 10.0.1.2
  !
  next-hop next-hop-list next-hop 2
   outgoing-interface eth-rt3
   next-hop-address 10.0.2.3
  !
 !
 static-routes ipv4 route 172.16.3.0/24
  next-hop special-next-hop blackhole
 !
!
```

Currently, setting the administrative distance in static routes is
not supported.

Signed-off-by: Renato Westphal <[email protected]>
  • Loading branch information
rwestphal committed Nov 4, 2023
1 parent 980f5af commit 7066fed
Show file tree
Hide file tree
Showing 10 changed files with 473 additions and 17 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ Holo supports the following IETF RFCs and Internet drafts:
| ietf-bfd@2022-09-22 | 100.00% | 100.00% | - | - | [100.00%](http://westphal.com.br/holo/ietf-bfd.html) |
| ietf-interfaces@2018-01-09 | 100.00% | 0.00% | - | - | [22.22%](http://westphal.com.br/holo/ietf-interfaces.html) |
| ietf-ip@2018-01-09 | 17.39% | 0.00% | - | - | [13.33%](http://westphal.com.br/holo/ietf-ip.html) |
| ietf-ipv4-unicast-routing@2018-03-13 | 0.00% | 100.00% | - | - | [18.75%](http://westphal.com.br/holo/ietf-ipv4-unicast-routing.html) |
| ietf-ipv6-unicast-routing@2018-03-13 | 0.00% | 100.00% | - | - | [8.57%](http://westphal.com.br/holo/ietf-ipv6-unicast-routing.html) |
| ietf-ipv4-unicast-routing@2018-03-13 | 100.00% | 100.00% | - | - | [100.00%](http://westphal.com.br/holo/ietf-ipv4-unicast-routing.html) |
| ietf-ipv6-unicast-routing@2018-03-13 | 40.62% | 100.00% | - | - | [45.71%](http://westphal.com.br/holo/ietf-ipv6-unicast-routing.html) |
| ietf-key-chain@2017-04-18 | 100.00% | 100.00% | - | - | [100.00%](http://westphal.com.br/holo/ietf-key-chain.html) |
| ietf-mpls-ldp@2022-03-14 | 86.96% | 92.31% | 100.00% | 100.00% | [92.38%](http://westphal.com.br/holo/ietf-mpls-ldp.html) |
| ietf-mpls@2020-12-18 | 0.00% | 57.14% | - | - | [35.29%](http://westphal.com.br/holo/ietf-mpls.html) |
Expand All @@ -204,7 +204,7 @@ Holo supports the following IETF RFCs and Internet drafts:
| ietf-ospfv3-extended-lsa@2023-08-21 | 50.00% | 85.28% | - | - | [84.85%](http://westphal.com.br/holo/ietf-ospfv3-extended-lsa.html) |
| ietf-rip@2020-02-20 | 27.91% | 93.33% | 100.00% | - | [55.41%](http://westphal.com.br/holo/ietf-rip.html) |
| ietf-routing-policy@2021-10-11 | 100.00% | 0.00% | - | - | [98.11%](http://westphal.com.br/holo/ietf-routing-policy.html) |
| ietf-routing@2018-03-13 | 91.67% | 85.71% | - | - | [88.46%](http://westphal.com.br/holo/ietf-routing.html) |
| ietf-routing@2018-03-13 | 100.00% | 85.71% | - | - | [92.31%](http://westphal.com.br/holo/ietf-routing.html) |
| ietf-segment-routing-mpls@2021-05-26 | 62.50% | 0.00% | - | 23.53% | [32.76%](http://westphal.com.br/holo/ietf-segment-routing-mpls.html) |
| ietf-segment-routing@2021-05-26 | 100.00% | - | - | - | [100.00%](http://westphal.com.br/holo/ietf-segment-routing.html) |

Expand Down
13 changes: 12 additions & 1 deletion holo-routing/src/ibus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,23 @@ use holo_utils::southbound::{RouteKeyMsg, RouteMsg};
use ipnetwork::IpNetwork;

use crate::rib::Route;
use crate::Master;
use crate::{Interface, Master};

// ===== global functions =====

pub(crate) async fn process_msg(master: &mut Master, msg: IbusMsg) {
match msg {
// Interface update notification.
IbusMsg::InterfaceUpd(msg) => {
master.interfaces.insert(
msg.ifname.clone(),
Interface::new(msg.ifname, msg.ifindex, msg.flags),
);
}
// Interface delete notification.
IbusMsg::InterfaceDel(ifname) => {
master.interfaces.remove(&ifname);
}
// Interface address addition notification.
IbusMsg::InterfaceAddressAdd(msg) => {
// Add connected route to the RIB.
Expand Down
17 changes: 16 additions & 1 deletion holo-routing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ use holo_northbound::{
use holo_protocol::{event_recorder, spawn_protocol_task, InstanceShared};
use holo_utils::ibus::{IbusReceiver, IbusSender};
use holo_utils::protocol::Protocol;
use holo_utils::southbound::InterfaceFlags;
use holo_utils::sr::SrCfg;
use holo_utils::Database;
use ipnetwork::IpNetwork;
use tokio::sync::mpsc;
use tracing::Instrument;

use crate::rib::Rib;
use crate::rib::{Rib, StaticRoute};

pub struct Master {
// Northbound Tx channel.
Expand All @@ -41,8 +43,12 @@ pub struct Master {
pub event_recorder_config: event_recorder::Config,
// Netlink socket.
pub netlink_handle: rtnetlink::Handle,
// List of interfaces.
pub interfaces: BTreeMap<String, Interface>,
// RIB.
pub rib: Rib,
// Static routes.
pub static_routes: BTreeMap<IpNetwork, StaticRoute>,
// SR configuration data.
pub sr_config: SrCfg,
// Protocol instances.
Expand All @@ -57,6 +63,13 @@ pub struct InstanceId {
pub name: String,
}

#[derive(Debug, new)]
pub struct Interface {
pub ifname: String,
pub ifindex: u32,
pub flags: InterfaceFlags,
}

// ===== impl Master =====

impl Master {
Expand Down Expand Up @@ -115,7 +128,9 @@ pub fn start(
shared: shared.clone(),
event_recorder_config,
netlink_handle: netlink::init(),
interfaces: Default::default(),
rib: Default::default(),
static_routes: Default::default(),
sr_config: Default::default(),
instances: Default::default(),
};
Expand Down
Loading

0 comments on commit 7066fed

Please sign in to comment.