Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Directly connected routes #87

Merged
merged 4 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ steps:
route0 kni0.200 fe80::1 42:42:A4:59:BE:A5

- cli: neighbor insert route0 kni0.100 200.0.0.2 00:11:22:33:44:55
- sleep: 1
- cli: neighbor flush

- cli_check: |
YANET_FORMAT_COLUMNS=route_name,interface_name,ip_address,mac_address neighbor show
Expand All @@ -42,7 +42,7 @@ steps:
route0 kni0.200 fe80::1 42:42:A4:59:BE:A5

- cli: neighbor remove route0 kni0.100 200.0.0.2
- sleep: 1
- cli: neighbor flush

- cli_check: |
YANET_FORMAT_COLUMNS=route_name,interface_name,ip_address,mac_address neighbor show
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
steps:
- cli:
- neighbor insert route0 kni0.100 10.10.0.2 00:00:ee:10:44:02
- neighbor insert route0 kni0.100 10.10.0.250 00:00:ee:10:44:fa
- neighbor insert route0 kni0.100 2000:100::2 00:00:ee:10:66:02
- neighbor insert route0 kni0.100 2000:100::fa 00:00:ee:10:66:fa
- neighbor insert route0 kni0.200 10.20.0.2 00:00:ee:20:44:02
- neighbor insert route0 kni0.200 10.20.0.250 00:00:ee:20:44:fa
- neighbor insert route0 kni0.200 2000:200::2 00:00:ee:20:66:02
- neighbor insert route0 kni0.200 2000:200::fa 00:00:ee:20:66:fa
- neighbor flush
- sendPackets:
- port: kni0
send: 001-send.pcap
expect: 001-expect.pcap
- sendPackets:
- port: kni0
send: 002-send.pcap
expect: 002-expect.pcap
- sendPackets:
- port: kni0
send: 003-send.pcap
expect: 003-expect.pcap
- sendPackets:
- port: kni0
send: 004-send.pcap
expect: 004-expect.pcap
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"modules": {
"lp0.100": {
"type": "logicalPort",
"physicalPort": "kni0",
"vlanId": "100",
"macAddress": "00:00:00:11:11:11",
"nextModule": "acl0"
},
"lp0.200": {
"type": "logicalPort",
"physicalPort": "kni0",
"vlanId": "200",
"macAddress": "00:00:00:22:22:22",
"nextModule": "acl0"
},
"acl0": {
"type": "acl",
"nextModules": [
"route0"
]
},
"route0": {
"type": "route",
"interfaces": {
"kni0.100": {
"ipAddresses": [
"10.10.0.1/24",
"2000:100::1/96"
],
"nextModule": "lp0.100"
},
"kni0.200": {
"ipAddresses": [
"10.20.0.1/24",
"2000:200::1/96"
],
"nextModule": "lp0.200"
}
}
}
}
}
86 changes: 86 additions & 0 deletions autotest/units/001_one_port/071_route_directly_connected/gen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from scapy.all import *
from scapy.contrib.mpls import MPLS


def write_pcap(filename, *packetsList):
if len(packetsList) == 0:
PcapWriter(filename)._write_header(Ether())
return

PcapWriter(filename)

for packets in packetsList:
if type(packets) == list:
for packet in packets:
packet.time = 0
wrpcap(filename, [p for p in packet], append=True)
else:
packets.time = 0
wrpcap(filename, [p for p in packets], append=True)


# 10.10.0.0/24 -> kni0.100
write_pcap("001-send.pcap",
Ether(dst="00:00:00:11:11:11", src="00:00:DE:AD:00:00")/Dot1Q(vlan=100)/IP(dst="10.10.0.2", src="222.222.222.222")/UDP(),
Ether(dst="00:00:00:11:11:11", src="00:00:DE:AD:00:00")/Dot1Q(vlan=100)/IP(dst="10.10.0.111", src="222.222.222.222")/UDP(), # neighbor mac invalid
Ether(dst="00:00:00:11:11:11", src="00:00:DE:AD:00:00")/Dot1Q(vlan=100)/IP(dst="10.10.0.250", src="222.222.222.222")/UDP(),
Ether(dst="00:00:00:22:22:22", src="00:00:DE:AD:00:00")/Dot1Q(vlan=200)/IP(dst="10.10.0.2", src="222.222.222.222")/UDP(),
Ether(dst="00:00:00:22:22:22", src="00:00:DE:AD:00:00")/Dot1Q(vlan=200)/IP(dst="10.10.0.111", src="222.222.222.222")/UDP(), # neighbor mac invalid
Ether(dst="00:00:00:22:22:22", src="00:00:DE:AD:00:00")/Dot1Q(vlan=200)/IP(dst="10.10.0.250", src="222.222.222.222")/UDP())

