|
2 | 2 |
|
3 | 3 | use futures::stream::TryStreamExt; |
4 | 4 | use netlink_packet_route::link::{ |
5 | | - InfoData, InfoKind, InfoMacVlan, LinkAttribute, LinkInfo, LinkMessage, |
| 5 | + InfoData, InfoKind, InfoMacVlan, InfoVrf, LinkAttribute, LinkInfo, |
| 6 | + LinkMessage, |
6 | 7 | }; |
7 | 8 | use tokio::runtime::Runtime; |
8 | 9 |
|
@@ -78,6 +79,33 @@ fn create_get_delete_macvlan() { |
78 | 79 | .unwrap(); |
79 | 80 | } |
80 | 81 |
|
| 82 | +#[test] |
| 83 | +fn create_delete_vrf() { |
| 84 | + const VRF_IFACE_NAME: &str = "vrf2222"; |
| 85 | + const VRF_TABLE: u32 = 2222; |
| 86 | + let rt = Runtime::new().unwrap(); |
| 87 | + let handle = rt.block_on(_create_vrf(VRF_IFACE_NAME, VRF_TABLE)); |
| 88 | + assert!(handle.is_ok()); |
| 89 | + |
| 90 | + let mut handle = handle.unwrap(); |
| 91 | + let msg = rt.block_on(_get_iface(&mut handle, VRF_IFACE_NAME.to_owned())); |
| 92 | + assert!(msg.is_ok()); |
| 93 | + assert!(has_nla( |
| 94 | + msg.as_ref().unwrap(), |
| 95 | + &LinkAttribute::IfName(VRF_IFACE_NAME.to_string()) |
| 96 | + )); |
| 97 | + assert!(has_nla( |
| 98 | + msg.as_ref().unwrap(), |
| 99 | + &LinkAttribute::LinkInfo(vec![ |
| 100 | + LinkInfo::Kind(InfoKind::Vrf), |
| 101 | + LinkInfo::Data(InfoData::Vrf(vec![InfoVrf::TableId(VRF_TABLE),])) |
| 102 | + ]) |
| 103 | + )); |
| 104 | + |
| 105 | + rt.block_on(_del_iface(&mut handle, msg.unwrap().header.index)) |
| 106 | + .unwrap(); |
| 107 | +} |
| 108 | + |
81 | 109 | fn has_nla(msg: &LinkMessage, nla: &LinkAttribute) -> bool { |
82 | 110 | msg.attributes.iter().any(|x| x == nla) |
83 | 111 | } |
@@ -128,3 +156,12 @@ async fn _create_macvlan( |
128 | 156 | req.execute().await?; |
129 | 157 | Ok(link_handle) |
130 | 158 | } |
| 159 | + |
| 160 | +async fn _create_vrf(name: &str, table: u32) -> Result<LinkHandle, Error> { |
| 161 | + let (conn, handle, _) = new_connection().unwrap(); |
| 162 | + tokio::spawn(conn); |
| 163 | + let link_handle = handle.link(); |
| 164 | + let req = link_handle.add().vrf(name.to_string(), table); |
| 165 | + req.execute().await?; |
| 166 | + Ok(link_handle) |
| 167 | +} |
0 commit comments