write_pcap("001-expect.pcap",
Ether(dst="00:00:EE:10:44:02", src="00:00:00:11:11:11")/Dot1Q(vlan=100)/IP(dst="10.10.0.2", src="222.222.222.222", ttl=63)/UDP(),
Ether(dst="00:00:EE:10:44:FA", src="00:00:00:11:11:11")/Dot1Q(vlan=100)/IP(dst="10.10.0.250", src="222.222.222.222", ttl=63)/UDP(),
Ether(dst="00:00:EE:10:44:02", src="00:00:00:11:11:11")/Dot1Q(vlan=100)/IP(dst="10.10.0.2", src="222.222.222.222", ttl=63)/UDP(),
Ether(dst="00:00:EE:10:44:FA", src="00:00:00:11:11:11")/Dot1Q(vlan=100)/IP(dst="10.10.0.250", src="222.222.222.222", ttl=63)/UDP())


# 2000:100::/96 -> kni0.100
write_pcap("002-send.pcap",
Ether(dst="00:00:00:11:11:11", src="00:00:DE:AD:00:00")/Dot1Q(vlan=100)/IPv6(dst="2000:100::2", src="2222::2222")/UDP(),
Ether(dst="00:00:00:11:11:11", src="00:00:DE:AD:00:00")/Dot1Q(vlan=100)/IPv6(dst="2000:100::6F", src="2222::2222")/UDP(), # neighbor mac invalid
Ether(dst="00:00:00:11:11:11", src="00:00:DE:AD:00:00")/Dot1Q(vlan=100)/IPv6(dst="2000:100::FA", src="2222::2222")/UDP(),
Ether(dst="00:00:00:22:22:22", src="00:00:DE:AD:00:00")/Dot1Q(vlan=200)/IPv6(dst="2000:100::2", src="2222::2222")/UDP(),
Ether(dst="00:00:00:22:22:22", src="00:00:DE:AD:00:00")/Dot1Q(vlan=200)/IPv6(dst="2000:100::6F", src="2222::2222")/UDP(), # neighbor mac invalid
Ether(dst="00:00:00:22:22:22", src="00:00:DE:AD:00:00")/Dot1Q(vlan=200)/IPv6(dst="2000:100::FA", src="2222::2222")/UDP())

write_pcap("002-expect.pcap",
Ether(dst="00:00:EE:10:66:02", src="00:00:00:11:11:11")/Dot1Q(vlan=100)/IPv6(dst="2000:100::2", src="2222::2222", hlim=63)/UDP(),
Ether(dst="00:00:EE:10:66:FA", src="00:00:00:11:11:11")/Dot1Q(vlan=100)/IPv6(dst="2000:100::FA", src="2222::2222", hlim=63)/UDP(),
Ether(dst="00:00:EE:10:66:02", src="00:00:00:11:11:11")/Dot1Q(vlan=100)/IPv6(dst="2000:100::2", src="2222::2222", hlim=63)/UDP(),
Ether(dst="00:00:EE:10:66:FA", src="00:00:00:11:11:11")/Dot1Q(vlan=100)/IPv6(dst="2000:100::FA", src="2222::2222", hlim=63)/UDP())


# 10.20.0.0/24 -> kni0.200
write_pcap("003-send.pcap",
Ether(dst="00:00:00:11:11:11", src="00:00:DE:AD:00:00")/Dot1Q(vlan=100)/IP(dst="10.20.0.2", src="222.222.222.222")/UDP(),
Ether(dst="00:00:00:11:11:11", src="00:00:DE:AD:00:00")/Dot1Q(vlan=100)/IP(dst="10.20.0.111", src="222.222.222.222")/UDP(), # neighbor mac invalid
Ether(dst="00:00:00:11:11:11", src="00:00:DE:AD:00:00")/Dot1Q(vlan=100)/IP(dst="10.20.0.250", src="222.222.222.222")/UDP(),
Ether(dst="00:00:00:22:22:22", src="00:00:DE:AD:00:00")/Dot1Q(vlan=200)/IP(dst="10.20.0.2", src="222.222.222.222")/UDP(),
Ether(dst="00:00:00:22:22:22", src="00:00:DE:AD:00:00")/Dot1Q(vlan=200)/IP(dst="10.20.0.111", src="222.222.222.222")/UDP(), # neighbor mac invalid
Ether(dst="00:00:00:22:22:22", src="00:00:DE:AD:00:00")/Dot1Q(vlan=200)/IP(dst="10.20.0.250", src="222.222.222.222")/UDP())

write_pcap("003-expect.pcap",
Ether(dst="00:00:EE:20:44:02", src="00:00:00:22:22:22")/Dot1Q(vlan=200)/IP(dst="10.20.0.2", src="222.222.222.222", ttl=63)/UDP(),
Ether(dst="00:00:EE:20:44:FA", src="00:00:00:22:22:22")/Dot1Q(vlan=200)/IP(dst="10.20.0.250", src="222.222.222.222", ttl=63)/UDP(),
Ether(dst="00:00:EE:20:44:02", src="00:00:00:22:22:22")/Dot1Q(vlan=200)/IP(dst="10.20.0.2", src="222.222.222.222", ttl=63)/UDP(),
Ether(dst="00:00:EE:20:44:FA", src="00:00:00:22:22:22")/Dot1Q(vlan=200)/IP(dst="10.20.0.250", src="222.222.222.222", ttl=63)/UDP())


# 2000:200::/96 -> kni0.200
write_pcap("004-send.pcap",
Ether(dst="00:00:00:11:11:11", src="00:00:DE:AD:00:00")/Dot1Q(vlan=100)/IPv6(dst="2000:200::2", src="2222::2222")/UDP(),
Ether(dst="00:00:00:11:11:11", src="00:00:DE:AD:00:00")/Dot1Q(vlan=100)/IPv6(dst="2000:200::6F", src="2222::2222")/UDP(), # neighbor mac invalid
Ether(dst="00:00:00:11:11:11", src="00:00:DE:AD:00:00")/Dot1Q(vlan=100)/IPv6(dst="2000:200::FA", src="2222::2222")/UDP(),
Ether(dst="00:00:00:22:22:22", src="00:00:DE:AD:00:00")/Dot1Q(vlan=200)/IPv6(dst="2000:200::2", src="2222::2222")/UDP(),
Ether(dst="00:00:00:22:22:22", src="00:00:DE:AD:00:00")/Dot1Q(vlan=200)/IPv6(dst="2000:200::6F", src="2222::2222")/UDP(), # neighbor mac invalid
Ether(dst="00:00:00:22:22:22", src="00:00:DE:AD:00:00")/Dot1Q(vlan=200)/IPv6(dst="2000:200::FA", src="2222::2222")/UDP())

write_pcap("004-expect.pcap",
Ether(dst="00:00:EE:20:66:02", src="00:00:00:22:22:22")/Dot1Q(vlan=200)/IPv6(dst="2000:200::2", src="2222::2222", hlim=63)/UDP(),
Ether(dst="00:00:EE:20:66:FA", src="00:00:00:22:22:22")/Dot1Q(vlan=200)/IPv6(dst="2000:200::FA", src="2222::2222", hlim=63)/UDP(),
Ether(dst="00:00:EE:20:66:02", src="00:00:00:22:22:22")/Dot1Q(vlan=200)/IPv6(dst="2000:200::2", src="2222::2222", hlim=63)/UDP(),
Ether(dst="00:00:EE:20:66:FA", src="00:00:00:22:22:22")/Dot1Q(vlan=200)/IPv6(dst="2000:200::FA", src="2222::2222", hlim=63)/UDP())
1 change: 1 addition & 0 deletions cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ std::vector<std::tuple<std::string,
{"neighbor show", "", [](const auto& args) { call(neighbor::show, args); }},
{"neighbor insert", "[route_name] [interface_name] [ip_address] [mac_address]", [](const auto& args) { call(neighbor::insert, args); }},
{"neighbor remove", "[route_name] [interface_name] [ip_address]", [](const auto& args) { call(neighbor::remove, args); }},
{"neighbor flush", "", [](const auto& args) { call(neighbor::flush, args); }},
{"rib", "", [](const auto& args) { call(rib::summary, args); }},
{"rib prefixes", "", [](const auto& args) { call(rib::prefixes, args); }},
{"rib lookup", "[vrf] [ip_address]", [](const auto& args) { call(rib::lookup, args); }},
Expand Down
6 changes: 6 additions & 0 deletions cli/neighbor.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,10 @@ void remove(const std::string& route_name,
ip_address});
}

void flush()
{
interface::dataPlane dataplane;
dataplane.neighbor_flush();
}

}
6 changes: 3 additions & 3 deletions common/controlplaneconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class interface_t
void pop(common::stream_in_t& stream)
{
stream.pop(interfaceId);
stream.pop(ipAddresses);
stream.pop(ip_prefixes);
stream.pop(neighborIPv4Address);
stream.pop(neighborIPv6Address);
stream.pop(static_neighbor_mac_address_v4);
Expand All @@ -116,7 +116,7 @@ class interface_t
void push(common::stream_out_t& stream) const
{
stream.push(interfaceId);
stream.push(ipAddresses);
stream.push(ip_prefixes);
stream.push(neighborIPv4Address);
stream.push(neighborIPv6Address);
stream.push(static_neighbor_mac_address_v4);
Expand All @@ -130,7 +130,7 @@ class interface_t
public:
tInterfaceId interfaceId;

std::set<common::ip_address_t> ipAddresses;
std::set<common::ip_prefix_t> ip_prefixes;
std::optional<common::ipv4_address_t> neighborIPv4Address;
std::optional<common::ipv6_address_t> neighborIPv6Address;
std::optional<common::mac_address_t> static_neighbor_mac_address_v4; ///< @todo: no directly connected (only v4 and v6 neighbor)
Expand Down
2 changes: 2 additions & 0 deletions common/define.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ extern LogPriority logPriority;
#define YANET_NETWORK_FLAG_NOT_FIRST_FRAGMENT ((uint8_t)(1u << 1))
#define YANET_NETWORK_FLAG_HAS_EXTENSION ((uint8_t)(1u << 2))

#define YANET_NEXTHOP_FLAG_DIRECTLY ((uint16_t)(1u << 0))

/// @todo: move
template<typename map_T,
typename key_T>
Expand Down
2 changes: 1 addition & 1 deletion common/icp.h
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ namespace route_interface
{
using response = std::map<std::tuple<std::string, ///< route_name
std::string>, ///< interface_name
std::tuple<std::set<ip_address_t>,
std::tuple<std::set<ip_prefix_t>,
std::optional<ipv4_address_t>, ///< neighbor
std::optional<ipv6_address_t>, ///< neighbor
std::optional<mac_address_t>, ///< neighbor_mac_address_v4
Expand Down
10 changes: 6 additions & 4 deletions common/idp.h
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,10 @@ using request = lpm::request;

namespace route_value_update
{
using interface = std::vector<std::tuple<tInterfaceId,
std::vector<uint32_t>,
ip_address_t>>; ///< neighbor_address
using interface = std::vector<std::tuple<tInterfaceId, ///< interface_id
std::vector<uint32_t>, ///< labels
ip_address_t, ///< neighbor_address
uint16_t>>; ///< nexthop_flags

using request = std::tuple<uint32_t, ///< route_value_id
tSocketId,
Expand All @@ -405,7 +406,8 @@ using interface = std::tuple<uint32_t, ///< weight_start
tCounterId,
uint32_t, ///< label
ip_address_t, ///< nexthop_address
ip_address_t>>>; ///< neighbor_address
ip_address_t, ///< neighbor_address
uint16_t>>>; ///< nexthop_flags

using request = std::tuple<uint32_t, ///< route_tunnel_value_id
tSocketId,
Expand Down
12 changes: 12 additions & 0 deletions common/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,18 @@ class ip_prefix_t
}
}

bool is_host() const
{
if (is_ipv4())
{
return std::get<ipv4_prefix_t>(prefix).mask() == 32;
}
else
{
return std::get<ipv6_prefix_t>(prefix).mask() == 128;
}
}

ip_prefix_t get_default() const
{
if (is_ipv4())
Expand Down
6 changes: 3 additions & 3 deletions controlplane/configconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -874,15 +874,15 @@ void config_converter_t::acl_rules_route_local(controlplane::base::acl_t& acl,
{
(void)interfaceName;

for (const auto& ipAddress : interface.ipAddresses)
for (const auto& ipAddress : interface.ip_prefixes)
{
if (ipAddress.is_ipv4())
{
rule_network_ipv4.destinationPrefixes.emplace(ipAddress.get_ipv4());
rule_network_ipv4.destinationPrefixes.emplace(ipAddress.address());
}
else
{
rule_network_ipv6.destinationPrefixes.emplace(ipAddress.get_ipv6());
rule_network_ipv6.destinationPrefixes.emplace(ipAddress.address());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion controlplane/configparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ void config_parser_t::loadConfig_route(controlplane::base_t& baseNext,
{
for (const auto& ipAddressJson : interfaceJson["ipAddresses"])
{
interface.ipAddresses.emplace(ipAddressJson.get<std::string>());
interface.ip_prefixes.emplace(ipAddressJson.get<std::string>());
}
}

Expand Down
12 changes: 0 additions & 12 deletions controlplane/controlplane.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,6 @@ class cControlPlane
}
}

void inline forEachSocket(const std::function<void(const tSocketId& socketId, const std::set<tInterfaceId>& interfaces)>& function) const
{
generations.current_lock();
std::map<tSocketId, std::set<tInterfaceId>> socket_interfaces = generations.current().socket_interfaces;
generations.current_unlock();

for (const auto& [socket_id, interfaces] : socket_interfaces)
{
function(socket_id, interfaces);
}
}

protected: /** commands */
common::icp::getPhysicalPorts::response getPhysicalPorts() const;
common::icp::getLogicalPorts::response getLogicalPorts() const;
Expand Down
Loading
Loading