diff --git a/Documentation/cubes.rst b/Documentation/cubes.rst index 42416a9ce..15668ce23 100644 --- a/Documentation/cubes.rst +++ b/Documentation/cubes.rst @@ -158,10 +158,10 @@ For instance: # create port2 on br1 (simplebridge), it doesn't require any further parameters polycubectl br1 ports add port2 - # create portX on r1 (router), it requires ip and netmask parameters - polycubectl r1 ports add port1 ip=10.0.1.1 netmask=255.255.255.0 - polycubectl r1 ports add port2 ip=10.0.2.1 netmask=255.255.255.0 - polycubectl r1 ports add port1 ip=10.0.3.1 netmask=255.255.255.0 + # create portX on r1 (router), it doesn't require mandatory parameters, but it is useful to assign an ip (during or after creation) + polycubectl r1 ports add port1 ip=10.0.1.1/24 + polycubectl r1 ports add port2 ip=10.0.2.1/24 + polycubectl r1 ports add port1 ip=10.0.3.1/24 Connect Ports ^^^^^^^^^^^^^ diff --git a/Documentation/tutorials/tutorial2/tutorial2.rst b/Documentation/tutorials/tutorial2/tutorial2.rst index cce74ce16..2e6684c0f 100644 --- a/Documentation/tutorials/tutorial2/tutorial2.rst +++ b/Documentation/tutorials/tutorial2/tutorial2.rst @@ -77,14 +77,13 @@ Before trying to add a port, let's use the ``polycubectl`` help to get the info Other parameters: peer=value string Peer name, such as a network interfaces (e.g., 'veth0') or another cube (e.g., 'br1:port2') - ip=value string IP address of the port - netmask=value string Netmask of the port + ip=value string IP address and prefix of the port mac=value string MAC address of the port Example: - polycubectl r1 ports add port1 peer=r0:port1 ip=207.46.130.1 netmask=255.255.255.0 mac=B3:23:45:F5:3A + polycubectl r1 ports add port1 peer=r0:port1 ip=207.46.130.1/24 mac=B3:23:45:F5:3A -The output indicates that a port name is expected ``Keyword``, and following it the ``peer``, ``ip``, ``netmask`` and ``mac`` are supported parameters. +The output indicates that a port name is expected ``Keyword``, and following it the ``peer``, ``ip`` and ``mac`` are supported parameters. **Connect** ``veth1`` **to** ``r1`` @@ -93,7 +92,7 @@ The output indicates that a port name is expected ``Keyword``, and following it :: # create new port on r1 and set the IP parameters - polycubectl r1 ports add to_veth1 ip=10.0.1.254 netmask=255.255.255.0 + polycubectl r1 ports add to_veth1 ip=10.0.1.254/24 # connect port to netdev polycubectl connect r1:to_veth1 veth1 @@ -102,8 +101,8 @@ The router automatically adds a new local entry in the routing table. :: polycubectl r1 show route - interface netmask network nexthop pathcost - to_veth1 255.255.255.0 10.0.1.0 local 0 + interface network nexthop pathcost + to_veth1 10.0.1.0/24 local 0 @@ -112,7 +111,7 @@ The router automatically adds a new local entry in the routing table. :: # create new port on r1 and set the IP parameters - polycubectl r1 ports add to_veth2 ip=10.0.2.254 netmask=255.255.255.0 + polycubectl r1 ports add to_veth2 ip=10.0.2.254/24 # connect router port to netdev interface polycubectl r1 ports to_veth2 set peer=veth2 @@ -126,7 +125,7 @@ The router automatically adds a new local entry in the routing table. # create new port on r1 and set the IP parameters # notice that in this case 'peer' is also set so the port is also connected to the netdev - polycubectl r1 ports add to_veth3 ip=10.0.3.254 netmask=255.255.255.0 peer=veth3 + polycubectl r1 ports add to_veth3 ip=10.0.3.254/24 peer=veth3 Step 3: Check configuration @@ -144,16 +143,16 @@ You should see an output similar to the next one, where ports are ``up`` and hav loglevel: info ports: - name uuid status peer ip netmask mac - to_veth3 c51bb0ed-9e6f-44ed-a096-b13bc1011331 up veth3 10.0.3.254 255.255.255.0 72:59:a8:c2:c2:44 - to_veth2 48f8d130-aa32-4354-a1b5-105df9a8ad7b up veth2 10.0.2.254 255.255.255.0 d6:42:7f:65:b4:40 - to_veth1 46c685b9-4c80-4466-9d81-985598a07444 up veth1 10.0.1.254 255.255.255.0 52:f0:5f:2c:a5:a7 + name uuid status peer ip mac + to_veth3 c51bb0ed-9e6f-44ed-a096-b13bc1011331 up veth3 10.0.3.254/24 72:59:a8:c2:c2:44 + to_veth2 48f8d130-aa32-4354-a1b5-105df9a8ad7b up veth2 10.0.2.254/24 d6:42:7f:65:b4:40 + to_veth1 46c685b9-4c80-4466-9d81-985598a07444 up veth1 10.0.1.254/24 52:f0:5f:2c:a5:a7 route: - network netmask nexthop interface pathcost - 10.0.1.0 255.255.255.0 local to_veth1 0 - 10.0.2.0 255.255.255.0 local to_veth2 0 - 10.0.3.0 255.255.255.0 local to_veth3 0 + network nexthop interface pathcost + 10.0.1.0/24 local to_veth1 0 + 10.0.2.0/24 local to_veth2 0 + 10.0.3.0/24 local to_veth3 0 Step 4: Test the connectivity between the namespaces and the router diff --git a/Documentation/tutorials/tutorial3/tutorial3.rst b/Documentation/tutorials/tutorial3/tutorial3.rst index 4dfbe0632..60a9aa253 100644 --- a/Documentation/tutorials/tutorial3/tutorial3.rst +++ b/Documentation/tutorials/tutorial3/tutorial3.rst @@ -103,7 +103,7 @@ Step 3: Add and connect ports on routers :: # Create new port on r1 and set the IP parameters - polycubectl r1 ports add to_br1 ip=10.0.1.254 netmask=255.255.255.0 + polycubectl r1 ports add to_br1 ip=10.0.1.254/24 # Create a bridge interface on br1 polycubectl br1 ports add to_r1 # Connect both ports @@ -117,7 +117,7 @@ In order to permit more networks on the same router interface we need to add a s :: # Add a secondary address on r1 interface `to_br1` - polycubectl r1 ports to_br1 secondaryip add 10.0.2.254 255.255.255.0 + polycubectl r1 ports to_br1 secondaryip add 10.0.2.254/24 **Connect** ``r2`` **to** ``br2`` @@ -125,7 +125,7 @@ In order to permit more networks on the same router interface we need to add a s :: # Create new port on r2 and set the IP parameters - polycubectl r2 ports add to_br2 ip=10.0.3.254 netmask=255.255.255.0 + polycubectl r2 ports add to_br2 ip=10.0.3.254/24 # Create a bridge interface on br2 polycubectl br2 ports add to_r2 @@ -139,8 +139,8 @@ In the router ``r2`` we have three different networks, so we need to add two sec :: # Add the secondary addresses on r2 interface `to_br2` - polycubectl r2 ports to_br2 secondaryip add 10.0.4.254 255.255.255.0 - polycubectl r2 ports to_br2 secondaryip add 10.0.5.254 255.255.255.0 + polycubectl r2 ports to_br2 secondaryip add 10.0.4.254/24 + polycubectl r2 ports to_br2 secondaryip add 10.0.5.254/24 **Connect the routers** @@ -149,8 +149,8 @@ We need to create a point-to-point link between the routers to connect them. To :: # Create new port on r1 and r2 and set the IP parameters - polycubectl r1 ports add to_r2 ip=10.1.0.1 netmask=255.255.255.252 - polycubectl r2 ports add to_r1 ip=10.1.0.2 netmask=255.255.255.252 + polycubectl r1 ports add to_r2 ip=10.1.0.1/30 + polycubectl r2 ports add to_r1 ip=10.1.0.2/30 # Connects the routers polycubectl connect r1:to_r2 r2:to_r1 @@ -164,9 +164,9 @@ We need to tell the router `r1` which are the networks reachable through `r2` :: - polycubectl r1 route add 10.0.3.0 255.255.255.0 10.1.0.2 - polycubectl r1 route add 10.0.4.0 255.255.255.0 10.1.0.2 - polycubectl r1 route add 10.0.5.0 255.255.255.0 10.1.0.2 + polycubectl r1 route add 10.0.3.0/24 10.1.0.2 + polycubectl r1 route add 10.0.4.0/24 10.1.0.2 + polycubectl r1 route add 10.0.5.0/24 10.1.0.2 **Add static entries in the routing table of router `r2`** @@ -175,8 +175,8 @@ We need to do the same on the router `r2` :: - polycubectl r2 route add 10.0.1.0 255.255.255.0 10.1.0.1 - polycubectl r2 route add 10.0.2.0 255.255.255.0 10.1.0.1 + polycubectl r2 route add 10.0.1.0/24 10.1.0.1 + polycubectl r2 route add 10.0.2.0/24 10.1.0.1 **Show the routing tables of the routers** diff --git a/scripts/install.sh b/scripts/install.sh index 848614091..9f57a829c 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -140,14 +140,14 @@ echo "Install polycube" cd $DIR/.. if [ "$INSTALL_CLEAN_POLYCUBE" == true ] ; then $SUDO rm -rf build -else +#else # The above commands are executed only in case of a manual install; # Jenkins runs this script with "$INSTALL_CLEAN_POLYCUBE" = true # The above commands are useful in case you are re-running this # script on an existing install, i.e., update source code and # all the submodules - git pull - git submodule update --init --recursive + #git pull + #git submodule update --init --recursive fi mkdir -p build && cd build diff --git a/src/libs/polycube/include/polycube/services/utils.h b/src/libs/polycube/include/polycube/services/utils.h index 9e467e870..3a08afbb7 100644 --- a/src/libs/polycube/include/polycube/services/utils.h +++ b/src/libs/polycube/include/polycube/services/utils.h @@ -65,7 +65,12 @@ uint32_t get_netmask_length(const std::string &netmask_string); /* Take in ingress a prefix length like 24 and return the * "netmask" -> 255.255.255.0 in this case */ -std::string get_netmask_from_CIDR(const int cidr); +std::string get_netmask_from_prefixlength(const int prefixlength); + +/* Take in ingress an ip/prefix and return the ip address and the netmask +* in the variables ip_address and netmask passed by reference */ +void split_ip_and_prefix(const std::string &ip_and_prefix, + std::string &ip_address, std::string &netmask); /* * formats a debug string, custom specifiers are evaluated by a diff --git a/src/libs/polycube/src/utils.cpp b/src/libs/polycube/src/utils.cpp index 28b98c2f7..892809024 100644 --- a/src/libs/polycube/src/utils.cpp +++ b/src/libs/polycube/src/utils.cpp @@ -296,17 +296,33 @@ uint32_t get_netmask_length(const std::string &netmask_string) { throw std::runtime_error("IP Address is not in a valid format"); } -std::string get_netmask_from_CIDR(const int cidr) { +std::string get_netmask_from_prefixlength(const int prefixlength) { uint32_t ipv4Netmask; + if (prefixlength == 0) { + return "0.0.0.0"; + } + ipv4Netmask = 0xFFFFFFFF; - ipv4Netmask <<= 32 - cidr; + ipv4Netmask <<= 32 - prefixlength; ipv4Netmask = ntohl(ipv4Netmask); struct in_addr addr = {ipv4Netmask}; return inet_ntoa(addr); } +void split_ip_and_prefix(const std::string &ip_and_prefix, + std::string &ip_address, std::string &netmask) { + // ip_and_prefix = ip_address/prefix + std::istringstream split(ip_and_prefix); + std::vector info; + char split_char = '/'; + for (std::string each; std::getline(split, each, split_char); + info.push_back(each)); + ip_address = info[0]; + netmask = get_netmask_from_prefixlength(std::atoi(info[1].c_str())); +} + } // namespace utils } // namespace service } // namespace polycube diff --git a/src/polycubed/src/cube.cpp b/src/polycubed/src/cube.cpp index dd7bd58b9..32d755e07 100644 --- a/src/polycubed/src/cube.cpp +++ b/src/polycubed/src/cube.cpp @@ -164,9 +164,13 @@ std::shared_ptr Cube::add_port(const std::string &name, peerB.set_status(IFACE_STATUS::UP); peerA.set_namespace(prefix_ns + get_name()); peerA.set_status(IFACE_STATUS::UP); - if (conf.count("ip") && conf.count("netmask")) { - int prefix = polycube::service::utils::get_netmask_length(conf.at("netmask").get()); - peerA.set_ip(conf.at("ip").get(), prefix); + if (conf.count("ip")) { + std::string ip_address; + std::string netmask; + polycube::service::utils::split_ip_and_prefix( + conf.at("ip").get(), ip_address, netmask); + int prefix = polycube::service::utils::get_netmask_length(netmask); + peerA.set_ip(ip_address, prefix); } else if (conf.count("ipv6")) { peerA.set_ipv6(conf.at("ipv6").get()); } diff --git a/src/services/pcn-nat/test/examples/example1.sh b/src/services/pcn-nat/test/examples/example1.sh index 5bb610a81..784dfdb84 100755 --- a/src/services/pcn-nat/test/examples/example1.sh +++ b/src/services/pcn-nat/test/examples/example1.sh @@ -36,9 +36,9 @@ create_veth_net 2 polycubectl nat add nat1 polycubectl router add r1 -polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip netmask=255.255.255.0 +polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip/24 polycubectl router r1 ports to_veth1 set peer=veth1 -polycubectl router r1 ports add to_nat1 ip=$to_nat_ip netmask=255.255.255.0 +polycubectl router r1 ports add to_nat1 ip=$to_nat_ip/24 polycubectl nat1 ports add to_r1 type=INTERNAL polycubectl connect nat1:to_r1 r1:to_nat1 diff --git a/src/services/pcn-nat/test/examples/example2.sh b/src/services/pcn-nat/test/examples/example2.sh index 4fe678807..5bc2bc7b3 100755 --- a/src/services/pcn-nat/test/examples/example2.sh +++ b/src/services/pcn-nat/test/examples/example2.sh @@ -36,9 +36,9 @@ create_veth_net 2 polycubectl nat add nat1 polycubectl router add r1 -polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip netmask=255.255.255.0 +polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip/24 polycubectl router r1 ports to_veth1 set peer=veth1 -polycubectl router r1 ports add to_nat1 ip=$to_nat_ip netmask=255.255.255.0 +polycubectl router r1 ports add to_nat1 ip=$to_nat_ip/24 polycubectl nat1 ports add to_r1 type=INTERNAL polycubectl connect nat1:to_r1 r1:to_nat1 diff --git a/src/services/pcn-nat/test/examples/example3.sh b/src/services/pcn-nat/test/examples/example3.sh index 7ce84af08..f0e7d2316 100755 --- a/src/services/pcn-nat/test/examples/example3.sh +++ b/src/services/pcn-nat/test/examples/example3.sh @@ -38,9 +38,9 @@ create_veth_net 2 polycubectl nat add nat1 polycubectl router add r1 -polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip netmask=255.255.255.0 +polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip/24 polycubectl router r1 ports to_veth1 set peer=veth1 -polycubectl router r1 ports add to_nat1 ip=$to_nat_ip netmask=255.255.255.0 +polycubectl router r1 ports add to_nat1 ip=$to_nat_ip/24 polycubectl nat1 ports add to_r1 type=INTERNAL polycubectl connect nat1:to_r1 r1:to_nat1 diff --git a/src/services/pcn-nat/test/examples/example4.sh b/src/services/pcn-nat/test/examples/example4.sh index 1f41e417d..800fe3e55 100755 --- a/src/services/pcn-nat/test/examples/example4.sh +++ b/src/services/pcn-nat/test/examples/example4.sh @@ -54,9 +54,9 @@ create_veth_net 2 polycubectl nat add nat1 polycubectl router add r1 -polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip netmask=255.255.255.0 +polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip/24 polycubectl router r1 ports to_veth1 set peer=veth1 -polycubectl router r1 ports add to_nat1 ip=$to_nat_ip netmask=255.255.255.0 +polycubectl router r1 ports add to_nat1 ip=$to_nat_ip/24 polycubectl nat1 ports add to_r1 type=INTERNAL polycubectl connect nat1:to_r1 r1:to_nat1 diff --git a/src/services/pcn-nat/test/test_all_dnat.sh b/src/services/pcn-nat/test/test_all_dnat.sh index e3b310989..5a92258b8 100755 --- a/src/services/pcn-nat/test/test_all_dnat.sh +++ b/src/services/pcn-nat/test/test_all_dnat.sh @@ -60,8 +60,8 @@ create_veth_net 2 polycubectl nat add nat1 polycubectl router add r1 -polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip netmask=255.255.255.0 peer=veth1 -polycubectl router r1 ports add to_veth2 ip=$to_veth2_ip netmask=255.255.255.0 peer=veth2 +polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip/24 peer=veth1 +polycubectl router r1 ports add to_veth2 ip=$to_veth2_ip/24 peer=veth2 polycubectl attach nat1 r1:to_veth2 position=first diff --git a/src/services/pcn-nat/test/test_all_pf.sh b/src/services/pcn-nat/test/test_all_pf.sh index 348b7b0ec..03af5fcc0 100755 --- a/src/services/pcn-nat/test/test_all_pf.sh +++ b/src/services/pcn-nat/test/test_all_pf.sh @@ -62,8 +62,8 @@ create_veth_net 2 polycubectl nat add nat1 polycubectl router add r1 -polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip netmask=255.255.255.0 peer=veth1 -polycubectl router r1 ports add to_veth2 ip=$to_veth2_ip netmask=255.255.255.0 peer=veth2 +polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip/24 peer=veth1 +polycubectl router r1 ports add to_veth2 ip=$to_veth2_ip/24 peer=veth2 polycubectl attach nat1 r1:to_veth2 position=first diff --git a/src/services/pcn-nat/test/test_icmp_dnat.sh b/src/services/pcn-nat/test/test_icmp_dnat.sh index 5358ce1ca..3e6991234 100755 --- a/src/services/pcn-nat/test/test_icmp_dnat.sh +++ b/src/services/pcn-nat/test/test_icmp_dnat.sh @@ -36,8 +36,8 @@ create_veth_net 2 polycubectl nat add nat1 polycubectl router add r1 -polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip netmask=255.255.255.0 peer=veth1 -polycubectl router r1 ports add to_veth2 ip=$to_veth2_ip netmask=255.255.255.0 peer=veth2 +polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip/24 peer=veth1 +polycubectl router r1 ports add to_veth2 ip=$to_veth2_ip/24 peer=veth2 polycubectl attach nat1 r1:to_veth2 position=first diff --git a/src/services/pcn-nat/test/test_icmp_masq.sh b/src/services/pcn-nat/test/test_icmp_masq.sh index e68ae3eb0..443051468 100755 --- a/src/services/pcn-nat/test/test_icmp_masq.sh +++ b/src/services/pcn-nat/test/test_icmp_masq.sh @@ -35,8 +35,8 @@ create_veth_net 2 polycubectl nat add nat1 polycubectl router add r1 -polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip netmask=255.255.255.0 peer=veth1 -polycubectl router r1 ports add to_veth2 ip=$to_veth2_ip netmask=255.255.255.0 peer=veth2 +polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip/24 peer=veth1 +polycubectl router r1 ports add to_veth2 ip=$to_veth2_ip/24 peer=veth2 polycubectl attach nat1 r1:to_veth2 position=first diff --git a/src/services/pcn-nat/test/test_icmp_snat.sh b/src/services/pcn-nat/test/test_icmp_snat.sh index 0bcf3b2ff..61a61a970 100755 --- a/src/services/pcn-nat/test/test_icmp_snat.sh +++ b/src/services/pcn-nat/test/test_icmp_snat.sh @@ -35,12 +35,12 @@ create_veth_net 2 polycubectl nat add nat1 polycubectl router add r1 -polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip netmask=255.255.255.0 peer=veth1 -polycubectl router r1 ports add to_veth2 ip=$to_veth2_ip netmask=255.255.255.0 peer=veth2 +polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip/24 peer=veth1 +polycubectl router r1 ports add to_veth2 ip=$to_veth2_ip/24 peer=veth2 polycubectl attach nat1 r1:to_veth2 position=first # configure source nat polycubectl nat1 rule snat append internal-net=10.0.1.0/24 external-ip=$to_veth2_ip -sudo ip netns exec ns1 ping $veth2_ip -c 3 \ No newline at end of file +sudo ip netns exec ns1 ping $veth2_ip -c 3 diff --git a/src/services/pcn-nat/test/test_tcp_dnat.sh b/src/services/pcn-nat/test/test_tcp_dnat.sh index 4d807f19f..18adc0581 100755 --- a/src/services/pcn-nat/test/test_tcp_dnat.sh +++ b/src/services/pcn-nat/test/test_tcp_dnat.sh @@ -52,8 +52,8 @@ create_veth_net 2 polycubectl nat add nat1 polycubectl router add r1 -polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip netmask=255.255.255.0 peer=veth1 -polycubectl router r1 ports add to_veth2 ip=$to_veth2_ip netmask=255.255.255.0 peer=veth2 +polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip/24 peer=veth1 +polycubectl router r1 ports add to_veth2 ip=$to_veth2_ip/24 peer=veth2 polycubectl attach nat1 r1:to_veth2 position=first diff --git a/src/services/pcn-nat/test/test_tcp_masq.sh b/src/services/pcn-nat/test/test_tcp_masq.sh index d594021f2..30640bf60 100755 --- a/src/services/pcn-nat/test/test_tcp_masq.sh +++ b/src/services/pcn-nat/test/test_tcp_masq.sh @@ -44,8 +44,8 @@ create_veth_net 2 polycubectl nat add nat1 polycubectl router add r1 -polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip netmask=255.255.255.0 peer=veth1 -polycubectl router r1 ports add to_veth2 ip=$to_veth2_ip netmask=255.255.255.0 peer=veth2 +polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip/24 peer=veth1 +polycubectl router r1 ports add to_veth2 ip=$to_veth2_ip/24 peer=veth2 polycubectl attach nat1 r1:to_veth2 position=first diff --git a/src/services/pcn-nat/test/test_tcp_pf.sh b/src/services/pcn-nat/test/test_tcp_pf.sh index 626a92801..d0d88ac81 100755 --- a/src/services/pcn-nat/test/test_tcp_pf.sh +++ b/src/services/pcn-nat/test/test_tcp_pf.sh @@ -55,8 +55,8 @@ create_veth_net 2 polycubectl nat add nat1 polycubectl router add r1 -polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip netmask=255.255.255.0 peer=veth1 -polycubectl router r1 ports add to_veth2 ip=$to_veth2_ip netmask=255.255.255.0 peer=veth2 +polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip/24 peer=veth1 +polycubectl router r1 ports add to_veth2 ip=$to_veth2_ip/24 peer=veth2 polycubectl attach nat1 r1:to_veth2 position=first diff --git a/src/services/pcn-nat/test/test_tcp_snat.sh b/src/services/pcn-nat/test/test_tcp_snat.sh index 05b42bacc..52bcc6a9b 100755 --- a/src/services/pcn-nat/test/test_tcp_snat.sh +++ b/src/services/pcn-nat/test/test_tcp_snat.sh @@ -44,8 +44,8 @@ create_veth_net 2 polycubectl nat add nat1 polycubectl router add r1 -polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip netmask=255.255.255.0 peer=veth1 -polycubectl router r1 ports add to_veth2 ip=$to_veth2_ip netmask=255.255.255.0 peer=veth2 +polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip/24 peer=veth1 +polycubectl router r1 ports add to_veth2 ip=$to_veth2_ip/24 peer=veth2 polycubectl attach nat1 r1:to_veth2 position=first diff --git a/src/services/pcn-nat/test/test_udp_dnat.sh b/src/services/pcn-nat/test/test_udp_dnat.sh index 0b1c1b3fc..668eac784 100755 --- a/src/services/pcn-nat/test/test_udp_dnat.sh +++ b/src/services/pcn-nat/test/test_udp_dnat.sh @@ -44,8 +44,8 @@ create_veth_net 2 polycubectl nat add nat1 polycubectl router add r1 -polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip netmask=255.255.255.0 peer=veth1 -polycubectl router r1 ports add to_veth2 ip=$to_veth2_ip netmask=255.255.255.0 peer=veth2 +polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip/24 peer=veth1 +polycubectl router r1 ports add to_veth2 ip=$to_veth2_ip/24 peer=veth2 polycubectl attach nat1 r1:to_veth2 position=first diff --git a/src/services/pcn-nat/test/test_udp_masq.sh b/src/services/pcn-nat/test/test_udp_masq.sh index 5bd13a6be..e3bd698f2 100755 --- a/src/services/pcn-nat/test/test_udp_masq.sh +++ b/src/services/pcn-nat/test/test_udp_masq.sh @@ -44,8 +44,8 @@ create_veth_net 2 polycubectl nat add nat1 polycubectl router add r1 -polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip netmask=255.255.255.0 peer=veth1 -polycubectl router r1 ports add to_veth2 ip=$to_veth2_ip netmask=255.255.255.0 peer=veth2 +polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip/24 peer=veth1 +polycubectl router r1 ports add to_veth2 ip=$to_veth2_ip/24 peer=veth2 polycubectl attach nat1 r1:to_veth2 position=first diff --git a/src/services/pcn-nat/test/test_udp_pf.sh b/src/services/pcn-nat/test/test_udp_pf.sh index 4d103b48a..afd18ac40 100755 --- a/src/services/pcn-nat/test/test_udp_pf.sh +++ b/src/services/pcn-nat/test/test_udp_pf.sh @@ -46,8 +46,8 @@ create_veth_net 2 polycubectl nat add nat1 polycubectl router add r1 -polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip netmask=255.255.255.0 peer=veth1 -polycubectl router r1 ports add to_veth2 ip=$to_veth2_ip netmask=255.255.255.0 peer=veth2 +polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip/24 peer=veth1 +polycubectl router r1 ports add to_veth2 ip=$to_veth2_ip/24 peer=veth2 polycubectl attach nat1 r1:to_veth2 position=first diff --git a/src/services/pcn-nat/test/test_udp_snat.sh b/src/services/pcn-nat/test/test_udp_snat.sh index 66b213e5d..783461c58 100755 --- a/src/services/pcn-nat/test/test_udp_snat.sh +++ b/src/services/pcn-nat/test/test_udp_snat.sh @@ -43,8 +43,8 @@ create_veth_net 2 polycubectl nat add nat1 polycubectl router add r1 -polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip netmask=255.255.255.0 peer=veth1 -polycubectl router r1 ports add to_veth2 ip=$to_veth2_ip netmask=255.255.255.0 peer=veth2 +polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip/24 peer=veth1 +polycubectl router r1 ports add to_veth2 ip=$to_veth2_ip/24 peer=veth2 polycubectl attach nat1 r1:to_veth2 position=first diff --git a/src/services/pcn-router/datamodel/router.yang b/src/services/pcn-router/datamodel/router.yang index 20c7ff31c..1165e0fb9 100644 --- a/src/services/pcn-router/datamodel/router.yang +++ b/src/services/pcn-router/datamodel/router.yang @@ -19,35 +19,19 @@ module router { uses "polycube-standard-base:standard-base-yang-module" { augment ports { - leaf ip { - type inet:ipv4-address; - mandatory true; - description "IP address of the port"; - polycube-base:cli-example "207.46.130.1"; - } - - leaf netmask { - type inet:ipv4-address; - mandatory true; - description "Netmask of the port"; - polycube-base:cli-example "255.255.255.0"; + leaf ip { + type inet:ipv4-prefix; + description "IP address and prefix of the port"; + polycube-base:cli-example "10.0.0.1/24"; } list secondaryip { - description "Secondary IP address for the port"; - key "ip netmask"; + description "Additional IP addresses for the port"; + key "ip"; leaf ip { - type inet:ipv4-address; - mandatory true; - description "Seconadary IP address of the port"; - polycube-base:cli-example "207.46.131.1"; - } - - leaf netmask { - type inet:ipv4-address; - mandatory true; - description "Secondary netmask of the port"; - polycube-base:cli-example "255.255.255.0"; + type inet:ipv4-prefix; + description "Secondary IP address and prefix of the port"; + polycube-base:cli-example "10.0.0.2/24"; } } @@ -60,20 +44,13 @@ module router { } list route { - key "network netmask nexthop"; + key "network nexthop"; description "Entry associated with the routing table"; leaf network { - type inet:ipv4-address; + type inet:ipv4-prefix; mandatory true; description "Destination network IP"; - polycube-base:cli-example "123.13.34.0"; - } - - leaf netmask { - type inet:ipv4-address; - mandatory true; - description "Destination network netmask"; - polycube-base:cli-example "255.255.255.0"; + polycube-base:cli-example "10.0.0.0/24"; } leaf nexthop { @@ -99,7 +76,7 @@ module router { } } - list arp-entry { + list arp-table { key "address"; description "Entry associated with the ARP table"; leaf address { @@ -110,7 +87,7 @@ module router { } leaf mac { - type string; + type yang:mac-address; mandatory true; description "Destination MAC address"; polycube-base:cli-example "C5:13:2D:36:27:9B"; diff --git a/src/services/pcn-router/src/ArpEntry.cpp b/src/services/pcn-router/src/ArpEntry.cpp deleted file mode 100644 index 4451a18c1..000000000 --- a/src/services/pcn-router/src/ArpEntry.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2018 The Polycube Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// Modify these methods with your own implementation - -#include "ArpEntry.h" -#include "Router.h" - -ArpEntry::ArpEntry(Router &parent, const ArpEntryJsonObject &conf) - : parent_(parent) { - logger()->info("Creating ArpEntry instance"); -} - -ArpEntry::ArpEntry(Router &parent, const std::string &mac, - const std::string &ip, const std::string &interface) - : parent_(parent), mac_(mac), ip_(ip), interface_(interface) {} - -ArpEntry::~ArpEntry() {} - -void ArpEntry::update(const ArpEntryJsonObject &conf) { - // This method updates all the object/parameter in ArpEntry object specified - // in the conf JsonObject. - // You can modify this implementation. - - setInterface(conf.getInterface()); - - setMac(conf.getMac()); -} - -ArpEntryJsonObject ArpEntry::toJsonObject() { - ArpEntryJsonObject conf; - - conf.setInterface(getInterface()); - - conf.setMac(getMac()); - - conf.setAddress(getAddress()); - - return conf; -} - -std::string ArpEntry::getInterface() { - // This method retrieves the interface value. - return interface_; -} - -void ArpEntry::setInterface(const std::string &value) { - // This method set the interface value. - throw std::runtime_error("[ArpEntry]: Method setInterface not implemented"); -} - -std::string ArpEntry::getMac() { - // This method retrieves the mac value. - return mac_; -} - -void ArpEntry::setMac(const std::string &value) { - // This method set the mac value. - throw std::runtime_error("[ArpEntry]: Method setMac not implemented"); -} - -std::string ArpEntry::getAddress() { - // This method retrieves the address value. - return ip_; -} - -std::shared_ptr ArpEntry::logger() { - return parent_.logger(); -} diff --git a/src/services/pcn-router/src/ArpTable.cpp b/src/services/pcn-router/src/ArpTable.cpp new file mode 100644 index 000000000..1fdf2364a --- /dev/null +++ b/src/services/pcn-router/src/ArpTable.cpp @@ -0,0 +1,54 @@ +/* + * Copyright 2018 The Polycube Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// TODO: Modify these methods with your own implementation + +#include "ArpTable.h" +#include "Router.h" + +ArpTable::ArpTable(Router &parent, const ArpTableJsonObject &conf) + : ArpTableBase(parent) { + logger()->info("Creating ArpTable instance"); +} + +ArpTable::ArpTable(Router &parent, const std::string &mac, + const std::string &ip, const std::string &interface) + : ArpTableBase(parent), mac_(mac), ip_(ip), interface_(interface) {} + +ArpTable::~ArpTable() {} + +std::string ArpTable::getAddress() { + // This method retrieves the address value. + return ip_; +} + +std::string ArpTable::getMac() { + // This method retrieves the mac value. + return mac_; +} + +void ArpTable::setMac(const std::string &value) { + throw std::runtime_error("ArpTable::setMac: Method not implemented"); +} + +std::string ArpTable::getInterface() { + // This method retrieves the interface value. + return interface_; +} + +void ArpTable::setInterface(const std::string &value) { + throw std::runtime_error("ArpTable::setInterface: Method not implemented"); +} diff --git a/src/services/pcn-router/src/ArpEntry.h b/src/services/pcn-router/src/ArpTable.h similarity index 68% rename from src/services/pcn-router/src/ArpEntry.h rename to src/services/pcn-router/src/ArpTable.h index d53029598..af1168301 100644 --- a/src/services/pcn-router/src/ArpEntry.h +++ b/src/services/pcn-router/src/ArpTable.h @@ -16,36 +16,28 @@ #pragma once -#include "../interface/ArpEntryInterface.h" -#include "polycube/services/utils.h" - -#include +#include "../base/ArpTableBase.h" class Router; -using namespace io::swagger::server::model; +using namespace polycube::service::model; struct arp_entry { uint64_t mac; uint32_t port; } __attribute__((packed)); -class ArpEntry : public ArpEntryInterface { +class ArpTable : public ArpTableBase { public: - ArpEntry(Router &parent, const ArpEntryJsonObject &conf); - ArpEntry(Router &parent, const std::string &mac, const std::string &ip, - const std::string &interface); - virtual ~ArpEntry(); - - std::shared_ptr logger(); - void update(const ArpEntryJsonObject &conf) override; - ArpEntryJsonObject toJsonObject() override; + ArpTable(Router &parent, const ArpTableJsonObject &conf); + ArpTable(Router &parent, const std::string &mac, const std::string &ip, + const std::string &interface); + virtual ~ArpTable(); /// - /// Outgoing interface + /// Destination IP address /// - std::string getInterface() override; - void setInterface(const std::string &value) override; + std::string getAddress() override; /// /// Destination MAC address @@ -54,13 +46,12 @@ class ArpEntry : public ArpEntryInterface { void setMac(const std::string &value) override; /// - /// Destination IP address + /// Outgoing interface /// - std::string getAddress() override; + std::string getInterface() override; + void setInterface(const std::string &value) override; private: - Router &parent_; - std::string mac_; std::string ip_; std::string interface_; diff --git a/src/services/pcn-router/src/CMakeLists.txt b/src/services/pcn-router/src/CMakeLists.txt index 8720d1c4c..c782aaf46 100644 --- a/src/services/pcn-router/src/CMakeLists.txt +++ b/src/services/pcn-router/src/CMakeLists.txt @@ -2,39 +2,44 @@ include(${PROJECT_SOURCE_DIR}/cmake/LoadFileAsVariable.cmake) aux_source_directory(serializer SERIALIZER_SOURCES) aux_source_directory(api API_SOURCES) -aux_source_directory(default-src SRC_SOURCES) +aux_source_directory(base BASE_SOURCES) include_directories(serializer) -include_directories(interface) -include_directories(default-src) include_directories(/usr/include/libnl3) +if (NOT DEFINED POLYCUBE_STANDALONE_SERVICE OR POLYCUBE_STANDALONE_SERVICE) + find_package(PkgConfig REQUIRED) + pkg_check_modules(POLYCUBE libpolycube) + include_directories(${POLYCUBE_INCLUDE_DIRS}) +endif(NOT DEFINED POLYCUBE_STANDALONE_SERVICE OR POLYCUBE_STANDALONE_SERVICE) + # Needed to load files as variables include_directories(${CMAKE_CURRENT_BINARY_DIR}) add_library(pcn-router SHARED ${SERIALIZER_SOURCES} ${API_SOURCES} - ${SRC_SOURCES} - ArpEntry.cpp + ${BASE_SOURCES} + ArpTable.cpp Ports.cpp PortsSecondaryip.cpp Route.cpp Router.cpp Router-lib.cpp CircularBuffer.cpp - UtilityMethods.cpp) + Utils.cpp) -# load ebpf datapath code in std::string variables -load_file_as_variable(pcn-router Router_dp.c router_code) +# load ebpf datapath code a variable +load_file_as_variable(pcn-router + Router_dp.c + router_code) # load datamodel in a variable -load_file_as_variable(pcn-router ../datamodel/router.yang router_datamodel) +load_file_as_variable(pcn-router + ../datamodel/router.yang + router_datamodel) -target_link_libraries(pcn-router - polycube - tins - uuid) +target_link_libraries(pcn-router ${POLYCUBE_LIBRARIES}) # Specify shared library install directory diff --git a/src/services/pcn-router/src/Ports.cpp b/src/services/pcn-router/src/Ports.cpp index 21fdd6443..3a90c4454 100644 --- a/src/services/pcn-router/src/Ports.cpp +++ b/src/services/pcn-router/src/Ports.cpp @@ -14,46 +14,59 @@ * limitations under the License. */ -// Modify these methods with your own implementation +// TODO: Modify these methods with your own implementation #include "Ports.h" #include "Router.h" -#include "UtilityMethods.h" #include "../../../polycubed/src/utils/netlink.h" #include "../../../polycubed/src/utils/ns.h" Ports::Ports(polycube::service::Cube &parent, - std::shared_ptr port, - const PortsJsonObject &conf) - : Port(port), parent_(static_cast(parent)) { + std::shared_ptr port, + const PortsJsonObject &conf) + : PortsBase(parent, port) { if (conf.macIsSet()) mac_ = conf.getMac(); - else - mac_ = polycube::service::utils::get_random_mac(); - - if (!is_netmask_valid( - conf.getNetmask())) // TODO: not sure that the validation is needed - throw std::runtime_error("Netmask is in invalid format"); - - ip_ = conf.getIp(); - netmask_ = conf.getNetmask(); - - std::string port_name(getName()); + else { + mac_ = get_random_mac(); + // update mac in the namespace + if (parent_.get_shadow()) { + std::function doThis = [&]{ + parent_.netlink_instance_router_.set_iface_mac(getName(), mac_); + }; + polycube::polycubed::Namespace namespace_ = + polycube::polycubed::Namespace::open("pcn-" + parent_.get_name()); + namespace_.execute(doThis); + } + } - // TODO: check that no other router port exists in the same network + std::string ip_address; + std::string netmask; + uint32_t ip_uint; + uint32_t netmask_uint; + if (conf.ipIsSet()) { + // TODO: check that no other router port exists in the same network + ip_ = conf.getIp(); + split_ip_and_prefix(ip_, ip_address, netmask); + ip_uint = ip_string_to_be_uint(ip_address); + netmask_uint = ip_string_to_be_uint(netmask); + } else { + ip_ = ""; + ip_uint = 0; + netmask_uint = 0; + } /* * Add the port to the datapath */ - auto router_port = parent.get_hash_table("router_port"); r_port value{ - .ip = utils::ip_string_to_be_uint(ip_), - .netmask = utils::ip_string_to_be_uint(netmask_), + .ip = ip_uint, + .netmask = netmask_uint, .secondary_ip = {}, .secondary_netmask = {}, - .mac = utils::mac_string_to_be_uint(mac_), + .mac = mac_string_to_be_uint(mac_), }; uint16_t index = this->index(); @@ -61,24 +74,29 @@ Ports::Ports(polycube::service::Cube &parent, conf.getSecondaryip(); int i = 0; for (auto &addr : secondary_ips) { - value.secondary_ip[i] = utils::ip_string_to_be_uint(addr.getIp()); - value.secondary_netmask[i] = utils::ip_string_to_be_uint(addr.getNetmask()); + std::string secondaryIp = addr.getIp(); + split_ip_and_prefix(secondaryIp, ip_address, netmask); + ip_uint = ip_string_to_be_uint(ip_address); + netmask_uint = ip_string_to_be_uint(netmask); + value.secondary_ip[i] = ip_uint; + value.secondary_netmask[i] = netmask_uint; i++; } router_port.set(index, value); logger()->info( - "Added new port: {0} (index: {4}) [mac: {1} - ip: {2} - netmask: {3}]", - getName(), mac_, ip_, netmask_, index); + "Added new port: {0} (index: {3}) [mac: {1} - ip: {2}]", + getName(), mac_, ip_, index); for (auto &addr : secondary_ips) - logger()->info("\t secondary address: [ip: {0} - netmask: {1}]", - addr.getIp(), addr.getNetmask()); + logger()->info("\t secondary address: [ip: {0}]", addr.getIp()); - /* - * Add two routes in the routing table - */ - parent_.add_local_route(conf.getIp(), conf.getNetmask(), getName(), index); + if (conf.ipIsSet()) { + /* + * Add two routes in the routing table + */ + parent_.add_local_route(conf.getIp(), getName(), index); + } /* * Create an object representing the secondary IP and add the routes related to @@ -86,37 +104,20 @@ Ports::Ports(polycube::service::Cube &parent, */ for (auto &addr : secondary_ips) { - PortsSecondaryip::createInControlPlane(*this, addr.getIp(), - addr.getNetmask(), addr); + PortsSecondaryip::createInControlPlane(*this, addr.getIp(), addr); } // lambda function to align IP and Netmask between Port and ExtIface ParameterEventCallback f_ip; - f_ip = [&](const std::string param_name, const std::string cidr) { + f_ip = [&](const std::string param_name, const std::string new_ip) { try { - if (!cidr.empty()) { + if (!new_ip.empty()) { + if (ip_ == new_ip) + return; + // set the ip address of the netdev on the port - // cidr = ip_address/prefix - std::istringstream split(cidr); - std::vector info; - - char split_char = '/'; - for (std::string each; std::getline(split, each, split_char); - info.push_back(each)) - ; - std::string new_ip = info[0]; - std::string new_netmask = - utils::get_netmask_from_CIDR(std::stoi(info[1])); - - std::string old_ip = getIp(); - std::string old_netmask = getNetmask(); - - logger()->debug("Align ip and netmask of port {0}", name()); - - if (old_ip != new_ip) - setIp_Netlink(new_ip); - if (old_netmask != new_netmask) - setNetmask_Netlink(new_netmask); + logger()->debug("Align ip of the port {0}", name()); + doSetIp(new_ip); } } catch (std::exception &e) { logger()->trace("iface_ip_notification - False ip notification: {0}", @@ -126,12 +127,14 @@ Ports::Ports(polycube::service::Cube &parent, // lambda function to align MAC between Port and ExtIface ParameterEventCallback f_mac; - f_mac = [&](const std::string param_name, const std::string mac) { + f_mac = [&](const std::string param_name, const std::string new_mac) { try { - if (mac_ != mac) { - logger()->debug("Align mac of port {0}", name()); - doSetMac(mac); - } + if (mac_ == new_mac) + return; + + // set the mac address of the netdev on the port + logger()->debug("Align mac of port {0}", name()); + doSetMac(new_mac); } catch (std::exception &e) { logger()->trace("iface_mac_notification - False mac notification: {0}", e.what()); @@ -139,7 +142,9 @@ Ports::Ports(polycube::service::Cube &parent, }; if (!parent_.get_shadow()) { - // Register the new port to IP and MAC notifications arriving from ExtIface + /* Register the new port to IP and MAC notifications arriving from ExtIface + * do not use define because strings are easier to manipulate + * for future extensions */ subscribe_peer_parameter("IP", f_ip); subscribe_peer_parameter("MAC", f_mac); } @@ -152,232 +157,75 @@ Ports::~Ports() { } } -void Ports::update(const PortsJsonObject &conf) { - // This method updates all the object/parameter in Ports object specified in - // the conf JsonObject. - // You can modify this implementation. - Port::set_conf(conf.getBase()); - - logger()->info("Updating port"); - - setIp(conf.getIp()); - - setNetmask(conf.getNetmask()); - - if (conf.macIsSet()) { - setMac(conf.getMac()); - } - - if (conf.secondaryipIsSet()) { - for (auto &i : conf.getSecondaryip()) { - auto ip = i.getIp(); - auto netmask = i.getNetmask(); - auto m = getSecondaryip(ip, netmask); - m->update(i); - } - } -} - -PortsJsonObject Ports::toJsonObject() { - PortsJsonObject conf; - conf.setBase(Port::to_json()); - - conf.setIp(getIp()); - - conf.setNetmask(getNetmask()); - - conf.setMac(getMac()); - - // Remove comments when you implement all sub-methods - for (auto &i : getSecondaryipList()) { - conf.addPortsSecondaryip(i->toJsonObject()); - } - - return conf; -} - std::string Ports::getIp() { // This method retrieves the ip value. - return ip_; } void Ports::setIp(const std::string &value) { // This method set the ip value. - if (ip_ != value) { - // unset old ip - if (parent_.get_shadow()) { - int prefix = get_netmask_length(getNetmask()); - std::function doThis = [&]{ - parent_.netlink_instance_router_.delete_iface_ip(getName(), ip_, prefix); - }; - polycube::polycubed::Namespace namespace_ = polycube::polycubed::Namespace::open("pcn-" + parent_.get_name()); - namespace_.execute(doThis); - } - - setIp_Netlink(value); - - // set new ip - if (parent_.get_shadow()) { - int prefix = get_netmask_length(getNetmask()); - std::function doThis = [&]{ - parent_.netlink_instance_router_.add_iface_ip(getName(), value, prefix); - }; - polycube::polycubed::Namespace namespace_ = polycube::polycubed::Namespace::open("pcn-" + parent_.get_name()); - namespace_.execute(doThis); - } - - // Align Port with the peer interface - int prefix = get_netmask_length(getNetmask()); - std::string cidr = ip_ + "/" + std::to_string(prefix); - set_peer_parameter("IP", cidr); - } -} - -void Ports::setIp_Netlink(const std::string &value) { - // This method set the ip value. - if (ip_ != value) { - std::string new_ip = value; - /* Update the port in the datapath */ - uint16_t index = this->index(); - auto router_port = parent_.get_hash_table("router_port"); - - try { - r_port value = router_port.get(index); - value.ip = utils::ip_string_to_be_uint(new_ip); - } catch (...) { - logger()->error("Port {0} not found in the data path", this->name()); - } - - logger()->debug( - "Updated IP port: {0} (index: {4}) [mac: {1} - ip: {2} - netmask: {3}]", - getName(), getMac(), new_ip, getNetmask(), index); - - /* Update routes in the routing table */ - parent_.remove_local_route(ip_, getNetmask(), getName()); - parent_.add_local_route(new_ip, getNetmask(), getName(), index); - - ip_ = new_ip; - } -} - -std::string Ports::getNetmask() { - // This method retrieves the netmask value. - return netmask_; -} - -void Ports::setNetmask(const std::string &value) { - // This method set the netmask value. - if (netmask_ != value) { - // unset old netmask - if (parent_.get_shadow()) { - int prefix = get_netmask_length(netmask_); - std::function doThis = [&]{ - parent_.netlink_instance_router_.delete_iface_ip(getName(), ip_, prefix); - }; - polycube::polycubed::Namespace namespace_ = polycube::polycubed::Namespace::open("pcn-" + parent_.get_name()); - namespace_.execute(doThis); - } - - setNetmask_Netlink(value); - - // set new netmask - if (parent_.get_shadow()) { - int prefix = get_netmask_length(value); - std::function doThis = [&]{ - parent_.netlink_instance_router_.add_iface_ip(getName(), getIp(), prefix); - }; - polycube::polycubed::Namespace namespace_ = polycube::polycubed::Namespace::open("pcn-" + parent_.get_name()); - namespace_.execute(doThis); - } - - // Align Port with the peer interface - int prefix = get_netmask_length(value); - std::string cidr = getIp() + "/" + std::to_string(prefix); - set_peer_parameter("IP", cidr); - } -} - -void Ports::setNetmask_Netlink(const std::string &value) { - // This method set the netmask value. - if (netmask_ != value) { - std::string new_netmask = value; - /* Update the port in the datapath */ - uint16_t index = this->index(); - auto router_port = parent_.get_hash_table("router_port"); - - try { - r_port value = router_port.get(index); - value.netmask = utils::ip_string_to_be_uint(new_netmask); - } catch (...) { - logger()->error("Port {0} not found in the data path", this->name()); - } - - logger()->debug( - "Updated netmask port: {0} (index: {4}) [mac: {1} - ip: {2} - netmask: {3}]", - getName(), getMac(), getIp(), new_netmask, index); - - /* Update routes in the routing table */ - parent_.remove_local_route(getIp(), netmask_, getName()); - parent_.add_local_route(getIp(), new_netmask, getName(), index); - - netmask_ = new_netmask; + if (ip_ == value) { + return; } -} - -std::string Ports::getMac() { - // This method retrieves the mac value. - return mac_; -} - -void Ports::setMac(const std::string &value) { - // This method set the mac value. - doSetMac(value); + // update ip in the namespace if (parent_.get_shadow()) { std::function doThis = [&]{ - parent_.netlink_instance_router_.set_iface_mac(getName(), mac_); + parent_.netlink_instance_router_.set_iface_cidr(getName(), value); }; polycube::polycubed::Namespace namespace_ = - polycube::polycubed::Namespace::open("pcn-" + parent_.get_name()); + polycube::polycubed::Namespace::open("pcn-" + parent_.get_name()); namespace_.execute(doThis); } - // Align Port with the peer interface - set_peer_parameter("MAC", value); + doSetIp(value); + + if (!parent_.get_shadow()) { + // Align Port with the peer interface + set_peer_parameter("IP", value); + } } -void Ports::doSetMac(const std::string &new_mac) { - if (mac_ == new_mac) { +void Ports::doSetIp(const std::string &new_ip) { + if (ip_ == new_ip) { return; } + std::string ip_address; + std::string netmask; + split_ip_and_prefix(new_ip, ip_address, netmask); + /* Update the port in the datapath */ uint16_t index = this->index(); auto router_port = parent_.get_hash_table("router_port"); - r_port map_value = router_port.get(index); - map_value.mac = utils::mac_string_to_be_uint(new_mac); - router_port.set(index, map_value); + try { + r_port value = router_port.get(index); + value.ip = ip_string_to_be_uint(ip_address); + value.netmask = ip_string_to_be_uint(netmask); + } catch (...) { + logger()->error("Port {0} not found in the data path", this->name()); + } logger()->debug( - "Updated mac port: {0} (index: {4}) [mac: {1} - ip: {2} - netmask: {3}]", - getName(), new_mac, getIp(), getNetmask(), index); + "Updated IP port: {0} (index: {3}) [mac: {1} - ip: {2}]", + getName(), getMac(), new_ip, index); - mac_ = new_mac; -} + /* Update routes in the routing table */ + if (!ip_.empty()) { + parent_.remove_local_route(ip_, getName()); + } + parent_.add_local_route(new_ip, getName(), index); -std::shared_ptr Ports::logger() { - return parent_.logger(); + ip_ = new_ip; } -std::shared_ptr Ports::getSecondaryip( - const std::string &ip, const std::string &netmask) { - logger()->debug("Getting secondary ip [port: {0} - ip: {1} - netmask: {2}]", - getName(), ip, netmask); +std::shared_ptr Ports::getSecondaryip(const std::string &ip) { + logger()->debug("Getting secondary ip [port: {0} - ip: {1}]", + getName(), ip); - for (auto &p : secondary_ips_) { - if ((p.getIp() == ip) && (p.getNetmask() == netmask)) + for (auto p : secondary_ips_) { + if (p.getIp() == ip) return std::make_shared(p); } } @@ -387,23 +235,19 @@ std::vector> Ports::getSecondaryipList() { getName(), secondary_ips_.size()); std::vector> ips_vect; - for (auto &it : secondary_ips_) { + for (auto it : secondary_ips_) { auto ip = it.getIp(); - auto netmask = it.getNetmask(); - ips_vect.push_back(getSecondaryip(ip, netmask)); + ips_vect.push_back(getSecondaryip(ip)); } - return ips_vect; } -void Ports::addSecondaryip(const std::string &ip, const std::string &netmask, - const PortsSecondaryipJsonObject &conf) { +void Ports::addSecondaryip(const std::string &ip, const PortsSecondaryipJsonObject &conf) { /* * First create the port in the control plane */ logger()->info( - "Adding secondary address [port: {0} - ip: {1} - netmask: {2}]", - getName(), ip, netmask); + "Adding secondary address [port: {0} - ip: {1}]", getName(), ip); auto ret = secondary_ips_.emplace(PortsSecondaryip(*this, conf)); @@ -411,32 +255,26 @@ void Ports::addSecondaryip(const std::string &ip, const std::string &netmask, * Then update the port in the data path (this also adds the proper routes in * the routing table) */ - PortsSecondaryip::updatePortInDataPath(*this); + updatePortInDataPath(); } -void Ports::addSecondaryipList( - const std::vector &conf) { - for (auto &i : conf) { - std::string ip_ = i.getIp(); - std::string netmask_ = i.getNetmask(); - addSecondaryip(ip_, netmask_, i); - } +// Basic default implementation, place your extension here (if needed) +void Ports::addSecondaryipList(const std::vector &conf) { + // call default implementation in base class + PortsBase::addSecondaryipList(conf); } -void Ports::replaceSecondaryip(const std::string &ip, - const std::string &netmask, - const PortsSecondaryipJsonObject &conf) { - delSecondaryip(ip, netmask); - std::string ip_ = conf.getIp(); - std::string netmask_ = conf.getNetmask(); - addSecondaryip(ip_, netmask_, conf); +// Basic default implementation, place your extension here (if needed) +void Ports::replaceSecondaryip(const std::string &ip, const PortsSecondaryipJsonObject &conf) { + // call default implementation in base class + PortsBase::replaceSecondaryip(ip, conf); } -void Ports::delSecondaryip(const std::string &ip, const std::string &netmask) { +void Ports::delSecondaryip(const std::string &ip) { // Check that the secondary address exists bool found = false; - for (auto &addr : secondary_ips_) { - if ((addr.getIp() == ip) && (addr.getNetmask() == netmask)) { + for (auto addr : secondary_ips_) { + if (addr.getIp() == ip) { found = true; // remove the port from the data structure secondary_ips_.erase(addr); @@ -448,17 +286,96 @@ void Ports::delSecondaryip(const std::string &ip, const std::string &netmask) { "Address does not exist (or it is not a secondary address)"); // change the port in the datapath - PortsSecondaryip::updatePortInDataPath(*this); + updatePortInDataPath(); - parent_.remove_local_route(ip, netmask, getName()); + parent_.remove_local_route(ip, getName()); } +// Basic default implementation, place your extension here (if needed) void Ports::delSecondaryipList() { - for (auto it = secondary_ips_.begin(); it != secondary_ips_.end();) { - auto tmp = it; - it++; - std::string ip = tmp->getIp(); - std::string netmask = tmp->getNetmask(); - delSecondaryip(ip, netmask); + // call default implementation in base class + PortsBase::delSecondaryipList(); +} + +std::string Ports::getMac() { + // This method retrieves the mac value. + return mac_; +} + +void Ports::setMac(const std::string &value) { + // This method set the mac value. + if (mac_ == value) { + return; + } + + // update mac in the namespace + if (parent_.get_shadow()) { + std::function doThis = [&]{ + parent_.netlink_instance_router_.set_iface_mac(getName(), mac_); + }; + polycube::polycubed::Namespace namespace_ = + polycube::polycubed::Namespace::open("pcn-" + parent_.get_name()); + namespace_.execute(doThis); + } + + doSetMac(value); + + if (!parent_.get_shadow()) { + // Align Port with the peer interface + set_peer_parameter("MAC", value); + } +} + +void Ports::doSetMac(const std::string &new_mac) { + if (mac_ == new_mac) { + return; } + + /* Update the port in the datapath */ + uint16_t index = this->index(); + auto router_port = parent_.get_hash_table("router_port"); + + r_port map_value = router_port.get(index); + map_value.mac = mac_string_to_be_uint(new_mac); + router_port.set(index, map_value); + + logger()->debug( + "Updated mac port: {0} (index: {3}) [mac: {1} - ip: {2}]", + getName(), new_mac, getIp(), index); + + mac_ = new_mac; +} + +void Ports::updatePortInDataPath() { + std::string ip_address; + std::string netmask; + uint32_t ip_uint = 0; + uint32_t netmask_uint = 0; + + split_ip_and_prefix(ip_, ip_address, netmask); + ip_uint = ip_string_to_be_uint(ip_address); + netmask_uint = ip_string_to_be_uint(netmask); + + auto router_port = parent_.get_hash_table("router_port"); + r_port value{ + .ip = ip_uint, + .netmask = netmask_uint, + .secondary_ip = {}, + .secondary_netmask = {}, + .mac = mac_string_to_be_uint(mac_), + }; + + uint16_t index = this->index(); + int i = 0; + for (auto addr : secondary_ips_) { + std::string secondaryIp = addr.getIp(); + split_ip_and_prefix(secondaryIp, ip_address, netmask); + ip_uint = ip_string_to_be_uint(ip_address); + netmask_uint = ip_string_to_be_uint(netmask); + value.secondary_ip[i] = ip_uint; + value.secondary_netmask[i] = netmask_uint; + i++; + } + + router_port.set(index, value); } diff --git a/src/services/pcn-router/src/Ports.h b/src/services/pcn-router/src/Ports.h index 984ddd808..7ccd5d3b7 100644 --- a/src/services/pcn-router/src/Ports.h +++ b/src/services/pcn-router/src/Ports.h @@ -16,88 +16,69 @@ #pragma once -#include "../interface/PortsInterface.h" +#include "../base/PortsBase.h" -#include "polycube/services/cube.h" -#include "polycube/services/port.h" -#include "polycube/services/utils.h" - -#include #include #include "PortsSecondaryip.h" +#include "Utils.h" class Router; -#define SECONDARY_ADDRESS 5 +/* MAX_SECONDARY_ADDRESSES definition in datapath */ +#define MAX_SECONDARY_ADDRESSES 5 /* Router Port definition in datapath*/ struct r_port { uint32_t ip; uint32_t netmask; - uint32_t secondary_ip[SECONDARY_ADDRESS]; - uint32_t secondary_netmask[SECONDARY_ADDRESS]; + uint32_t secondary_ip[MAX_SECONDARY_ADDRESSES]; + uint32_t secondary_netmask[MAX_SECONDARY_ADDRESSES]; uint64_t mac : 48; } __attribute__((packed)); -using namespace io::swagger::server::model; +using namespace polycube::service::model; +using namespace polycube::service::utils; -class Ports : public polycube::service::Port, public PortsInterface { +class Ports : public PortsBase { friend class PortsSecondaryip; public: Ports(polycube::service::Cube &parent, - std::shared_ptr port, - const PortsJsonObject &conf); + std::shared_ptr port, + const PortsJsonObject &conf); virtual ~Ports(); - std::shared_ptr logger(); - void update(const PortsJsonObject &conf) override; - PortsJsonObject toJsonObject() override; - /// - /// IP address of the port + /// IP address and prefix of the port /// std::string getIp() override; void setIp(const std::string &value) override; - void setIp_Netlink(const std::string &value); + void doSetIp(const std::string &new_ip); /// - /// Netmask of the port + /// Additional IP addresses for the port /// - std::string getNetmask() override; - void setNetmask(const std::string &value) override; - void setNetmask_Netlink(const std::string &value); + std::shared_ptr getSecondaryip(const std::string &ip) override; + std::vector> getSecondaryipList() override; + void addSecondaryip(const std::string &ip, const PortsSecondaryipJsonObject &conf) override; + void addSecondaryipList(const std::vector &conf) override; + void replaceSecondaryip(const std::string &ip, const PortsSecondaryipJsonObject &conf) override; + void delSecondaryip(const std::string &ip) override; + void delSecondaryipList() override; /// /// MAC address of the port /// std::string getMac() override; void setMac(const std::string &value) override; - void doSetMac(const std::string &value); + void doSetMac(const std::string &new_mac); - /// - /// Secondary IP address for the port - /// - std::shared_ptr getSecondaryip( - const std::string &ip, const std::string &netmask) override; - std::vector> getSecondaryipList() override; - void addSecondaryip(const std::string &ip, const std::string &netmask, - const PortsSecondaryipJsonObject &conf) override; - void addSecondaryipList( - const std::vector &conf) override; - void replaceSecondaryip(const std::string &ip, const std::string &netmask, - const PortsSecondaryipJsonObject &conf) override; - void delSecondaryip(const std::string &ip, - const std::string &netmask) override; - void delSecondaryipList() override; + protected: + void updatePortInDataPath(); private: - Router &parent_; - std::string mac_; std::string ip_; - std::string netmask_; - std::set secondary_ips_; }; diff --git a/src/services/pcn-router/src/PortsSecondaryip.cpp b/src/services/pcn-router/src/PortsSecondaryip.cpp index 80c7b59b7..2b90f2e37 100644 --- a/src/services/pcn-router/src/PortsSecondaryip.cpp +++ b/src/services/pcn-router/src/PortsSecondaryip.cpp @@ -14,87 +14,51 @@ * limitations under the License. */ -// Modify these methods with your own implementation +// TODO: Modify these methods with your own implementation #include "PortsSecondaryip.h" #include "Router.h" +#include "Ports.h" -#include -PortsSecondaryip::PortsSecondaryip(Ports &parent, - const PortsSecondaryipJsonObject &conf) - : parent_(parent) { +PortsSecondaryip::PortsSecondaryip(Ports &parent, const PortsSecondaryipJsonObject &conf) + : PortsSecondaryipBase(parent) { + // TODO: check that no other router port exists in the same network ip_ = conf.getIp(); - netmask_ = conf.getNetmask(); - - parent.logger()->debug("Adding secondary address [ip: {0} - netmask: {1}]", - ip_, netmask_); + parent.logger()->debug("Adding secondary address [ip: {0}]", ip_); - // TODO: check that no other router port exists in the same network + int max_address = MAX_SECONDARY_ADDRESSES; + if (parent.secondary_ips_.size() >= max_address) { + throw std::runtime_error("Maximum number of secondary IPs on the port " + + parent.getName()); + } /* * Add two routes in the routing table */ int index = parent.parent_.Cube::get_port(parent.getName())->index(); - parent.parent_.add_local_route(ip_, netmask_, parent.getName(), index); + parent.parent_.add_local_route(ip_, parent.getName(), index); } PortsSecondaryip::~PortsSecondaryip() {} -void PortsSecondaryip::update(const PortsSecondaryipJsonObject &conf) { - // This method updates all the object/parameter in PortsSecondaryip object - // specified in the conf JsonObject. - // You can modify this implementation. -} - -PortsSecondaryipJsonObject PortsSecondaryip::toJsonObject() { - PortsSecondaryipJsonObject conf; - - conf.setIp(getIp()); - - conf.setNetmask(getNetmask()); - - return conf; -} - -// TODO: move in the Ports class? Probably it is better -void PortsSecondaryip::updatePortInDataPath(Ports &parent) { - auto router_port = - parent.parent_.get_hash_table("router_port"); - - r_port value{ - .ip = utils::ip_string_to_be_uint(parent.getIp()), - .netmask = utils::ip_string_to_be_uint(parent.getNetmask()), - .secondary_ip = {}, - .secondary_netmask = {}, - .mac = utils::mac_string_to_be_uint(parent.getMac()), - }; - - uint16_t index = parent.parent_.get_port(parent.getName())->index(); - int i = 0; - for (auto &addr : parent.getSecondaryipList()) { - value.secondary_ip[i] = utils::ip_string_to_be_uint(addr->getIp()); - value.secondary_netmask[i] = - utils::ip_string_to_be_uint(addr->getNetmask()); - i++; - } - - router_port.set(index, value); +std::string PortsSecondaryip::getIp() { + // This method retrieves the ip value. + return ip_; } void PortsSecondaryip::createInControlPlane( - Ports &parent, const std::string &ip, const std::string &netmask, + Ports &parent, const std::string &ip, const PortsSecondaryipJsonObject &conf) { // This method creates the actual PortsSecondaryip object given thee key // param. - // TODO: a port cannot have more than SECONDARY_ADDRESS secondary addresses. + // TODO: a port cannot have more than MAX_SECONDARY_ADDRESSES secondary addresses. // This constraint come - // from a constant defined in the fast path + // from a constant defined in the fast paths parent.logger()->info( - "Adding secondary address [port: {0} - ip: {1} - netmask: {2}]", - parent.getName(), ip, netmask); + "Adding secondary address [port: {0} - ip: {1}]", parent.getName(), ip); parent.logger()->info("Port {0} has already {1} secondary addresses", parent.getName(), parent.secondary_ips_.size()); @@ -102,17 +66,3 @@ void PortsSecondaryip::createInControlPlane( parent.logger()->info("Now port {0} has {1} secondary addresses", parent.getName(), parent.secondary_ips_.size()); } - -std::string PortsSecondaryip::getIp() const { - // This method retrieves the ip value. - return ip_; -} - -std::string PortsSecondaryip::getNetmask() const { - // This method retrieves the netmask value. - return netmask_; -} - -std::shared_ptr PortsSecondaryip::logger() { - return parent_.logger(); -} diff --git a/src/services/pcn-router/src/PortsSecondaryip.h b/src/services/pcn-router/src/PortsSecondaryip.h index 7ff93f240..5d376f969 100644 --- a/src/services/pcn-router/src/PortsSecondaryip.h +++ b/src/services/pcn-router/src/PortsSecondaryip.h @@ -16,51 +16,32 @@ #pragma once -#include "../interface/PortsSecondaryipInterface.h" - -#include +#include "../base/PortsSecondaryipBase.h" class Ports; -using namespace io::swagger::server::model; +using namespace polycube::service::model; -class PortsSecondaryip : public PortsSecondaryipInterface { +class PortsSecondaryip : public PortsSecondaryipBase { public: PortsSecondaryip(Ports &parent, const PortsSecondaryipJsonObject &conf); virtual ~PortsSecondaryip(); - std::shared_ptr logger(); - void update(const PortsSecondaryipJsonObject &conf) override; - PortsSecondaryipJsonObject toJsonObject() override; - - /// - /// Seconadary IP address of the port - /// - std::string getIp() const override; - /// - /// Secondary netmask of the port + /// Secondary IP address and prefix of the port /// - std::string getNetmask() const override; + std::string getIp() override; // The following methods have been added manually static void createInControlPlane(Ports &parent, const std::string &ip, - const std::string &netmask, const PortsSecondaryipJsonObject &conf); bool operator<(const PortsSecondaryip &p) const { - return std::tie(ip_, netmask_) < std::tie(p.ip_, p.netmask_); + return std::tie(ip_) < std::tie(p.ip_); } - static void updatePortInDataPath(Ports &parent); - private: - Ports &parent_; - // The following variables have been added manually std::string ip_; - std::string netmask_; - - // The following methods have been added manually }; diff --git a/src/services/pcn-router/src/Route.cpp b/src/services/pcn-router/src/Route.cpp index fed0902f6..90e6e9ed5 100644 --- a/src/services/pcn-router/src/Route.cpp +++ b/src/services/pcn-router/src/Route.cpp @@ -14,17 +14,15 @@ * limitations under the License. */ -// Modify these methods with your own implementation +// TODO: Modify these methods with your own implementation #include "Route.h" #include "Router.h" -Route::Route(Router &parent, const RouteJsonObject &conf) : parent_(parent) { +Route::Route(Router &parent, const RouteJsonObject &conf) + : RouteBase(parent) { logger()->info("Creating Route instance"); - // TODO: check the validity of the netmask - - netmask_ = conf.getNetmask(); network_ = conf.getNetwork(); nexthop_ = conf.getNexthop(); @@ -33,9 +31,8 @@ Route::Route(Router &parent, const RouteJsonObject &conf) : parent_(parent) { pathcost_ = conf.getPathcost(); parent.logger()->debug( - "Adding route [network: {0} - netmask: {1} - nexthop: {2} - path cost: " - "{3}]", - network_, netmask_, nexthop_, pathcost_); + "Adding route [network: {0} - nexthop: {1} - path cost: {2}]", + network_, nexthop_, pathcost_); // identify the interface of the router to be used to reach the nexthop if (!conf.interfaceIsSet()) { @@ -45,21 +42,18 @@ Route::Route(Router &parent, const RouteJsonObject &conf) : parent_(parent) { } parent.logger()->info( - "Adding route [network: {0} - netmask: {1} - nexthop: {2} - interface: " - "{3} - path cost: {4}]", - network_, netmask_, nexthop_, interface_, pathcost_); + "Adding route [network: {0} - nexthop: {1} - interface: {2} " + "- path cost: {3}]", network_, nexthop_, interface_, pathcost_); int port_id = parent.get_port(interface_)->index(); - parent.add_active_nexthop_in_ebpf_map(network_, netmask_, nexthop_, + parent.add_active_nexthop_in_ebpf_map(network_, nexthop_, conf.getPathcost(), port_id); } -Route::Route(Router &parent, std::string network, const std::string &netmask, - const std::string &nexthop, const std::string &interface, - const uint32_t pathcost) - : parent_(parent) { - netmask_ = netmask; +Route::Route(Router &parent, std::string network, const std::string &nexthop, + const std::string &interface, const uint32_t pathcost) + : RouteBase(parent) { network_ = network; nexthop_ = nexthop; interface_ = interface; @@ -69,40 +63,9 @@ Route::Route(Router &parent, std::string network, const std::string &netmask, Route::~Route() {} -void Route::update(const RouteJsonObject &conf) { - // This method updates all the object/parameter in Route object specified in - // the conf JsonObject. - // You can modify this implementation. - - if (conf.pathcostIsSet()) { - setPathcost(conf.getPathcost()); - } -} - -RouteJsonObject Route::toJsonObject() { - RouteJsonObject conf; - - conf.setInterface(getInterface()); - - conf.setNetmask(getNetmask()); - - conf.setNexthop(getNexthop()); - - conf.setNetwork(getNetwork()); - - conf.setPathcost(getPathcost()); - - return conf; -} - -std::string Route::getInterface() { - // This method retrieves the interface value. - return interface_; -} - -std::string Route::getNetmask() { - // This method retrieves the netmask value. - return netmask_; +std::string Route::getNetwork() { + // This method retrieves the network value. + return network_; } std::string Route::getNexthop() { @@ -110,9 +73,9 @@ std::string Route::getNexthop() { return nexthop_; } -std::string Route::getNetwork() { - // This method retrieves the network value. - return network_; +std::string Route::getInterface() { + // This method retrieves the interface value. + return interface_; } uint32_t Route::getPathcost() { @@ -121,12 +84,7 @@ uint32_t Route::getPathcost() { } void Route::setPathcost(const uint32_t &value) { - // This method set the pathcost value. - throw std::runtime_error("[Route]: Method setPathcost not implemented"); -} - -std::shared_ptr Route::logger() { - return parent_.logger(); + throw std::runtime_error("Route::setPathcost: Method not implemented"); } bool Route::pathcostIsSet() { diff --git a/src/services/pcn-router/src/Route.h b/src/services/pcn-router/src/Route.h index e12e8cc8a..44c5fea42 100644 --- a/src/services/pcn-router/src/Route.h +++ b/src/services/pcn-router/src/Route.h @@ -16,21 +16,13 @@ #pragma once -#include "../interface/RouteInterface.h" - -#include +#include "../base/RouteBase.h" #include -#include "polycube/services/cube.h" -#include "polycube/services/port.h" -#include "polycube/services/utils.h" - -#include "ArpEntry.h" +#include "ArpTable.h" #include "Ports.h" -#include "UtilityMethods.h" - #include "CircularBuffer.h" #include @@ -47,47 +39,31 @@ #define TYPE_NOLOCALINTERFACE 0 // used to compare the 'type' field in the rt_v #define TYPE_LOCALINTERFACE 1 -using polycube::service::CubeType; -using namespace polycube::service; - -using namespace Tins; - class Router; -using namespace io::swagger::server::model; +using namespace polycube::service::model; -class Route : public RouteInterface { +class Route : public RouteBase { public: Route(Router &parent, const RouteJsonObject &conf); - Route(Router &parent, const std::string network, const std::string &netmask, - const std::string &nexthop, const std::string &interface, - const uint32_t pathcost); + Route(Router &parent, const std::string network, const std::string &nexthop, + const std::string &interface, const uint32_t pathcost); virtual ~Route(); - std::shared_ptr logger(); - void update(const RouteJsonObject &conf) override; - RouteJsonObject toJsonObject() override; - /// - /// Outgoing interface - /// - std::string getInterface() override; - - /// - /// Destination network netmask + /// Destination network IP /// - std::string getNetmask() override; + std::string getNetwork() override; /// - /// Next hop; if destination is local will be shown 'local' instead of - /// the ip address + /// Next hop; if destination is local will be shown 'local' instead of the ip address /// std::string getNexthop() override; /// - /// Destination network IP + /// Outgoing interface /// - std::string getNetwork() override; + std::string getInterface() override; /// /// Cost of this route @@ -96,15 +72,11 @@ class Route : public RouteInterface { void setPathcost(const uint32_t &value) override; // The following methods have been added manually - bool pathcostIsSet(); private: - Router &parent_; - // The following attributes have been added manually std::string network_; - std::string netmask_; std::string nexthop_; std::string interface_; uint32_t pathcost_; diff --git a/src/services/pcn-router/src/Router-lib.cpp b/src/services/pcn-router/src/Router-lib.cpp index a20521066..95b7df046 100644 --- a/src/services/pcn-router/src/Router-lib.cpp +++ b/src/services/pcn-router/src/Router-lib.cpp @@ -1,12 +1,8 @@ /** -* router API * router API generated from router.yang * -* OpenAPI spec version: 1.0.0 -* -* NOTE: This class is auto generated by the swagger code generator program. -* https://github.com/polycube-network/swagger-codegen.git -* branch polycube +* NOTE: This file is auto generated by polycube-codegen +* https://github.com/polycube-network/polycube-codegen */ @@ -16,7 +12,7 @@ #include "../datamodel/router.h" // generated from datamodel #define SERVICE_PYANG_GIT "" -#define SERVICE_SWAGGER_CODEGEN_GIT "implement_help_in_framework/be2c60c" +#define SERVICE_SWAGGER_CODEGEN_GIT "GIT_REPO_ID" #include diff --git a/src/services/pcn-router/src/Router.cpp b/src/services/pcn-router/src/Router.cpp index cee1c5602..fc403f201 100644 --- a/src/services/pcn-router/src/Router.cpp +++ b/src/services/pcn-router/src/Router.cpp @@ -14,14 +14,11 @@ * limitations under the License. */ -// Modify these methods with your own implementation +// TODO: Modify these methods with your own implementation #include "Router.h" #include "Router_dp.h" -using utils::ip_string_to_be_uint; -using utils::be_uint_to_ip_string; - enum { SLOWPATH_ARP_REPLY = 1, SLOWPATH_ARP_LOOKUP_MISS, @@ -30,14 +27,14 @@ enum { }; Router::Router(const std::string name, const RouterJsonObject &conf) - : Cube(conf.getBase(), {generate_code()}, {}), + : Cube(conf.getBase(), { router_code }, {}), + RouterBase(name), netlink_instance_router_(polycube::polycubed::Netlink::getInstance()) { - logger()->set_pattern("[%Y-%m-%d %H:%M:%S.%e] [Router] [%n] [%l] %v"); logger()->info("Creating Router instance"); addPortsList(conf.getPorts()); - addArpEntryList(conf.getArpEntry()); addRouteList(conf.getRoute()); + addArpTableList(conf.getArpTable()); if (get_shadow()) { // netlink notification @@ -64,6 +61,7 @@ Router::Router(const std::string name, const RouterJsonObject &conf) } Router::~Router() { + logger()->info("Destroying Router instance"); if (get_shadow()) { netlink_instance_router_.unregisterObserver( polycube::polycubed::Netlink::Event::ROUTE_ADDED, @@ -80,92 +78,269 @@ Router::~Router() { } } -void Router::update(const RouterJsonObject &conf) { - // This method updates all the object/parameter in Router object specified in - // the conf JsonObject. - // You can modify this implementation. - Cube::set_conf(conf.getBase()); - - if (conf.arpEntryIsSet()) { - for (auto &i : conf.getArpEntry()) { - auto address = i.getAddress(); - auto m = getArpEntry(address); - m->update(i); - } - } +void Router::packet_in(Ports &port, + polycube::service::PacketInMetadata &md, + const std::vector &packet) { + logger()->debug("Packet received from port {0}", port.name()); - if (conf.routeIsSet()) { - for (auto &i : conf.getRoute()) { - auto network = i.getNetwork(); - auto netmask = i.getNetmask(); - auto nexthop = i.getNexthop(); - auto m = getRoute(network, netmask, nexthop); - m->update(i); - } + switch (md.reason) { + case SLOWPATH_TTL_EXCEEDED: + generate_icmp_ttlexceed(port, md, packet); + break; + + case SLOWPATH_ARP_LOOKUP_MISS: + generate_arp_request(port, md, packet); + break; + + case SLOWPATH_ARP_REPLY: + generate_arp_reply(port, md, packet); + break; + + case SLOWPATH_PKT_FOR_ROUTER: + handle_router_pkt(port, md, packet); + break; + + default: + logger()->error("Not valid reason {0} received", md.reason); } +} - if (conf.portsIsSet()) { - for (auto &i : conf.getPorts()) { - auto name = i.getName(); - auto m = getPorts(name); - m->update(i); - } +// Basic default implementation, place your extension here (if needed) +std::shared_ptr Router::getPorts(const std::string &name) { + // call default implementation in base class + return RouterBase::getPorts(name); +} + +// Basic default implementation, place your extension here (if needed) +std::vector> Router::getPortsList() { + // call default implementation in base class + return RouterBase::getPortsList(); +} + +// Basic default implementation, place your extension here (if needed) +void Router::addPorts(const std::string &name, const PortsJsonObject &conf) { + RouterBase::addPorts(name, conf); + if (get_shadow()) { + // this aligns the mac of the port with that of the veth in the namespace + getPorts(name)->setMac(getPorts(name)->getMac()); } } -RouterJsonObject Router::toJsonObject() { - RouterJsonObject conf; - conf.setBase(Cube::to_json()); +// Basic default implementation, place your extension here (if needed) +void Router::addPortsList(const std::vector &conf) { + // call default implementation in base class + RouterBase::addPortsList(conf); +} - for (auto &i : getArpEntryList()) { - conf.addArpEntry(i->toJsonObject()); +// Basic default implementation, place your extension here (if needed) +void Router::replacePorts(const std::string &name, + const PortsJsonObject &conf) { + // call default implementation in base class + RouterBase::replacePorts(name, conf); +} + +// Basic default implementation, place your extension here (if needed) +void Router::delPorts(const std::string &name) { + logger()->info("Remove port {0}", name); + + auto port = get_port(name); + + // remove the secondary addresses of the port (and the related routes in the + // routing table) + port->delSecondaryipList(); + + remove_local_route(port->getIp(), name); + + auto router_port = get_hash_table("router_port"); + + // remove the port from the datapath + uint16_t index = port->index(); + router_port.remove(index); + logger()->debug("Removed from 'router_port' - key: {0}", int_to_hex(index)); + + // call default implementation in base class + RouterBase::delPorts(name); + + logger()->info("Port {0} was removed", name); +} + +// Basic default implementation, place your extension here (if needed) +void Router::delPortsList() { + // call default implementation in base class + RouterBase::delPortsList(); +} + +std::shared_ptr Router::getRoute(const std::string &network, + const std::string &nexthop) { + std::tuple key(network, nexthop); + + return std::shared_ptr(&routes_.at(key), [](Route *) {}); +} + +std::vector> Router::getRouteList() { + std::vector> routes_vect; + for (auto &it : routes_) { + routes_vect.push_back(getRoute(it.second.getNetwork(), + it.second.getNexthop())); + logger()->debug("\t'route [network: {0} - nexthop: {1}]", + it.second.getNetwork(), it.second.getNexthop()); } - for (auto &i : getRouteList()) { - conf.addRoute(i->toJsonObject()); + return routes_vect; +} + +void Router::addRoute(const std::string &network, + const std::string &nexthop, + const RouteJsonObject &conf) { + logger()->debug( + "Trying to add route [network: {0} - nexthop: {1}]", network, nexthop); + + std::tuple key(network, nexthop); + + if (routes_.count(key) != 0) + throw std::runtime_error("Route already exists"); + + routes_.emplace(std::piecewise_construct, std::forward_as_tuple(key), + std::forward_as_tuple(*this, conf)); +} + +// Basic default implementation, place your extension here (if needed) +void Router::addRouteList(const std::vector &conf) { + // call default implementation in base class + RouterBase::addRouteList(conf); +} + +// Basic default implementation, place your extension here (if needed) +void Router::replaceRoute(const std::string &network, + const std::string &nexthop, + const RouteJsonObject &conf) { + // call default implementation in base class + RouterBase::replaceRoute(network, nexthop, conf); +} + +void Router::delRoute(const std::string &network, const std::string &nexthop) { + logger()->debug( + "Trying to remove route [network: {0} - nexthop: {1}]", network, nexthop); + + // FIXME: is this good? cannot users delete "local" routes. + // It is possible in linux + if (nexthop == "local") // FIXME: use constants for these two values + throw std::runtime_error("Users can not delete a local route"); + + remove_route(network, nexthop); +} + +// Basic default implementation, place your extension here (if needed) +void Router::delRouteList() { + // call default implementation in base class + RouterBase::delRouteList(); +} + +std::shared_ptr Router::getArpTable(const std::string &address) { + uint32_t ip_key = ip_string_to_be_uint(address); + + try { + auto arp_table = get_hash_table("arp_table"); + + arp_entry entry = arp_table.get(ip_key); + std::string mac = be_uint_to_mac_string(entry.mac); + auto port = get_port(entry.port); + + return std::make_shared( + ArpTable(*this, mac, address, port->name())); + } catch (std::exception &e) { + logger()->error("Unable to find ARP table entry for address {0}. {1}", + address, e.what()); + throw std::runtime_error("ARP table entry not found"); } +} + +std::vector> Router::getArpTableList() { + std::vector> arp_table_entries; + + // The ARP table is read from the data path + try { + auto arp_table = get_hash_table("arp_table"); + auto arp_entries = arp_table.get_all(); + + for (auto &entry : arp_entries) { + auto key = entry.first; + auto value = entry.second; + + std::string ip = be_uint_to_ip_string(key); + std::string mac = be_uint_to_mac_string(value.mac); + + auto port = get_port(value.port); - for (auto &i : getPortsList()) { - conf.addPorts(i->toJsonObject()); + logger()->debug("Returning entry [ip: {0} - mac: {1} - interface: {2}]", + ip, mac, port->name()); + + arp_table_entries.push_back( + std::make_shared(ArpTable(*this, mac, ip, port->name()))); + } + } catch (std::exception &e) { + logger()->error("Error while trying to get the ARP table"); + throw std::runtime_error("Unable to get the ARP table list"); } - return conf; + return arp_table_entries; } -std::string Router::generate_code() { - return router_code; +void Router::addArpTable(const std::string &address, + const ArpTableJsonObject &conf) { + logger()->debug("Creating ARP entry [ip: {0} - mac: {1} - interface: {2}", + address, conf.getMac(), conf.getInterface()); + + uint64_t mac = mac_string_to_be_uint(conf.getMac()); + uint32_t index = get_port(conf.getInterface())->index(); + + // FIXME: Check if entry already exists? + auto arp_table = get_hash_table("arp_table"); + arp_table.set(ip_string_to_be_uint(address), + arp_entry{.mac = mac, .port = index}); } -std::vector Router::generate_code_vector() { - throw std::runtime_error("Method not implemented"); +// Basic default implementation, place your extension here (if needed) +void Router::addArpTableList(const std::vector &conf) { + // call default implementation in base class + RouterBase::addArpTableList(conf); } -void Router::packet_in(Ports &port, PacketInMetadata &md, - const std::vector &packet) { - logger()->debug("Packet received from port {0}", port.name()); +// Basic default implementation, place your extension here (if needed) +void Router::replaceArpTable(const std::string &address, + const ArpTableJsonObject &conf) { + // call default implementation in base class + RouterBase::replaceArpTable(address, conf); +} - switch (md.reason) { - case SLOWPATH_TTL_EXCEEDED: - generate_icmp_ttlexceed(port, md, packet); - break; +void Router::delArpTable(const std::string &address) { + std::shared_ptr entry; - case SLOWPATH_ARP_LOOKUP_MISS: - generate_arp_request(port, md, packet); - break; + try { + entry = getArpTable(address); + } catch (std::exception &e) { + logger()->error("Unable to remove the ARP table entry for address {0}. {1}", + address, e.what()); + throw std::runtime_error("ARP table entry not found"); + } - case SLOWPATH_ARP_REPLY: - generate_arp_reply(port, md, packet); - break; + uint32_t key = ip_string_to_be_uint(address); - case SLOWPATH_PKT_FOR_ROUTER: - handle_router_pkt(port, md, packet); - break; + auto arp_table = get_hash_table("arp_table"); - default: - logger()->error("Not valid reason {0} received", md.reason); + try { + arp_table.remove(key); + } catch (...) { + throw std::runtime_error("ARP table entry not found"); } } +// Basic default implementation, place your extension here (if needed) +void Router::delArpTableList() { + // call default implementation in base class + RouterBase::delArpTableList(); +} + /* * Methods to manage routing table in the datapath */ @@ -176,14 +351,16 @@ void Router::packet_in(Ports &port, PacketInMetadata &md, std::string Router::search_interface_from_nexthop(const std::string &nexthop) { for (auto item : routes_) { auto &network_ = std::get<0>(item.first); - auto &netmask_ = std::get<1>(item.first); - auto &nexthop_ = std::get<2>(item.first); + auto &nexthop_ = std::get<1>(item.first); // ignore non directly reachable routes if (nexthop_ != "local" && nexthop_ != "0.0.0.0") { continue; } - if (address_in_subnet(network_, netmask_, nexthop)) { + std::string ip_route; + std::string netmask_route; + split_ip_and_prefix(network_, ip_route, netmask_route); + if (address_in_subnet(ip_route, netmask_route, nexthop)) { return item.second.getInterface(); } } @@ -196,19 +373,20 @@ std::string Router::search_interface_from_nexthop(const std::string &nexthop) { * towards the given destination */ void Router::add_active_nexthop_in_ebpf_map(const std::string &network, - const std::string &netmask, - const std::string &nexthop, - int32_t new_pathcost, - const int &port_id) { + const std::string &nexthop, + int32_t new_pathcost, + const int &port_id) { int index = port_id; std::string new_nexthop = nexthop; int32_t min = INT32_MAX; + std::string ip_route; + std::string netmask_route; + split_ip_and_prefix(network, ip_route, netmask_route); // Iterate over the current elements of the routing table for (auto elem : routes_) { - if (elem.second.getNetwork() == network && - elem.second.getNetmask() == netmask) { + if (elem.second.getNetwork() == network) { if (elem.second.getNexthop() == "local") { logger()->debug( "There is a local entry. Route do not added to the datapath"); @@ -244,8 +422,8 @@ void Router::add_active_nexthop_in_ebpf_map(const std::string &network, auto routing_table = get_hash_table("routing_table"); rt_k key{ - .netmask_len = get_netmask_length(netmask), - .network = ip_string_to_be_uint(network), + .netmask_len = get_netmask_length(netmask_route), + .network = ip_string_to_be_uint(ip_route), }; rt_v value{ @@ -264,20 +442,18 @@ void Router::add_active_nexthop_in_ebpf_map(const std::string &network, * is then added to the data plane. */ void Router::remove_route(const std::string &network, - const std::string &netmask, const std::string &nexthop) { - std::tuple key(network, netmask, nexthop); + std::tuple key(network, nexthop); if (routes_.count(key) == 0) throw std::runtime_error("Route does not exist"); routes_.erase(key); logger()->debug( - "Removed route from control plane [network: {0} - netmask: {1} - " - "nexthop: {2}]", - network, netmask, nexthop); + "Removed route from control plane [network: {0} - nexthop: {1}]", + network, nexthop); - find_new_active_nexthop(network, netmask, nexthop); + find_new_active_nexthop(network, nexthop); } /* @@ -295,21 +471,22 @@ void Router::remove_all_routes() { for (auto it = routes_.begin(); it != routes_.end();) { if ((it->second.getNexthop()) != "local") { std::string network = it->second.getNetwork(); - std::string netmask = it->second.getNetmask(); std::string nexthop = it->second.getNexthop(); routes_.erase(it++); logger()->debug( - "Removed route from control plane [network: {0} - netmask: {1} - " - "nexthop: {2}]", - network, netmask, nexthop); + "Removed route from control plane [network: {0} - nexthop: {1}]", + network, nexthop); // retrieve the entry from the fast path for the "netmask" "network", and // get the nexthop in order to check whether the route is also in the fast // path + std::string ip_route; + std::string netmask_route; + split_ip_and_prefix(network, ip_route, netmask_route); try { rt_k key{ - .netmask_len = get_netmask_length(netmask), - .network = ip_string_to_be_uint(network), + .netmask_len = ip_string_to_be_uint(netmask_route), + .network = ip_string_to_be_uint(ip_route), }; rt_v value = routing_table.get(key); @@ -327,10 +504,8 @@ void Router::remove_all_routes() { } } else { logger()->debug( - "Local route not removed [network: {0} - netmask: {1} - nexthop: " - "{2}]", - it->second.getNetwork(), it->second.getNetmask(), - it->second.getNexthop()); + "Local route not removed [network: {0} - nexthop: {1}]", + it->second.getNetwork(), it->second.getNexthop()); it++; } } @@ -340,7 +515,6 @@ void Router::remove_all_routes() { * Add two local routes to the routing table */ void Router::add_local_route(const std::string &interface_ip, - const std::string &interface_netmask, const std::string &port_name, const int port_index) { /* @@ -349,11 +523,15 @@ void Router::add_local_route(const std::string &interface_ip, * interface") */ + std::string ip_route; + std::string netmask_route; + split_ip_and_prefix(interface_ip, ip_route, netmask_route); + auto routing_table = get_hash_table("routing_table"); rt_k key{ .netmask_len = 32, /* /32 -> 255.255.255.255 */ - .network = ip_string_to_be_uint(interface_ip), + .network = ip_string_to_be_uint(ip_route), }; rt_v value{ @@ -365,9 +543,8 @@ void Router::add_local_route(const std::string &interface_ip, routing_table.set(key, value); logger()->info( - "Added route [network: {0} - netmask: {1} - nexthop: {2} - interface: " - "{3}]", - interface_ip, "255.255.255.255", "0.0.0.0", port_name); + "Added route [network: {0}/32 - nexthop: {1} - interface: {2}]", + ip_route, "0.0.0.0", port_name); /* * Add a route to the local network, i.e., to the network directly reachable @@ -375,11 +552,11 @@ void Router::add_local_route(const std::string &interface_ip, */ // Add the route in the fast path - uint32_t networkDec = ip_string_to_be_uint(interface_ip) & - ip_string_to_be_uint(interface_netmask); + uint32_t networkDec = ip_string_to_be_uint(ip_route) & + ip_string_to_be_uint(netmask_route); std::string network = be_uint_to_ip_string(networkDec); rt_k key2{ - .netmask_len = get_netmask_length(interface_netmask), + .netmask_len = get_netmask_length(netmask_route), .network = networkDec, }; @@ -392,19 +569,20 @@ void Router::add_local_route(const std::string &interface_ip, routing_table.set(key2, value2); logger()->info( - "Added route [network: {0} - netmask: {1} - nexthop: {2} - interface: " - "{3}]", - network, interface_netmask, "0.0.0.0", port_name); + "Added route [network: {0}/{1} - nexthop: {2} - interface: {3}]", + network, get_netmask_length(netmask_route), "0.0.0.0", port_name); // Add the route in the table of the control plane std::string nexthop("local"); - std::tuple keyF(network, interface_netmask, nexthop); + std::string route = network + "/" + + std::to_string(get_netmask_length(netmask_route)); + std::tuple keyF(route, nexthop); uint32_t pathcost = 0; routes_.emplace(std::piecewise_construct, std::forward_as_tuple(keyF), - std::forward_as_tuple(*this, network, interface_netmask, - nexthop, port_name, pathcost)); + std::forward_as_tuple(*this, route, nexthop, + port_name, pathcost)); // FIXME: add also the /32 route? } @@ -413,9 +591,13 @@ void Router::add_local_route(const std::string &interface_ip, * Remove two local route from the routing table */ void Router::remove_local_route(const std::string &interface_ip, - const std::string &interface_netmask, const std::string &port_name) { - std::string network = get_network_from_ip(interface_ip, interface_netmask); + std::string ip_route; + std::string netmask_route; + split_ip_and_prefix(interface_ip, ip_route, netmask_route); + std::string network = get_network_from_ip(ip_route, netmask_route); + std::string route = network + "/" + + std::to_string(get_netmask_length(netmask_route)); logger()->debug("Removing routes involving the port {0} and the network {1}", port_name, network); @@ -427,15 +609,15 @@ void Router::remove_local_route(const std::string &interface_ip, for (auto it = routes_.begin(); it != routes_.end();) { if (it->second.getNexthop() == "local" && it->second.getInterface() == port_name && - it->second.getNetwork() == network) { + it->second.getNetwork() == route) { routes_.erase(it++); // remove the route from the control plane logger()->debug( - "Removed local route from the control plane [network: {0} - netmask: " - "{1} - nexthop: {2} - interface: {3}]", - network, interface_netmask, "0.0.0.0", port_name); + "Removed local route from the control plane [network: {0} " + "- nexthop: {1} - interface: {2}]", + route, "0.0.0.0", port_name); // Remove or update the route in the data path - find_new_active_nexthop(network, interface_netmask, "0.0.0.0"); + find_new_active_nexthop(route, "0.0.0.0"); break; } @@ -457,7 +639,7 @@ void Router::remove_local_route(const std::string &interface_ip, for (auto it = routes_.begin(); it != routes_.end();) { if (it->second.getNexthop() != "local" /*"local" are those networks directly connected*/ && - address_in_subnet(it->second.getNexthop(), interface_netmask, + address_in_subnet(it->second.getNexthop(), netmask_route, network)) { // it->second.getInterface() == port_name) { @@ -465,21 +647,20 @@ void Router::remove_local_route(const std::string &interface_ip, // remove, then the route must be removed as well std::string cur_network(it->second.getNetwork()); - std::string cur_netmask(it->second.getNetmask()); std::string cur_nexthop(it->second.getNexthop()); std::string cur_interface(it->second.getInterface()); routes_.erase(it++); logger()->debug( - "Removed local route from the control plane [network: {0} - netmask: " - "{1} - nexthop: {2} - interface: {3}]", - cur_network, cur_netmask, cur_nexthop, cur_interface); + "Removed local route from the control plane [network: {0} " + "- nexthop: {1} - interface: {2}]", + cur_network, cur_nexthop, cur_interface); // check if the entry is also in the fast path and either remove or update // it, according to the // fact that there is another nexthop for that network or not - find_new_active_nexthop(cur_network, cur_netmask, cur_nexthop); + find_new_active_nexthop(cur_network, cur_nexthop); } else ++it; } @@ -489,28 +670,30 @@ void Router::remove_local_route(const std::string &interface_ip, struct rt_k key { .netmask_len = 32, /* /32 -> 255.255.255.255 */ - .network = ip_string_to_be_uint(interface_ip), + .network = ip_string_to_be_uint(ip_route), }; routing_table.remove(key); } /* -* Looks for a nex nexthop for a destination network. +* Looks for a new nexthop for a destination network. * If it is found, the route in the fastpath is updated, otherwise it is removed */ void Router::find_new_active_nexthop(const std::string &network, - const std::string &netmask, const std::string &nexthop) { + std::string ip_route; + std::string netmask_route; + split_ip_and_prefix(network, ip_route, netmask_route); auto routing_table = get_hash_table("routing_table"); rt_k key{ - .netmask_len = get_netmask_length(netmask), - .network = ip_string_to_be_uint(network), + .netmask_len = get_netmask_length(netmask_route), + .network = ip_string_to_be_uint(ip_route), }; rt_v value = routing_table.get(key); - if (value.nexthop == ip_string_to_be_uint(nexthop)) { + if (value.nexthop == ip_string_to_be_uint(ip_route)) { // the nexthop in the fast path corresponds to that just removed in the // control path // then, the entry in the fast path is removed if no other nexthop is @@ -522,14 +705,12 @@ void Router::find_new_active_nexthop(const std::string &network, int32_t min = INT32_MAX; std::string new_nexthop; for (auto elem : routes_) { - if (elem.second.getNetwork() == network && - elem.second.getNetmask() == netmask) { + if (elem.second.getNetwork() == network) { logger()->debug( - "Alternative route found for network [network: {0} - netmask: {1} " - "- nexthop: {2} - interface: {3} - cost: {4}]", - elem.second.getNetwork(), elem.second.getNetmask(), - elem.second.getNexthop(), elem.second.getInterface(), - elem.second.getPathcost()); + "Alternative route found for network [network: {0} " + "- nexthop: {1} - interface: {2} - cost: {3}]", + elem.second.getNetwork(), elem.second.getNexthop(), + elem.second.getInterface(), elem.second.getPathcost()); // these entry is for the network we are considering @@ -695,7 +876,6 @@ void Router::generate_arp_request(Port &port, PacketInMetadata &md, } mu.unlock(); /* prepare the arp request - source mac is port src_mac source ip is src_ip target ip is target_ip @@ -762,253 +942,6 @@ void Router::generate_arp_reply(Port &port, PacketInMetadata &md, mu.unlock(); } -std::shared_ptr Router::getPorts(const std::string &name) { - return get_port(name); -} - -std::vector> Router::getPortsList() { - return get_ports(); -} - -void Router::addPorts(const std::string &name, const PortsJsonObject &conf) { - add_port(name, conf); - if (get_shadow()) - getPorts(name)->setMac(getPorts(name)->getMac()); -} - -void Router::addPortsList(const std::vector &conf) { - for (auto &i : conf) { - std::string name_ = i.getName(); - addPorts(name_, i); - } -} - -void Router::replacePorts(const std::string &name, - const PortsJsonObject &conf) { - delPorts(name); - std::string name_ = conf.getName(); - addPorts(name_, conf); -} - -void Router::delPorts(const std::string &name) { - logger()->info("Remove port {0}", name); - - auto port = get_port(name); - - // remove the secondary addresses of the port (and the related routes in the - // routing table) - port->delSecondaryipList(); - - remove_local_route(port->getIp(), port->getNetmask(), name); - - auto router_port = get_hash_table("router_port"); - - // remove the port from the datapath - uint16_t index = port->index(); - router_port.remove(index); - logger()->debug("Removed from 'router_port' - key: {0}", - from_int_to_hex(index)); - - remove_port(name); - - logger()->info("Port {0} was removed", name); -} - -void Router::delPortsList() { - auto ports = get_ports(); - for (auto it : ports) { - delPorts(it->name()); - } -} - -std::shared_ptr Router::getRoute(const std::string &network, - const std::string &netmask, - const std::string &nexthop) { - std::tuple key(network, netmask, nexthop); - - return std::shared_ptr(&routes_.at(key), [](Route *) {}); -} - -std::vector> Router::getRouteList() { - std::vector> routes_vect; - for (auto &it : routes_) { - routes_vect.push_back(getRoute(it.second.getNetwork(), - it.second.getNetmask(), - it.second.getNexthop())); - logger()->debug("\t'route [network: {0} - netmask: {1} - nexthop: {2}]", - it.second.getNetwork(), it.second.getNetmask(), - it.second.getNexthop()); - } - - return routes_vect; -} - -void Router::addRoute(const std::string &network, const std::string &netmask, - const std::string &nexthop, const RouteJsonObject &conf) { - logger()->debug( - "Trying to add route [network: {0} - netmask: {1} - nexthop: {2}]", - network, netmask, nexthop); - - std::tuple key(network, netmask, nexthop); - - if (routes_.count(key) != 0) - throw std::runtime_error("Route already exists"); - - routes_.emplace(std::piecewise_construct, std::forward_as_tuple(key), - std::forward_as_tuple(*this, conf)); -} - -void Router::addRouteList(const std::vector &conf) { - for (auto &i : conf) { - std::string network_ = i.getNetwork(); - std::string netmask_ = i.getNetmask(); - std::string nexthop_ = i.getNexthop(); - addRoute(network_, netmask_, nexthop_, i); - } -} - -void Router::replaceRoute(const std::string &network, - const std::string &netmask, - const std::string &nexthop, - const RouteJsonObject &conf) { - delRoute(network, netmask, nexthop); - std::string network_ = conf.getNetwork(); - std::string netmask_ = conf.getNetmask(); - std::string nexthop_ = conf.getNexthop(); - addRoute(network_, netmask_, nexthop_, conf); -} - -void Router::delRoute(const std::string &network, const std::string &netmask, - const std::string &nexthop) { - logger()->debug( - "Trying to remove route [network: {0} - netmask: {1} - nexthop: {2}]", - network, netmask, nexthop); - - // FIXME: is this good? cannot users delete "local" routes. - // It is possible in linux - if (nexthop == "local") // FIXME: use constants for these two values - throw std::runtime_error("Users can not delete a local route"); - - remove_route(network, netmask, nexthop); -} - -void Router::delRouteList() { - logger()->debug("Removing all the entries in the routing table"); - remove_all_routes(); -} - -std::shared_ptr Router::getArpEntry(const std::string &address) { - uint32_t ip_key = utils::ip_string_to_be_uint(address); - - try { - auto arp_table = get_hash_table("arp_table"); - - arp_entry entry = arp_table.get(ip_key); - std::string mac = utils::be_uint_to_mac_string(entry.mac); - auto port = get_port(entry.port); - - return std::make_shared( - ArpEntry(*this, mac, address, port->name())); - } catch (std::exception &e) { - logger()->error("Unable to find ARP table entry for address {0}. {1}", - address, e.what()); - throw std::runtime_error("ARP table entry not found"); - } -} - -std::vector> Router::getArpEntryList() { - std::vector> arp_table_entries; - - // The ARP table is read from the data path - try { - auto arp_table = get_hash_table("arp_table"); - auto arp_entries = arp_table.get_all(); - - for (auto &entry : arp_entries) { - auto key = entry.first; - auto value = entry.second; - - std::string ip = utils::be_uint_to_ip_string(key); - std::string mac = utils::be_uint_to_mac_string(value.mac); - - auto port = get_port(value.port); - - logger()->debug("Returning entry [ip: {0} - mac: {1} - interface: {2}]", - ip, mac, port->name()); - - arp_table_entries.push_back( - std::make_shared(ArpEntry(*this, mac, ip, port->name()))); - } - } catch (std::exception &e) { - logger()->error("Error while trying to get the ARP table"); - throw std::runtime_error("Unable to get the ARP table list"); - } - - return arp_table_entries; -} - -void Router::addArpEntry(const std::string &address, - const ArpEntryJsonObject &conf) { - logger()->debug("Creating ARP entry [ip: {0} - mac: {1} - interface: {2}", - address, conf.getMac(), conf.getInterface()); - - uint64_t mac = utils::mac_string_to_be_uint(conf.getMac()); - uint32_t index = get_port(conf.getInterface())->index(); - - // FIXME: Check if entry already exists? - auto arp_table = get_hash_table("arp_table"); - arp_table.set(utils::ip_string_to_be_uint(address), - arp_entry{.mac = mac, .port = index}); -} - -void Router::addArpEntryList(const std::vector &conf) { - for (auto &i : conf) { - std::string address_ = i.getAddress(); - addArpEntry(address_, i); - } -} - -void Router::replaceArpEntry(const std::string &address, - const ArpEntryJsonObject &conf) { - delArpEntry(address); - std::string address_ = conf.getAddress(); - addArpEntry(address_, conf); -} - -void Router::delArpEntry(const std::string &address) { - std::shared_ptr entry; - - try { - entry = getArpEntry(address); - } catch (std::exception &e) { - logger()->error("Unable to remove the ARP table entry for address {0}. {1}", - address, e.what()); - throw std::runtime_error("ARP table entry not found"); - } - - uint32_t key = utils::ip_string_to_be_uint(address); - - auto arp_table = get_hash_table("arp_table"); - - try { - arp_table.remove(key); - } catch (...) { - throw std::runtime_error("ARP table entry not found"); - } -} - -void Router::delArpEntryList() { - try { - auto arp_table = get_hash_table("arp_table"); - arp_table.remove_all(); - } catch (std::exception &e) { - logger()->error("Error while removing all entries from the ARP table. {0}", - e.what()); - throw std::runtime_error( - "Error while removing all entries from the ARP table"); - } -} - /* Netlink */ void Router::netlink_notification_route_added(int ifindex, const std::string &info_route) { std::lock_guard guard(router_mutex); @@ -1059,7 +992,7 @@ void Router::netlink_notification_route_deleted(int ifindex, const std::string & nexthop = "0.0.0.0"; uint32_t prefix_ = std::stoi(prefix); - std::string netmask = utils::get_netmask_from_CIDR(prefix_); + std::string netmask = utils::get_netmask_from_prefixlength(prefix_); try { std::string ip_port = get_port(name_port)->getIp(); @@ -1090,7 +1023,7 @@ void Router::netlink_notification_link_deleted(int ifindex, const std::string &i } } -void Router::netlink_notification_new_address(int ifindex, const std::string &info_address) { +void Router::netlink_notification_new_address(int ifindex, const std::string &new_ip) { std::lock_guard guard(router_mutex); // Check if the interface is of this cube @@ -1098,23 +1031,10 @@ void Router::netlink_notification_new_address(int ifindex, const std::string &in if (!name_port.empty()) { try { auto port = get_port(name_port); - - // info_address = ip_address/prefix - std::istringstream split(info_address); - std::vector info; - - char split_char = '/'; - for (std::string each; std::getline(split, each, split_char); info.push_back(each)); - std::string new_ip = info[0]; - std::string new_netmask = utils::get_netmask_from_CIDR(std::stoi(info[1])); - std::string old_ip = port->getIp(); - std::string old_netmask = port->getNetmask(); if (old_ip != new_ip) - port->setIp_Netlink(new_ip); - if (old_netmask != new_netmask) - port->setNetmask_Netlink(new_netmask); + port->doSetIp(new_ip); } catch (std::exception &e) { logger()->trace("new_address - False netlink notification: {0}", e.what()); @@ -1130,7 +1050,6 @@ void Router::add_linux_route(const std::string &network, const int port_index) { // Add the network reachable through the inteface uint32_t prefix_ = std::stoi(prefix); - std::string interface_netmask = utils::get_netmask_from_CIDR(prefix_); auto routing_table = get_hash_table("routing_table"); rt_k key{ @@ -1158,16 +1077,17 @@ void Router::add_linux_route(const std::string &network, }; routing_table.set(key, value); - logger()->info("Added Linux route [network: {0} - netmask: {1} - nexthop: {2} - interface: {3}]", - network, interface_netmask, nexthop, port_name); + logger()->info("Added Linux route [network: {0}/{1} - nexthop: {2} - interface: {3}]", + network, prefix, nexthop, port_name); // Add the route in the table of the control plane - std::tuple keyF(network, interface_netmask, nexthop); + std::string route = network + "/" + prefix; + std::tuple keyF(route, nexthop); uint32_t pathcost = 1; routes_.emplace(std::piecewise_construct, std::forward_as_tuple(keyF), - std::forward_as_tuple(*this, network, interface_netmask, - nexthop, port_name, pathcost)); + std::forward_as_tuple(*this, route, nexthop, port_name, + pathcost)); } // Remove Linux route from the routing table @@ -1176,7 +1096,6 @@ void Router::remove_linux_route(const std::string &network, const std::string &nexthop, const std::string &port_name) { uint32_t prefix_ = std::stoi(prefix); - std::string interface_netmask = utils::get_netmask_from_CIDR(prefix_); auto routing_table = get_hash_table("routing_table"); rt_k key{ @@ -1198,11 +1117,12 @@ void Router::remove_linux_route(const std::string &network, return; } - logger()->info("Removed Linux route [network: {0} - netmask: {1} - nexthop: {2} - interface: {3}]", - network, interface_netmask, nexthop, port_name); + logger()->info("Removed Linux route [network: {0}/{1} - nexthop: {2} - interface: {3}]", + network, prefix, nexthop, port_name); // remove the route in the table of the control plane - std::tuple key_cp(network, interface_netmask, nexthop); + std::string route = network + "/" + prefix; + std::tuple key_cp(route, nexthop); if (routes_.count(key_cp) != 0) routes_.erase(key_cp); } diff --git a/src/services/pcn-router/src/Router.h b/src/services/pcn-router/src/Router.h index 0ae4b789f..b389856b2 100644 --- a/src/services/pcn-router/src/Router.h +++ b/src/services/pcn-router/src/Router.h @@ -16,26 +16,22 @@ #pragma once -#include "../interface/RouterInterface.h" +#include "../base/RouterBase.h" -#include "polycube/services/cube.h" -#include "polycube/services/port.h" -#include "polycube/services/utils.h" - -#include - -#include "ArpEntry.h" +#include "ArpTable.h" #include "Ports.h" #include "Route.h" +#include "Utils.h" #include #include #include "../../../polycubed/src/utils/netlink.h" -using namespace io::swagger::server::model; -using namespace Tins; +using namespace polycube::service::model; +using namespace polycube::service::utils; using namespace polycube::service; +using namespace Tins; /* definitions copied from dataplane */ /* Routing Table Key */ @@ -54,93 +50,86 @@ struct rt_v { uint8_t type; } __attribute__((packed)); -class Router : public polycube::service::Cube, public RouterInterface { +class Router : public RouterBase { friend class Ports; friend class Route; public: Router(const std::string name, const RouterJsonObject &conf); virtual ~Router(); - std::string generate_code(); - std::vector generate_code_vector(); - void packet_in(Ports &port, polycube::service::PacketInMetadata &md, - const std::vector &packet) override; - void update(const RouterJsonObject &conf) override; - RouterJsonObject toJsonObject() override; + void packet_in(Ports &port, + polycube::service::PacketInMetadata &md, + const std::vector &packet) override; /// - /// Entry associated with the ARP table + /// Entry of the ports table /// - std::shared_ptr getArpEntry(const std::string &address) override; - std::vector> getArpEntryList() override; - void addArpEntry(const std::string &address, - const ArpEntryJsonObject &conf) override; - void addArpEntryList(const std::vector &conf) override; - void replaceArpEntry(const std::string &address, - const ArpEntryJsonObject &conf) override; - void delArpEntry(const std::string &address) override; - void delArpEntryList() override; + std::shared_ptr getPorts(const std::string &name) override; + std::vector> getPortsList() override; + void addPorts(const std::string &name, const PortsJsonObject &conf) override; + void addPortsList(const std::vector &conf) override; + void replacePorts(const std::string &name, + const PortsJsonObject &conf) override; + void delPorts(const std::string &name) override; + void delPortsList() override; /// /// Entry associated with the routing table /// std::shared_ptr getRoute(const std::string &network, - const std::string &netmask, const std::string &nexthop) override; std::vector> getRouteList() override; - void addRoute(const std::string &network, const std::string &netmask, - const std::string &nexthop, + void addRoute(const std::string &network, const std::string &nexthop, const RouteJsonObject &conf) override; void addRouteList(const std::vector &conf) override; - void replaceRoute(const std::string &network, const std::string &netmask, - const std::string &nexthop, + void replaceRoute(const std::string &network, const std::string &nexthop, const RouteJsonObject &conf) override; - void delRoute(const std::string &network, const std::string &netmask, + void delRoute(const std::string &network, const std::string &nexthop) override; void delRouteList() override; /// - /// Entry of the ports table + /// Entry associated with the ARP table /// - std::shared_ptr getPorts(const std::string &name) override; - std::vector> getPortsList() override; - void addPorts(const std::string &name, const PortsJsonObject &conf) override; - void addPortsList(const std::vector &conf) override; - void replacePorts(const std::string &name, - const PortsJsonObject &conf) override; - void delPorts(const std::string &name) override; - void delPortsList() override; + std::shared_ptr getArpTable(const std::string &address) override; + std::vector> getArpTableList() override; + void addArpTable(const std::string &address, + const ArpTableJsonObject &conf) override; + void addArpTableList(const std::vector &conf) override; + void replaceArpTable(const std::string &address, + const ArpTableJsonObject &conf) override; + void delArpTable(const std::string &address) override; + void delArpTableList() override; // The following methods have been added by hand // FIXME: the following methods should be protected. Ports should be friend void add_local_route(const std::string &interface_ip, - const std::string &interface_netmask, const std::string &port_name, const int port_index); void remove_local_route(const std::string &interface_ip, - const std::string &interface_netmask, const std::string &port_name); - void delete_route(const std::string &interface_ip, - const std::string &interface_netmask); + void delete_route(const std::string &interface_ip); std::string search_interface_from_nexthop(const std::string &nexthop); void add_active_nexthop_in_ebpf_map(const std::string &network, - const std::string &netmask, const std::string &nexthop, - int32_t actual_pathcost, + int32_t new_pathcost, const int &port_id); - void remove_route(const std::string &network, const std::string &netmask, - const std::string &nexthop); + void remove_route(const std::string &network, const std::string &nexthop); void remove_all_routes(); - /* Netlink */ + + /* SHADOW */ + + /* Mutex used to regulate access to ports and to the routing table + * by netlink notifications */ std::mutex router_mutex; polycube::polycubed::Netlink &netlink_instance_router_; int netlink_notification_index_route_added; @@ -154,7 +143,7 @@ class Router : public polycube::service::Cube, public RouterInterface { private: // The following variables have been added by hand - std::map, Route> routes_; + std::map, Route> routes_; // Mutex used to regulate access to the buffer of stored packets std::mutex mu; @@ -178,13 +167,11 @@ class Router : public polycube::service::Cube, public RouterInterface { // Methods to manage the routing table void find_new_active_nexthop(const std::string &network, - const std::string &netmask, const std::string &nexthop); - /* Netlink */ void add_linux_route(const std::string &network, const std::string &prefix, const std::string &nexthop, const std::string &port_name, const int port_index); - void remove_linux_route(const std::string &network, const std::string &netmask_length, + void remove_linux_route(const std::string &network, const std::string &prefix, const std::string &nexthop, const std::string &port_name); }; diff --git a/src/services/pcn-router/src/Router_dp.c b/src/services/pcn-router/src/Router_dp.c index 13445df47..fece35d6c 100644 --- a/src/services/pcn-router/src/Router_dp.c +++ b/src/services/pcn-router/src/Router_dp.c @@ -31,7 +31,7 @@ #define ROUTING_TABLE_DIM 256 #define ROUTER_PORT_N 32 #define ARP_TABLE_DIM 32 -#define SECONDARY_ADDRESS 5 +#define MAX_SECONDARY_ADDRESSES 5 // also defined in Ports.h #define TYPE_NOLOCALINTERFACE 0 // used to compare the 'type' field in the rt_v #define TYPE_LOCALINTERFACE 1 #define IP_CSUM_OFFSET (sizeof(struct eth_hdr) + offsetof(struct iphdr, check)) @@ -58,12 +58,12 @@ struct rt_v { __be32 nexthop; u8 type; }; -/* Router Port */ +/* Router Port, also defined in Ports.h */ struct r_port { __be32 ip; __be32 netmask; - __be32 secondary_ip[SECONDARY_ADDRESS]; - __be32 secondary_netmask[SECONDARY_ADDRESS]; + __be32 secondary_ip[MAX_SECONDARY_ADDRESSES]; + __be32 secondary_netmask[MAX_SECONDARY_ADDRESSES]; __be64 mac : 48; }; BPF_F_TABLE("lpm_trie", struct rt_k, struct rt_v, routing_table, @@ -200,7 +200,7 @@ static inline int send_packet_to_output_interface( return pcn_pkt_redirect(ctx, md, out_port); } static inline int search_secondary_address(__be32 *arr, __be32 ip) { - int i, size = SECONDARY_ADDRESS; + int i, size = MAX_SECONDARY_ADDRESSES; for (i = 0; i < size; i++) { if (arr[i] == ip) return i; /* found */ diff --git a/src/services/pcn-router/src/UtilityMethods.cpp b/src/services/pcn-router/src/Utils.cpp similarity index 83% rename from src/services/pcn-router/src/UtilityMethods.cpp rename to src/services/pcn-router/src/Utils.cpp index f812a6a10..1d313fc84 100644 --- a/src/services/pcn-router/src/UtilityMethods.cpp +++ b/src/services/pcn-router/src/Utils.cpp @@ -14,36 +14,17 @@ * limitations under the License. */ -#include "UtilityMethods.h" +#include "Utils.h" #include "Router.h" /*utility methods*/ -std::string from_int_to_hex(int t) { +std::string int_to_hex(int t) { std::stringstream stream; stream << "0x" << std::hex << t; return stream.str(); } -uint32_t get_netmask_length(const std::string &netmask_string) { - struct in_addr buf; - char address[100]; - int res = inet_pton( - AF_INET, netmask_string.c_str(), - &buf); /*convert ip address in binary form in network byte order */ - - if (res == 1) { - uint32_t counter = 0; - int n = buf.s_addr; - while (n) { - counter++; - n &= (n - 1); - } - return counter; - } else - throw std::runtime_error("IP Address is not in a valide format"); -} - unsigned int ip_to_int(const char *ip) { unsigned value = 0; // bytes processed. diff --git a/src/services/pcn-router/src/UtilityMethods.h b/src/services/pcn-router/src/Utils.h similarity index 78% rename from src/services/pcn-router/src/UtilityMethods.h rename to src/services/pcn-router/src/Utils.h index fb9eee235..650ac9500 100644 --- a/src/services/pcn-router/src/UtilityMethods.h +++ b/src/services/pcn-router/src/Utils.h @@ -18,16 +18,17 @@ #include -std::string from_int_to_hex(int t); - -uint32_t get_netmask_length(const std::string &netmask_string); -; +/* Take in ingress any int and return the hex in the form "0x.." */ +std::string int_to_hex(int t); unsigned int ip_to_int(const char *ip); +/* Take in ingress an ip, a netmask and a network and return true +* if the ip is part of the network */ bool address_in_subnet(const std::string &ip, const std::string &netmask, const std::string &network); +/* Take in ingress an ip and a netmask and return the network */ std::string get_network_from_ip(const std::string &ip, const std::string &netmask); diff --git a/src/services/pcn-router/src/api/RouterApi.cpp b/src/services/pcn-router/src/api/RouterApi.cpp index 1f50bc13b..54f164e47 100644 --- a/src/services/pcn-router/src/api/RouterApi.cpp +++ b/src/services/pcn-router/src/api/RouterApi.cpp @@ -1,12 +1,8 @@ /** -* router API * router API generated from router.yang * -* OpenAPI spec version: 1.0.0 -* -* NOTE: This class is auto generated by the swagger code generator program. -* https://github.com/polycube-network/swagger-codegen.git -* branch polycube +* NOTE: This file is auto generated by polycube-codegen +* https://github.com/polycube-network/polycube-codegen */ @@ -16,14 +12,14 @@ #include "RouterApi.h" #include "RouterApiImpl.h" -using namespace io::swagger::server::model; -using namespace io::swagger::server::api::RouterApiImpl; +using namespace polycube::service::model; +using namespace polycube::service::api::RouterApiImpl; #ifdef __cplusplus extern "C" { #endif -Response create_router_arp_entry_by_id_handler( +Response create_router_arp_table_by_id_handler( const char *name, const Key *keys, size_t num_keys , const char *value) { @@ -41,34 +37,34 @@ Response create_router_arp_entry_by_id_handler( try { auto request_body = nlohmann::json::parse(std::string { value }); // Getting the body param - ArpEntryJsonObject unique_value { request_body }; + ArpTableJsonObject unique_value { request_body }; unique_value.setAddress(unique_address); - create_router_arp_entry_by_id(unique_name, unique_address, unique_value); + create_router_arp_table_by_id(unique_name, unique_address, unique_value); return { kCreated, nullptr }; } catch(const std::exception &e) { return { kGenericError, ::strdup(e.what()) }; } } -Response create_router_arp_entry_list_by_id_handler( +Response create_router_arp_table_list_by_id_handler( const char *name, const Key *keys, size_t num_keys , const char *value) { // Getting the path params std::string unique_name { name }; // Getting the body param - std::vector unique_value; + std::vector unique_value; try { auto request_body = nlohmann::json::parse(std::string { value }); // Getting the body param - std::vector unique_value; + std::vector unique_value; for (auto &j : request_body) { - ArpEntryJsonObject a { j }; + ArpTableJsonObject a { j }; unique_value.push_back(a); } - create_router_arp_entry_list_by_id(unique_name, unique_value); + create_router_arp_table_list_by_id(unique_name, unique_value); return { kCreated, nullptr }; } catch(const std::exception &e) { return { kGenericError, ::strdup(e.what()) }; @@ -169,14 +165,6 @@ Response create_router_ports_secondaryip_by_id_handler( } } - std::string unique_netmask; - for (size_t i = 0; i < num_keys; ++i) { - if (!strcmp(keys[i].name, "netmask")) { - unique_netmask = std::string { keys[i].value.string }; - break; - } - } - try { auto request_body = nlohmann::json::parse(std::string { value }); @@ -184,8 +172,7 @@ Response create_router_ports_secondaryip_by_id_handler( PortsSecondaryipJsonObject unique_value { request_body }; unique_value.setIp(unique_ip); - unique_value.setNetmask(unique_netmask); - create_router_ports_secondaryip_by_id(unique_name, unique_portsName, unique_ip, unique_netmask, unique_value); + create_router_ports_secondaryip_by_id(unique_name, unique_portsName, unique_ip, unique_value); return { kCreated, nullptr }; } catch(const std::exception &e) { return { kGenericError, ::strdup(e.what()) }; @@ -238,14 +225,6 @@ Response create_router_route_by_id_handler( } } - std::string unique_netmask; - for (size_t i = 0; i < num_keys; ++i) { - if (!strcmp(keys[i].name, "netmask")) { - unique_netmask = std::string { keys[i].value.string }; - break; - } - } - std::string unique_nexthop; for (size_t i = 0; i < num_keys; ++i) { if (!strcmp(keys[i].name, "nexthop")) { @@ -261,9 +240,8 @@ Response create_router_route_by_id_handler( RouteJsonObject unique_value { request_body }; unique_value.setNetwork(unique_network); - unique_value.setNetmask(unique_netmask); unique_value.setNexthop(unique_nexthop); - create_router_route_by_id(unique_name, unique_network, unique_netmask, unique_nexthop, unique_value); + create_router_route_by_id(unique_name, unique_network, unique_nexthop, unique_value); return { kCreated, nullptr }; } catch(const std::exception &e) { return { kGenericError, ::strdup(e.what()) }; @@ -294,7 +272,7 @@ Response create_router_route_list_by_id_handler( } } -Response delete_router_arp_entry_by_id_handler( +Response delete_router_arp_table_by_id_handler( const char *name, const Key *keys, size_t num_keys ) { // Getting the path params @@ -309,21 +287,21 @@ Response delete_router_arp_entry_by_id_handler( try { - delete_router_arp_entry_by_id(unique_name, unique_address); + delete_router_arp_table_by_id(unique_name, unique_address); return { kOk, nullptr }; } catch(const std::exception &e) { return { kGenericError, ::strdup(e.what()) }; } } -Response delete_router_arp_entry_list_by_id_handler( +Response delete_router_arp_table_list_by_id_handler( const char *name, const Key *keys, size_t num_keys ) { // Getting the path params std::string unique_name { name }; try { - delete_router_arp_entry_list_by_id(unique_name); + delete_router_arp_table_list_by_id(unique_name); return { kOk, nullptr }; } catch(const std::exception &e) { return { kGenericError, ::strdup(e.what()) }; @@ -401,17 +379,9 @@ Response delete_router_ports_secondaryip_by_id_handler( } } - std::string unique_netmask; - for (size_t i = 0; i < num_keys; ++i) { - if (!strcmp(keys[i].name, "netmask")) { - unique_netmask = std::string { keys[i].value.string }; - break; - } - } - try { - delete_router_ports_secondaryip_by_id(unique_name, unique_portsName, unique_ip, unique_netmask); + delete_router_ports_secondaryip_by_id(unique_name, unique_portsName, unique_ip); return { kOk, nullptr }; } catch(const std::exception &e) { return { kGenericError, ::strdup(e.what()) }; @@ -453,14 +423,6 @@ Response delete_router_route_by_id_handler( } } - std::string unique_netmask; - for (size_t i = 0; i < num_keys; ++i) { - if (!strcmp(keys[i].name, "netmask")) { - unique_netmask = std::string { keys[i].value.string }; - break; - } - } - std::string unique_nexthop; for (size_t i = 0; i < num_keys; ++i) { if (!strcmp(keys[i].name, "nexthop")) { @@ -471,7 +433,7 @@ Response delete_router_route_by_id_handler( try { - delete_router_route_by_id(unique_name, unique_network, unique_netmask, unique_nexthop); + delete_router_route_by_id(unique_name, unique_network, unique_nexthop); return { kOk, nullptr }; } catch(const std::exception &e) { return { kGenericError, ::strdup(e.what()) }; @@ -492,7 +454,7 @@ Response delete_router_route_list_by_id_handler( } } -Response read_router_arp_entry_by_id_handler( +Response read_router_arp_table_by_id_handler( const char *name, const Key *keys, size_t num_keys ) { // Getting the path params @@ -508,7 +470,7 @@ Response read_router_arp_entry_by_id_handler( try { - auto x = read_router_arp_entry_by_id(unique_name, unique_address); + auto x = read_router_arp_table_by_id(unique_name, unique_address); nlohmann::json response_body; response_body = x.toJson(); return { kOk, ::strdup(response_body.dump().c_str()) }; @@ -517,7 +479,7 @@ Response read_router_arp_entry_by_id_handler( } } -Response read_router_arp_entry_interface_by_id_handler( +Response read_router_arp_table_interface_by_id_handler( const char *name, const Key *keys, size_t num_keys ) { // Getting the path params @@ -533,7 +495,7 @@ Response read_router_arp_entry_interface_by_id_handler( try { - auto x = read_router_arp_entry_interface_by_id(unique_name, unique_address); + auto x = read_router_arp_table_interface_by_id(unique_name, unique_address); nlohmann::json response_body; response_body = x; return { kOk, ::strdup(response_body.dump().c_str()) }; @@ -542,7 +504,7 @@ Response read_router_arp_entry_interface_by_id_handler( } } -Response read_router_arp_entry_list_by_id_handler( +Response read_router_arp_table_list_by_id_handler( const char *name, const Key *keys, size_t num_keys ) { // Getting the path params @@ -550,7 +512,7 @@ Response read_router_arp_entry_list_by_id_handler( try { - auto x = read_router_arp_entry_list_by_id(unique_name); + auto x = read_router_arp_table_list_by_id(unique_name); nlohmann::json response_body; for (auto &i : x) { response_body += i.toJson(); @@ -561,7 +523,7 @@ Response read_router_arp_entry_list_by_id_handler( } } -Response read_router_arp_entry_mac_by_id_handler( +Response read_router_arp_table_mac_by_id_handler( const char *name, const Key *keys, size_t num_keys ) { // Getting the path params @@ -577,7 +539,7 @@ Response read_router_arp_entry_mac_by_id_handler( try { - auto x = read_router_arp_entry_mac_by_id(unique_name, unique_address); + auto x = read_router_arp_table_mac_by_id(unique_name, unique_address); nlohmann::json response_body; response_body = x; return { kOk, ::strdup(response_body.dump().c_str()) }; @@ -715,31 +677,6 @@ Response read_router_ports_mac_by_id_handler( } } -Response read_router_ports_netmask_by_id_handler( - const char *name, const Key *keys, - size_t num_keys ) { - // Getting the path params - std::string unique_name { name }; - std::string unique_portsName; - for (size_t i = 0; i < num_keys; ++i) { - if (!strcmp(keys[i].name, "ports_name")) { - unique_portsName = std::string { keys[i].value.string }; - break; - } - } - - - try { - - auto x = read_router_ports_netmask_by_id(unique_name, unique_portsName); - nlohmann::json response_body; - response_body = x; - return { kOk, ::strdup(response_body.dump().c_str()) }; - } catch(const std::exception &e) { - return { kGenericError, ::strdup(e.what()) }; - } -} - Response read_router_ports_secondaryip_by_id_handler( const char *name, const Key *keys, size_t num_keys ) { @@ -761,18 +698,10 @@ Response read_router_ports_secondaryip_by_id_handler( } } - std::string unique_netmask; - for (size_t i = 0; i < num_keys; ++i) { - if (!strcmp(keys[i].name, "netmask")) { - unique_netmask = std::string { keys[i].value.string }; - break; - } - } - try { - auto x = read_router_ports_secondaryip_by_id(unique_name, unique_portsName, unique_ip, unique_netmask); + auto x = read_router_ports_secondaryip_by_id(unique_name, unique_portsName, unique_ip); nlohmann::json response_body; response_body = x.toJson(); return { kOk, ::strdup(response_body.dump().c_str()) }; @@ -821,14 +750,6 @@ Response read_router_route_by_id_handler( } } - std::string unique_netmask; - for (size_t i = 0; i < num_keys; ++i) { - if (!strcmp(keys[i].name, "netmask")) { - unique_netmask = std::string { keys[i].value.string }; - break; - } - } - std::string unique_nexthop; for (size_t i = 0; i < num_keys; ++i) { if (!strcmp(keys[i].name, "nexthop")) { @@ -840,7 +761,7 @@ Response read_router_route_by_id_handler( try { - auto x = read_router_route_by_id(unique_name, unique_network, unique_netmask, unique_nexthop); + auto x = read_router_route_by_id(unique_name, unique_network, unique_nexthop); nlohmann::json response_body; response_body = x.toJson(); return { kOk, ::strdup(response_body.dump().c_str()) }; @@ -862,14 +783,6 @@ Response read_router_route_interface_by_id_handler( } } - std::string unique_netmask; - for (size_t i = 0; i < num_keys; ++i) { - if (!strcmp(keys[i].name, "netmask")) { - unique_netmask = std::string { keys[i].value.string }; - break; - } - } - std::string unique_nexthop; for (size_t i = 0; i < num_keys; ++i) { if (!strcmp(keys[i].name, "nexthop")) { @@ -881,7 +794,7 @@ Response read_router_route_interface_by_id_handler( try { - auto x = read_router_route_interface_by_id(unique_name, unique_network, unique_netmask, unique_nexthop); + auto x = read_router_route_interface_by_id(unique_name, unique_network, unique_nexthop); nlohmann::json response_body; response_body = x; return { kOk, ::strdup(response_body.dump().c_str()) }; @@ -922,14 +835,6 @@ Response read_router_route_pathcost_by_id_handler( } } - std::string unique_netmask; - for (size_t i = 0; i < num_keys; ++i) { - if (!strcmp(keys[i].name, "netmask")) { - unique_netmask = std::string { keys[i].value.string }; - break; - } - } - std::string unique_nexthop; for (size_t i = 0; i < num_keys; ++i) { if (!strcmp(keys[i].name, "nexthop")) { @@ -941,7 +846,7 @@ Response read_router_route_pathcost_by_id_handler( try { - auto x = read_router_route_pathcost_by_id(unique_name, unique_network, unique_netmask, unique_nexthop); + auto x = read_router_route_pathcost_by_id(unique_name, unique_network, unique_nexthop); nlohmann::json response_body; response_body = x; return { kOk, ::strdup(response_body.dump().c_str()) }; @@ -950,7 +855,7 @@ Response read_router_route_pathcost_by_id_handler( } } -Response replace_router_arp_entry_by_id_handler( +Response replace_router_arp_table_by_id_handler( const char *name, const Key *keys, size_t num_keys , const char *value) { @@ -968,34 +873,34 @@ Response replace_router_arp_entry_by_id_handler( try { auto request_body = nlohmann::json::parse(std::string { value }); // Getting the body param - ArpEntryJsonObject unique_value { request_body }; + ArpTableJsonObject unique_value { request_body }; unique_value.setAddress(unique_address); - replace_router_arp_entry_by_id(unique_name, unique_address, unique_value); + replace_router_arp_table_by_id(unique_name, unique_address, unique_value); return { kOk, nullptr }; } catch(const std::exception &e) { return { kGenericError, ::strdup(e.what()) }; } } -Response replace_router_arp_entry_list_by_id_handler( +Response replace_router_arp_table_list_by_id_handler( const char *name, const Key *keys, size_t num_keys , const char *value) { // Getting the path params std::string unique_name { name }; // Getting the body param - std::vector unique_value; + std::vector unique_value; try { auto request_body = nlohmann::json::parse(std::string { value }); // Getting the body param - std::vector unique_value; + std::vector unique_value; for (auto &j : request_body) { - ArpEntryJsonObject a { j }; + ArpTableJsonObject a { j }; unique_value.push_back(a); } - replace_router_arp_entry_list_by_id(unique_name, unique_value); + replace_router_arp_table_list_by_id(unique_name, unique_value); return { kOk, nullptr }; } catch(const std::exception &e) { return { kGenericError, ::strdup(e.what()) }; @@ -1096,14 +1001,6 @@ Response replace_router_ports_secondaryip_by_id_handler( } } - std::string unique_netmask; - for (size_t i = 0; i < num_keys; ++i) { - if (!strcmp(keys[i].name, "netmask")) { - unique_netmask = std::string { keys[i].value.string }; - break; - } - } - try { auto request_body = nlohmann::json::parse(std::string { value }); @@ -1111,8 +1008,7 @@ Response replace_router_ports_secondaryip_by_id_handler( PortsSecondaryipJsonObject unique_value { request_body }; unique_value.setIp(unique_ip); - unique_value.setNetmask(unique_netmask); - replace_router_ports_secondaryip_by_id(unique_name, unique_portsName, unique_ip, unique_netmask, unique_value); + replace_router_ports_secondaryip_by_id(unique_name, unique_portsName, unique_ip, unique_value); return { kOk, nullptr }; } catch(const std::exception &e) { return { kGenericError, ::strdup(e.what()) }; @@ -1165,14 +1061,6 @@ Response replace_router_route_by_id_handler( } } - std::string unique_netmask; - for (size_t i = 0; i < num_keys; ++i) { - if (!strcmp(keys[i].name, "netmask")) { - unique_netmask = std::string { keys[i].value.string }; - break; - } - } - std::string unique_nexthop; for (size_t i = 0; i < num_keys; ++i) { if (!strcmp(keys[i].name, "nexthop")) { @@ -1188,9 +1076,8 @@ Response replace_router_route_by_id_handler( RouteJsonObject unique_value { request_body }; unique_value.setNetwork(unique_network); - unique_value.setNetmask(unique_netmask); unique_value.setNexthop(unique_nexthop); - replace_router_route_by_id(unique_name, unique_network, unique_netmask, unique_nexthop, unique_value); + replace_router_route_by_id(unique_name, unique_network, unique_nexthop, unique_value); return { kOk, nullptr }; } catch(const std::exception &e) { return { kGenericError, ::strdup(e.what()) }; @@ -1221,7 +1108,7 @@ Response replace_router_route_list_by_id_handler( } } -Response update_router_arp_entry_by_id_handler( +Response update_router_arp_table_by_id_handler( const char *name, const Key *keys, size_t num_keys , const char *value) { @@ -1239,17 +1126,17 @@ Response update_router_arp_entry_by_id_handler( try { auto request_body = nlohmann::json::parse(std::string { value }); // Getting the body param - ArpEntryJsonObject unique_value { request_body }; + ArpTableJsonObject unique_value { request_body }; unique_value.setAddress(unique_address); - update_router_arp_entry_by_id(unique_name, unique_address, unique_value); + update_router_arp_table_by_id(unique_name, unique_address, unique_value); return { kOk, nullptr }; } catch(const std::exception &e) { return { kGenericError, ::strdup(e.what()) }; } } -Response update_router_arp_entry_interface_by_id_handler( +Response update_router_arp_table_interface_by_id_handler( const char *name, const Key *keys, size_t num_keys , const char *value) { @@ -1268,38 +1155,38 @@ Response update_router_arp_entry_interface_by_id_handler( auto request_body = nlohmann::json::parse(std::string { value }); // The conversion is done automatically by the json library std::string unique_value = request_body; - update_router_arp_entry_interface_by_id(unique_name, unique_address, unique_value); + update_router_arp_table_interface_by_id(unique_name, unique_address, unique_value); return { kOk, nullptr }; } catch(const std::exception &e) { return { kGenericError, ::strdup(e.what()) }; } } -Response update_router_arp_entry_list_by_id_handler( +Response update_router_arp_table_list_by_id_handler( const char *name, const Key *keys, size_t num_keys , const char *value) { // Getting the path params std::string unique_name { name }; // Getting the body param - std::vector unique_value; + std::vector unique_value; try { auto request_body = nlohmann::json::parse(std::string { value }); // Getting the body param - std::vector unique_value; + std::vector unique_value; for (auto &j : request_body) { - ArpEntryJsonObject a { j }; + ArpTableJsonObject a { j }; unique_value.push_back(a); } - update_router_arp_entry_list_by_id(unique_name, unique_value); + update_router_arp_table_list_by_id(unique_name, unique_value); return { kOk, nullptr }; } catch(const std::exception &e) { return { kGenericError, ::strdup(e.what()) }; } } -Response update_router_arp_entry_mac_by_id_handler( +Response update_router_arp_table_mac_by_id_handler( const char *name, const Key *keys, size_t num_keys , const char *value) { @@ -1318,7 +1205,7 @@ Response update_router_arp_entry_mac_by_id_handler( auto request_body = nlohmann::json::parse(std::string { value }); // The conversion is done automatically by the json library std::string unique_value = request_body; - update_router_arp_entry_mac_by_id(unique_name, unique_address, unique_value); + update_router_arp_table_mac_by_id(unique_name, unique_address, unique_value); return { kOk, nullptr }; } catch(const std::exception &e) { return { kGenericError, ::strdup(e.what()) }; @@ -1472,32 +1359,6 @@ Response update_router_ports_mac_by_id_handler( } } -Response update_router_ports_netmask_by_id_handler( - const char *name, const Key *keys, - size_t num_keys , - const char *value) { - // Getting the path params - std::string unique_name { name }; - std::string unique_portsName; - for (size_t i = 0; i < num_keys; ++i) { - if (!strcmp(keys[i].name, "ports_name")) { - unique_portsName = std::string { keys[i].value.string }; - break; - } - } - - - try { - auto request_body = nlohmann::json::parse(std::string { value }); - // The conversion is done automatically by the json library - std::string unique_value = request_body; - update_router_ports_netmask_by_id(unique_name, unique_portsName, unique_value); - return { kOk, nullptr }; - } catch(const std::exception &e) { - return { kGenericError, ::strdup(e.what()) }; - } -} - Response update_router_ports_secondaryip_by_id_handler( const char *name, const Key *keys, size_t num_keys , @@ -1520,14 +1381,6 @@ Response update_router_ports_secondaryip_by_id_handler( } } - std::string unique_netmask; - for (size_t i = 0; i < num_keys; ++i) { - if (!strcmp(keys[i].name, "netmask")) { - unique_netmask = std::string { keys[i].value.string }; - break; - } - } - try { auto request_body = nlohmann::json::parse(std::string { value }); @@ -1535,8 +1388,7 @@ Response update_router_ports_secondaryip_by_id_handler( PortsSecondaryipJsonObject unique_value { request_body }; unique_value.setIp(unique_ip); - unique_value.setNetmask(unique_netmask); - update_router_ports_secondaryip_by_id(unique_name, unique_portsName, unique_ip, unique_netmask, unique_value); + update_router_ports_secondaryip_by_id(unique_name, unique_portsName, unique_ip, unique_value); return { kOk, nullptr }; } catch(const std::exception &e) { return { kGenericError, ::strdup(e.what()) }; @@ -1589,14 +1441,6 @@ Response update_router_route_by_id_handler( } } - std::string unique_netmask; - for (size_t i = 0; i < num_keys; ++i) { - if (!strcmp(keys[i].name, "netmask")) { - unique_netmask = std::string { keys[i].value.string }; - break; - } - } - std::string unique_nexthop; for (size_t i = 0; i < num_keys; ++i) { if (!strcmp(keys[i].name, "nexthop")) { @@ -1612,9 +1456,8 @@ Response update_router_route_by_id_handler( RouteJsonObject unique_value { request_body }; unique_value.setNetwork(unique_network); - unique_value.setNetmask(unique_netmask); unique_value.setNexthop(unique_nexthop); - update_router_route_by_id(unique_name, unique_network, unique_netmask, unique_nexthop, unique_value); + update_router_route_by_id(unique_name, unique_network, unique_nexthop, unique_value); return { kOk, nullptr }; } catch(const std::exception &e) { return { kGenericError, ::strdup(e.what()) }; @@ -1659,14 +1502,6 @@ Response update_router_route_pathcost_by_id_handler( } } - std::string unique_netmask; - for (size_t i = 0; i < num_keys; ++i) { - if (!strcmp(keys[i].name, "netmask")) { - unique_netmask = std::string { keys[i].value.string }; - break; - } - } - std::string unique_nexthop; for (size_t i = 0; i < num_keys; ++i) { if (!strcmp(keys[i].name, "nexthop")) { @@ -1680,7 +1515,7 @@ Response update_router_route_pathcost_by_id_handler( auto request_body = nlohmann::json::parse(std::string { value }); // The conversion is done automatically by the json library uint32_t unique_value = request_body; - update_router_route_pathcost_by_id(unique_name, unique_network, unique_netmask, unique_nexthop, unique_value); + update_router_route_pathcost_by_id(unique_name, unique_network, unique_nexthop, unique_value); return { kOk, nullptr }; } catch(const std::exception &e) { return { kGenericError, ::strdup(e.what()) }; @@ -1688,11 +1523,11 @@ Response update_router_route_pathcost_by_id_handler( } -Response router_arp_entry_list_by_id_help( +Response router_arp_table_list_by_id_help( const char *name, const Key *keys, size_t num_keys) { // Getting the path params std::string unique_name { name }; - nlohmann::json val = read_router_arp_entry_list_by_id_get_list(unique_name); + nlohmann::json val = read_router_arp_table_list_by_id_get_list(unique_name); return { kOk, ::strdup(val.dump().c_str()) }; } diff --git a/src/services/pcn-router/src/api/RouterApi.h b/src/services/pcn-router/src/api/RouterApi.h index 051f9d562..1d548e948 100644 --- a/src/services/pcn-router/src/api/RouterApi.h +++ b/src/services/pcn-router/src/api/RouterApi.h @@ -1,12 +1,8 @@ /** -* router API * router API generated from router.yang * -* OpenAPI spec version: 1.0.0 -* -* NOTE: This class is auto generated by the swagger code generator program. -* https://github.com/polycube-network/swagger-codegen.git -* branch polycube +* NOTE: This file is auto generated by polycube-codegen +* https://github.com/polycube-network/polycube-codegen */ @@ -25,7 +21,7 @@ #include "polycube/services/response.h" #include "polycube/services/shared_lib_elements.h" -#include "ArpEntryJsonObject.h" +#include "ArpTableJsonObject.h" #include "PortsJsonObject.h" #include "PortsSecondaryipJsonObject.h" #include "RouteJsonObject.h" @@ -37,8 +33,8 @@ extern "C" { #endif -Response create_router_arp_entry_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); -Response create_router_arp_entry_list_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); +Response create_router_arp_table_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); +Response create_router_arp_table_list_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); Response create_router_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); Response create_router_ports_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); Response create_router_ports_list_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); @@ -46,8 +42,8 @@ Response create_router_ports_secondaryip_by_id_handler(const char *name, const K Response create_router_ports_secondaryip_list_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); Response create_router_route_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); Response create_router_route_list_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); -Response delete_router_arp_entry_by_id_handler(const char *name, const Key *keys, size_t num_keys); -Response delete_router_arp_entry_list_by_id_handler(const char *name, const Key *keys, size_t num_keys); +Response delete_router_arp_table_by_id_handler(const char *name, const Key *keys, size_t num_keys); +Response delete_router_arp_table_list_by_id_handler(const char *name, const Key *keys, size_t num_keys); Response delete_router_by_id_handler(const char *name, const Key *keys, size_t num_keys); Response delete_router_ports_by_id_handler(const char *name, const Key *keys, size_t num_keys); Response delete_router_ports_list_by_id_handler(const char *name, const Key *keys, size_t num_keys); @@ -55,25 +51,24 @@ Response delete_router_ports_secondaryip_by_id_handler(const char *name, const K Response delete_router_ports_secondaryip_list_by_id_handler(const char *name, const Key *keys, size_t num_keys); Response delete_router_route_by_id_handler(const char *name, const Key *keys, size_t num_keys); Response delete_router_route_list_by_id_handler(const char *name, const Key *keys, size_t num_keys); -Response read_router_arp_entry_by_id_handler(const char *name, const Key *keys, size_t num_keys); -Response read_router_arp_entry_interface_by_id_handler(const char *name, const Key *keys, size_t num_keys); -Response read_router_arp_entry_list_by_id_handler(const char *name, const Key *keys, size_t num_keys); -Response read_router_arp_entry_mac_by_id_handler(const char *name, const Key *keys, size_t num_keys); +Response read_router_arp_table_by_id_handler(const char *name, const Key *keys, size_t num_keys); +Response read_router_arp_table_interface_by_id_handler(const char *name, const Key *keys, size_t num_keys); +Response read_router_arp_table_list_by_id_handler(const char *name, const Key *keys, size_t num_keys); +Response read_router_arp_table_mac_by_id_handler(const char *name, const Key *keys, size_t num_keys); Response read_router_by_id_handler(const char *name, const Key *keys, size_t num_keys); Response read_router_list_by_id_handler(const char *name, const Key *keys, size_t num_keys); Response read_router_ports_by_id_handler(const char *name, const Key *keys, size_t num_keys); Response read_router_ports_ip_by_id_handler(const char *name, const Key *keys, size_t num_keys); Response read_router_ports_list_by_id_handler(const char *name, const Key *keys, size_t num_keys); Response read_router_ports_mac_by_id_handler(const char *name, const Key *keys, size_t num_keys); -Response read_router_ports_netmask_by_id_handler(const char *name, const Key *keys, size_t num_keys); Response read_router_ports_secondaryip_by_id_handler(const char *name, const Key *keys, size_t num_keys); Response read_router_ports_secondaryip_list_by_id_handler(const char *name, const Key *keys, size_t num_keys); Response read_router_route_by_id_handler(const char *name, const Key *keys, size_t num_keys); Response read_router_route_interface_by_id_handler(const char *name, const Key *keys, size_t num_keys); Response read_router_route_list_by_id_handler(const char *name, const Key *keys, size_t num_keys); Response read_router_route_pathcost_by_id_handler(const char *name, const Key *keys, size_t num_keys); -Response replace_router_arp_entry_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); -Response replace_router_arp_entry_list_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); +Response replace_router_arp_table_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); +Response replace_router_arp_table_list_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); Response replace_router_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); Response replace_router_ports_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); Response replace_router_ports_list_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); @@ -81,24 +76,23 @@ Response replace_router_ports_secondaryip_by_id_handler(const char *name, const Response replace_router_ports_secondaryip_list_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); Response replace_router_route_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); Response replace_router_route_list_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); -Response update_router_arp_entry_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); -Response update_router_arp_entry_interface_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); -Response update_router_arp_entry_list_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); -Response update_router_arp_entry_mac_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); +Response update_router_arp_table_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); +Response update_router_arp_table_interface_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); +Response update_router_arp_table_list_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); +Response update_router_arp_table_mac_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); Response update_router_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); Response update_router_list_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); Response update_router_ports_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); Response update_router_ports_ip_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); Response update_router_ports_list_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); Response update_router_ports_mac_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); -Response update_router_ports_netmask_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); Response update_router_ports_secondaryip_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); Response update_router_ports_secondaryip_list_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); Response update_router_route_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); Response update_router_route_list_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); Response update_router_route_pathcost_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value); -Response router_arp_entry_list_by_id_help(const char *name, const Key *keys, size_t num_keys); +Response router_arp_table_list_by_id_help(const char *name, const Key *keys, size_t num_keys); Response router_list_by_id_help(const char *name, const Key *keys, size_t num_keys); Response router_ports_list_by_id_help(const char *name, const Key *keys, size_t num_keys); Response router_ports_secondaryip_list_by_id_help(const char *name, const Key *keys, size_t num_keys); diff --git a/src/services/pcn-router/src/api/RouterApiImpl.cpp b/src/services/pcn-router/src/api/RouterApiImpl.cpp index 372e87ecc..a04f48321 100644 --- a/src/services/pcn-router/src/api/RouterApiImpl.cpp +++ b/src/services/pcn-router/src/api/RouterApiImpl.cpp @@ -1,12 +1,8 @@ /** -* router API * router API generated from router.yang * -* OpenAPI spec version: 1.0.0 -* -* NOTE: This class is auto generated by the swagger code generator program. -* https://github.com/polycube-network/swagger-codegen.git -* branch polycube +* NOTE: This file is auto generated by polycube-codegen +* https://github.com/polycube-network/polycube-codegen */ @@ -15,12 +11,11 @@ #include "RouterApiImpl.h" -namespace io { -namespace swagger { -namespace server { +namespace polycube { +namespace service { namespace api { -using namespace io::swagger::server::model; +using namespace polycube::service::model; namespace RouterApiImpl { namespace { @@ -91,39 +86,39 @@ std::vector> read_router_list_by_id } /** -* @brief Create arp-entry by ID +* @brief Create arp-table by ID * -* Create operation of resource: arp-entry* +* Create operation of resource: arp-table* * * @param[in] name ID of name * @param[in] address ID of address -* @param[in] value arp-entrybody object +* @param[in] value arp-tablebody object * * Responses: * */ void -create_router_arp_entry_by_id(const std::string &name, const std::string &address, const ArpEntryJsonObject &value) { +create_router_arp_table_by_id(const std::string &name, const std::string &address, const ArpTableJsonObject &value) { auto router = get_cube(name); - router->addArpEntry(address, value); + return router->addArpTable(address, value); } /** -* @brief Create arp-entry by ID +* @brief Create arp-table by ID * -* Create operation of resource: arp-entry* +* Create operation of resource: arp-table* * * @param[in] name ID of name -* @param[in] value arp-entrybody object +* @param[in] value arp-tablebody object * * Responses: * */ void -create_router_arp_entry_list_by_id(const std::string &name, const std::vector &value) { +create_router_arp_table_list_by_id(const std::string &name, const std::vector &value) { auto router = get_cube(name); - router->addArpEntryList(value); + router->addArpTableList(value); } /** @@ -142,7 +137,7 @@ void create_router_ports_by_id(const std::string &name, const std::string &portsName, const PortsJsonObject &value) { auto router = get_cube(name); - router->addPorts(portsName, value); + return router->addPorts(portsName, value); } /** @@ -170,18 +165,17 @@ create_router_ports_list_by_id(const std::string &name, const std::vectorgetPorts(portsName); - ports->addSecondaryip(ip, netmask, value); + return ports->addSecondaryip(ip, value); } /** @@ -210,7 +204,6 @@ create_router_ports_secondaryip_list_by_id(const std::string &name, const std::s * * @param[in] name ID of name * @param[in] network ID of network -* @param[in] netmask ID of netmask * @param[in] nexthop ID of nexthop * @param[in] value routebody object * @@ -218,10 +211,10 @@ create_router_ports_secondaryip_list_by_id(const std::string &name, const std::s * */ void -create_router_route_by_id(const std::string &name, const std::string &network, const std::string &netmask, const std::string &nexthop, const RouteJsonObject &value) { +create_router_route_by_id(const std::string &name, const std::string &network, const std::string &nexthop, const RouteJsonObject &value) { auto router = get_cube(name); - router->addRoute(network, netmask, nexthop, value); + return router->addRoute(network, nexthop, value); } /** @@ -242,9 +235,9 @@ create_router_route_list_by_id(const std::string &name, const std::vectordelArpEntry(address); + return router->delArpTable(address); } /** -* @brief Delete arp-entry by ID +* @brief Delete arp-table by ID * -* Delete operation of resource: arp-entry* +* Delete operation of resource: arp-table* * * @param[in] name ID of name * @@ -270,9 +263,9 @@ delete_router_arp_entry_by_id(const std::string &name, const std::string &addres * */ void -delete_router_arp_entry_list_by_id(const std::string &name) { +delete_router_arp_table_list_by_id(const std::string &name) { auto router = get_cube(name); - router->delArpEntryList(); + router->delArpTableList(); } /** @@ -290,7 +283,7 @@ void delete_router_ports_by_id(const std::string &name, const std::string &portsName) { auto router = get_cube(name); - router->delPorts(portsName); + return router->delPorts(portsName); } /** @@ -317,17 +310,16 @@ delete_router_ports_list_by_id(const std::string &name) { * @param[in] name ID of name * @param[in] portsName ID of ports_name * @param[in] ip ID of ip -* @param[in] netmask ID of netmask * * Responses: * */ void -delete_router_ports_secondaryip_by_id(const std::string &name, const std::string &portsName, const std::string &ip, const std::string &netmask) { +delete_router_ports_secondaryip_by_id(const std::string &name, const std::string &portsName, const std::string &ip) { auto router = get_cube(name); auto ports = router->getPorts(portsName); - ports->delSecondaryip(ip, netmask); + return ports->delSecondaryip(ip); } /** @@ -355,17 +347,16 @@ delete_router_ports_secondaryip_list_by_id(const std::string &name, const std::s * * @param[in] name ID of name * @param[in] network ID of network -* @param[in] netmask ID of netmask * @param[in] nexthop ID of nexthop * * Responses: * */ void -delete_router_route_by_id(const std::string &name, const std::string &network, const std::string &netmask, const std::string &nexthop) { +delete_router_route_by_id(const std::string &name, const std::string &network, const std::string &nexthop) { auto router = get_cube(name); - router->delRoute(network, netmask, nexthop); + return router->delRoute(network, nexthop); } /** @@ -385,20 +376,20 @@ delete_router_route_list_by_id(const std::string &name) { } /** -* @brief Read arp-entry by ID +* @brief Read arp-table by ID * -* Read operation of resource: arp-entry* +* Read operation of resource: arp-table* * * @param[in] name ID of name * @param[in] address ID of address * * Responses: -* ArpEntryJsonObject +* ArpTableJsonObject */ -ArpEntryJsonObject -read_router_arp_entry_by_id(const std::string &name, const std::string &address) { +ArpTableJsonObject +read_router_arp_table_by_id(const std::string &name, const std::string &address) { auto router = get_cube(name); - return router->getArpEntry(address)->toJsonObject(); + return router->getArpTable(address)->toJsonObject(); } @@ -414,29 +405,29 @@ read_router_arp_entry_by_id(const std::string &name, const std::string &address) * std::string */ std::string -read_router_arp_entry_interface_by_id(const std::string &name, const std::string &address) { +read_router_arp_table_interface_by_id(const std::string &name, const std::string &address) { auto router = get_cube(name); - auto arpEntry = router->getArpEntry(address); - return arpEntry->getInterface(); + auto arpTable = router->getArpTable(address); + return arpTable->getInterface(); } /** -* @brief Read arp-entry by ID +* @brief Read arp-table by ID * -* Read operation of resource: arp-entry* +* Read operation of resource: arp-table* * * @param[in] name ID of name * * Responses: -* std::vector +* std::vector */ -std::vector -read_router_arp_entry_list_by_id(const std::string &name) { +std::vector +read_router_arp_table_list_by_id(const std::string &name) { auto router = get_cube(name); - auto &&arpEntry = router->getArpEntryList(); - std::vector m; - for(auto &i : arpEntry) + auto &&arpTable = router->getArpTableList(); + std::vector m; + for(auto &i : arpTable) m.push_back(i->toJsonObject()); return m; } @@ -453,10 +444,10 @@ read_router_arp_entry_list_by_id(const std::string &name) { * std::string */ std::string -read_router_arp_entry_mac_by_id(const std::string &name, const std::string &address) { +read_router_arp_table_mac_by_id(const std::string &name, const std::string &address) { auto router = get_cube(name); - auto arpEntry = router->getArpEntry(address); - return arpEntry->getMac(); + auto arpTable = router->getArpTable(address); + return arpTable->getMac(); } @@ -552,25 +543,6 @@ read_router_ports_mac_by_id(const std::string &name, const std::string &portsNam } -/** -* @brief Read netmask by ID -* -* Read operation of resource: netmask* -* -* @param[in] name ID of name -* @param[in] portsName ID of ports_name -* -* Responses: -* std::string -*/ -std::string -read_router_ports_netmask_by_id(const std::string &name, const std::string &portsName) { - auto router = get_cube(name); - auto ports = router->getPorts(portsName); - return ports->getNetmask(); - -} - /** * @brief Read secondaryip by ID * @@ -579,16 +551,15 @@ read_router_ports_netmask_by_id(const std::string &name, const std::string &port * @param[in] name ID of name * @param[in] portsName ID of ports_name * @param[in] ip ID of ip -* @param[in] netmask ID of netmask * * Responses: * PortsSecondaryipJsonObject */ PortsSecondaryipJsonObject -read_router_ports_secondaryip_by_id(const std::string &name, const std::string &portsName, const std::string &ip, const std::string &netmask) { +read_router_ports_secondaryip_by_id(const std::string &name, const std::string &portsName, const std::string &ip) { auto router = get_cube(name); auto ports = router->getPorts(portsName); - return ports->getSecondaryip(ip, netmask)->toJsonObject(); + return ports->getSecondaryip(ip)->toJsonObject(); } @@ -621,16 +592,15 @@ read_router_ports_secondaryip_list_by_id(const std::string &name, const std::str * * @param[in] name ID of name * @param[in] network ID of network -* @param[in] netmask ID of netmask * @param[in] nexthop ID of nexthop * * Responses: * RouteJsonObject */ RouteJsonObject -read_router_route_by_id(const std::string &name, const std::string &network, const std::string &netmask, const std::string &nexthop) { +read_router_route_by_id(const std::string &name, const std::string &network, const std::string &nexthop) { auto router = get_cube(name); - return router->getRoute(network, netmask, nexthop)->toJsonObject(); + return router->getRoute(network, nexthop)->toJsonObject(); } @@ -641,16 +611,15 @@ read_router_route_by_id(const std::string &name, const std::string &network, con * * @param[in] name ID of name * @param[in] network ID of network -* @param[in] netmask ID of netmask * @param[in] nexthop ID of nexthop * * Responses: * std::string */ std::string -read_router_route_interface_by_id(const std::string &name, const std::string &network, const std::string &netmask, const std::string &nexthop) { +read_router_route_interface_by_id(const std::string &name, const std::string &network, const std::string &nexthop) { auto router = get_cube(name); - auto route = router->getRoute(network, netmask, nexthop); + auto route = router->getRoute(network, nexthop); return route->getInterface(); } @@ -682,52 +651,51 @@ read_router_route_list_by_id(const std::string &name) { * * @param[in] name ID of name * @param[in] network ID of network -* @param[in] netmask ID of netmask * @param[in] nexthop ID of nexthop * * Responses: * uint32_t */ uint32_t -read_router_route_pathcost_by_id(const std::string &name, const std::string &network, const std::string &netmask, const std::string &nexthop) { +read_router_route_pathcost_by_id(const std::string &name, const std::string &network, const std::string &nexthop) { auto router = get_cube(name); - auto route = router->getRoute(network, netmask, nexthop); + auto route = router->getRoute(network, nexthop); return route->getPathcost(); } /** -* @brief Replace arp-entry by ID +* @brief Replace arp-table by ID * -* Replace operation of resource: arp-entry* +* Replace operation of resource: arp-table* * * @param[in] name ID of name * @param[in] address ID of address -* @param[in] value arp-entrybody object +* @param[in] value arp-tablebody object * * Responses: * */ void -replace_router_arp_entry_by_id(const std::string &name, const std::string &address, const ArpEntryJsonObject &value) { +replace_router_arp_table_by_id(const std::string &name, const std::string &address, const ArpTableJsonObject &value) { auto router = get_cube(name); - router->replaceArpEntry(address, value); + return router->replaceArpTable(address, value); } /** -* @brief Replace arp-entry by ID +* @brief Replace arp-table by ID * -* Replace operation of resource: arp-entry* +* Replace operation of resource: arp-table* * * @param[in] name ID of name -* @param[in] value arp-entrybody object +* @param[in] value arp-tablebody object * * Responses: * */ void -replace_router_arp_entry_list_by_id(const std::string &name, const std::vector &value) { +replace_router_arp_table_list_by_id(const std::string &name, const std::vector &value) { throw std::runtime_error("Method not supported"); } @@ -747,7 +715,7 @@ void replace_router_ports_by_id(const std::string &name, const std::string &portsName, const PortsJsonObject &value) { auto router = get_cube(name); - router->replacePorts(portsName, value); + return router->replacePorts(portsName, value); } /** @@ -774,18 +742,17 @@ replace_router_ports_list_by_id(const std::string &name, const std::vectorgetPorts(portsName); - ports->replaceSecondaryip(ip, netmask, value); + return ports->replaceSecondaryip(ip, value); } /** @@ -812,7 +779,6 @@ replace_router_ports_secondaryip_list_by_id(const std::string &name, const std:: * * @param[in] name ID of name * @param[in] network ID of network -* @param[in] netmask ID of netmask * @param[in] nexthop ID of nexthop * @param[in] value routebody object * @@ -820,10 +786,10 @@ replace_router_ports_secondaryip_list_by_id(const std::string &name, const std:: * */ void -replace_router_route_by_id(const std::string &name, const std::string &network, const std::string &netmask, const std::string &nexthop, const RouteJsonObject &value) { +replace_router_route_by_id(const std::string &name, const std::string &network, const std::string &nexthop, const RouteJsonObject &value) { auto router = get_cube(name); - router->replaceRoute(network, netmask, nexthop, value); + return router->replaceRoute(network, nexthop, value); } /** @@ -843,23 +809,23 @@ replace_router_route_list_by_id(const std::string &name, const std::vectorgetArpEntry(address); + auto arpTable = router->getArpTable(address); - arpEntry->update(value); + return arpTable->update(value); } /** @@ -875,26 +841,26 @@ update_router_arp_entry_by_id(const std::string &name, const std::string &addres * */ void -update_router_arp_entry_interface_by_id(const std::string &name, const std::string &address, const std::string &value) { +update_router_arp_table_interface_by_id(const std::string &name, const std::string &address, const std::string &value) { auto router = get_cube(name); - auto arpEntry = router->getArpEntry(address); + auto arpTable = router->getArpTable(address); - arpEntry->setInterface(value); + return arpTable->setInterface(value); } /** -* @brief Update arp-entry by ID +* @brief Update arp-table by ID * -* Update operation of resource: arp-entry* +* Update operation of resource: arp-table* * * @param[in] name ID of name -* @param[in] value arp-entrybody object +* @param[in] value arp-tablebody object * * Responses: * */ void -update_router_arp_entry_list_by_id(const std::string &name, const std::vector &value) { +update_router_arp_table_list_by_id(const std::string &name, const std::vector &value) { throw std::runtime_error("Method not supported"); } @@ -911,11 +877,11 @@ update_router_arp_entry_list_by_id(const std::string &name, const std::vectorgetArpEntry(address); + auto arpTable = router->getArpTable(address); - arpEntry->setMac(value); + return arpTable->setMac(value); } /** @@ -933,7 +899,7 @@ void update_router_by_id(const std::string &name, const RouterJsonObject &value) { auto router = get_cube(name); - router->update(value); + return router->update(value); } /** @@ -968,7 +934,7 @@ update_router_ports_by_id(const std::string &name, const std::string &portsName, auto router = get_cube(name); auto ports = router->getPorts(portsName); - ports->update(value); + return ports->update(value); } /** @@ -978,7 +944,7 @@ update_router_ports_by_id(const std::string &name, const std::string &portsName, * * @param[in] name ID of name * @param[in] portsName ID of ports_name -* @param[in] value IP address of the port +* @param[in] value IP address and prefix of the port * * Responses: * @@ -988,7 +954,7 @@ update_router_ports_ip_by_id(const std::string &name, const std::string &portsNa auto router = get_cube(name); auto ports = router->getPorts(portsName); - ports->setIp(value); + return ports->setIp(value); } /** @@ -1024,27 +990,7 @@ update_router_ports_mac_by_id(const std::string &name, const std::string &portsN auto router = get_cube(name); auto ports = router->getPorts(portsName); - ports->setMac(value); -} - -/** -* @brief Update netmask by ID -* -* Update operation of resource: netmask* -* -* @param[in] name ID of name -* @param[in] portsName ID of ports_name -* @param[in] value Netmask of the port -* -* Responses: -* -*/ -void -update_router_ports_netmask_by_id(const std::string &name, const std::string &portsName, const std::string &value) { - auto router = get_cube(name); - auto ports = router->getPorts(portsName); - - ports->setNetmask(value); + return ports->setMac(value); } /** @@ -1055,19 +1001,18 @@ update_router_ports_netmask_by_id(const std::string &name, const std::string &po * @param[in] name ID of name * @param[in] portsName ID of ports_name * @param[in] ip ID of ip -* @param[in] netmask ID of netmask * @param[in] value secondaryipbody object * * Responses: * */ void -update_router_ports_secondaryip_by_id(const std::string &name, const std::string &portsName, const std::string &ip, const std::string &netmask, const PortsSecondaryipJsonObject &value) { +update_router_ports_secondaryip_by_id(const std::string &name, const std::string &portsName, const std::string &ip, const PortsSecondaryipJsonObject &value) { auto router = get_cube(name); auto ports = router->getPorts(portsName); - auto secondaryip = ports->getSecondaryip(ip, netmask); + auto secondaryip = ports->getSecondaryip(ip); - secondaryip->update(value); + return secondaryip->update(value); } /** @@ -1094,7 +1039,6 @@ update_router_ports_secondaryip_list_by_id(const std::string &name, const std::s * * @param[in] name ID of name * @param[in] network ID of network -* @param[in] netmask ID of netmask * @param[in] nexthop ID of nexthop * @param[in] value routebody object * @@ -1102,11 +1046,11 @@ update_router_ports_secondaryip_list_by_id(const std::string &name, const std::s * */ void -update_router_route_by_id(const std::string &name, const std::string &network, const std::string &netmask, const std::string &nexthop, const RouteJsonObject &value) { +update_router_route_by_id(const std::string &name, const std::string &network, const std::string &nexthop, const RouteJsonObject &value) { auto router = get_cube(name); - auto route = router->getRoute(network, netmask, nexthop); + auto route = router->getRoute(network, nexthop); - route->update(value); + return route->update(value); } /** @@ -1132,7 +1076,6 @@ update_router_route_list_by_id(const std::string &name, const std::vectorgetRoute(network, netmask, nexthop); + auto route = router->getRoute(network, nexthop); - route->setPathcost(value); + return route->setPathcost(value); } @@ -1153,12 +1096,12 @@ update_router_route_pathcost_by_id(const std::string &name, const std::string &n * help related */ -std::vector> read_router_arp_entry_list_by_id_get_list(const std::string &name) { +std::vector> read_router_arp_table_list_by_id_get_list(const std::string &name) { std::vector> r; auto &&router = get_cube(name); - auto &&arpEntry = router->getArpEntryList(); - for(auto &i : arpEntry) { + auto &&arpTable = router->getArpTableList(); + for(auto &i : arpTable) { nlohmann::fifo_map keys; keys["address"] = i->getAddress(); @@ -1193,7 +1136,6 @@ std::vector> read_router_ports_seco nlohmann::fifo_map keys; keys["ip"] = i->getIp(); - keys["netmask"] = i->getNetmask(); r.push_back(keys); } @@ -1209,7 +1151,6 @@ std::vector> read_router_route_list nlohmann::fifo_map keys; keys["network"] = i->getNetwork(); - keys["netmask"] = i->getNetmask(); keys["nexthop"] = i->getNexthop(); r.push_back(keys); @@ -1223,5 +1164,4 @@ std::vector> read_router_route_list } } } -} diff --git a/src/services/pcn-router/src/api/RouterApiImpl.h b/src/services/pcn-router/src/api/RouterApiImpl.h index 7acd99197..937bebd9d 100644 --- a/src/services/pcn-router/src/api/RouterApiImpl.h +++ b/src/services/pcn-router/src/api/RouterApiImpl.h @@ -1,12 +1,8 @@ /** -* router API * router API generated from router.yang * -* OpenAPI spec version: 1.0.0 -* -* NOTE: This class is auto generated by the swagger code generator program. -* https://github.com/polycube-network/swagger-codegen.git -* branch polycube +* NOTE: This file is auto generated by polycube-codegen +* https://github.com/polycube-network/polycube-codegen */ @@ -26,84 +22,81 @@ #include #include "../Router.h" -#include "ArpEntryJsonObject.h" +#include "ArpTableJsonObject.h" #include "PortsJsonObject.h" #include "PortsSecondaryipJsonObject.h" #include "RouteJsonObject.h" #include "RouterJsonObject.h" #include -namespace io { -namespace swagger { -namespace server { +namespace polycube { +namespace service { namespace api { -using namespace io::swagger::server::model; +using namespace polycube::service::model; namespace RouterApiImpl { - void create_router_arp_entry_by_id(const std::string &name, const std::string &address, const ArpEntryJsonObject &value); - void create_router_arp_entry_list_by_id(const std::string &name, const std::vector &value); + void create_router_arp_table_by_id(const std::string &name, const std::string &address, const ArpTableJsonObject &value); + void create_router_arp_table_list_by_id(const std::string &name, const std::vector &value); void create_router_by_id(const std::string &name, const RouterJsonObject &value); void create_router_ports_by_id(const std::string &name, const std::string &portsName, const PortsJsonObject &value); void create_router_ports_list_by_id(const std::string &name, const std::vector &value); - void create_router_ports_secondaryip_by_id(const std::string &name, const std::string &portsName, const std::string &ip, const std::string &netmask, const PortsSecondaryipJsonObject &value); + void create_router_ports_secondaryip_by_id(const std::string &name, const std::string &portsName, const std::string &ip, const PortsSecondaryipJsonObject &value); void create_router_ports_secondaryip_list_by_id(const std::string &name, const std::string &portsName, const std::vector &value); - void create_router_route_by_id(const std::string &name, const std::string &network, const std::string &netmask, const std::string &nexthop, const RouteJsonObject &value); + void create_router_route_by_id(const std::string &name, const std::string &network, const std::string &nexthop, const RouteJsonObject &value); void create_router_route_list_by_id(const std::string &name, const std::vector &value); - void delete_router_arp_entry_by_id(const std::string &name, const std::string &address); - void delete_router_arp_entry_list_by_id(const std::string &name); + void delete_router_arp_table_by_id(const std::string &name, const std::string &address); + void delete_router_arp_table_list_by_id(const std::string &name); void delete_router_by_id(const std::string &name); void delete_router_ports_by_id(const std::string &name, const std::string &portsName); void delete_router_ports_list_by_id(const std::string &name); - void delete_router_ports_secondaryip_by_id(const std::string &name, const std::string &portsName, const std::string &ip, const std::string &netmask); + void delete_router_ports_secondaryip_by_id(const std::string &name, const std::string &portsName, const std::string &ip); void delete_router_ports_secondaryip_list_by_id(const std::string &name, const std::string &portsName); - void delete_router_route_by_id(const std::string &name, const std::string &network, const std::string &netmask, const std::string &nexthop); + void delete_router_route_by_id(const std::string &name, const std::string &network, const std::string &nexthop); void delete_router_route_list_by_id(const std::string &name); - ArpEntryJsonObject read_router_arp_entry_by_id(const std::string &name, const std::string &address); - std::string read_router_arp_entry_interface_by_id(const std::string &name, const std::string &address); - std::vector read_router_arp_entry_list_by_id(const std::string &name); - std::string read_router_arp_entry_mac_by_id(const std::string &name, const std::string &address); + ArpTableJsonObject read_router_arp_table_by_id(const std::string &name, const std::string &address); + std::string read_router_arp_table_interface_by_id(const std::string &name, const std::string &address); + std::vector read_router_arp_table_list_by_id(const std::string &name); + std::string read_router_arp_table_mac_by_id(const std::string &name, const std::string &address); RouterJsonObject read_router_by_id(const std::string &name); std::vector read_router_list_by_id(); PortsJsonObject read_router_ports_by_id(const std::string &name, const std::string &portsName); std::string read_router_ports_ip_by_id(const std::string &name, const std::string &portsName); std::vector read_router_ports_list_by_id(const std::string &name); std::string read_router_ports_mac_by_id(const std::string &name, const std::string &portsName); - std::string read_router_ports_netmask_by_id(const std::string &name, const std::string &portsName); - PortsSecondaryipJsonObject read_router_ports_secondaryip_by_id(const std::string &name, const std::string &portsName, const std::string &ip, const std::string &netmask); + PortsSecondaryipJsonObject read_router_ports_secondaryip_by_id(const std::string &name, const std::string &portsName, const std::string &ip); std::vector read_router_ports_secondaryip_list_by_id(const std::string &name, const std::string &portsName); - RouteJsonObject read_router_route_by_id(const std::string &name, const std::string &network, const std::string &netmask, const std::string &nexthop); - std::string read_router_route_interface_by_id(const std::string &name, const std::string &network, const std::string &netmask, const std::string &nexthop); + RouteJsonObject read_router_route_by_id(const std::string &name, const std::string &network, const std::string &nexthop); + std::string read_router_route_interface_by_id(const std::string &name, const std::string &network, const std::string &nexthop); std::vector read_router_route_list_by_id(const std::string &name); - uint32_t read_router_route_pathcost_by_id(const std::string &name, const std::string &network, const std::string &netmask, const std::string &nexthop); - void replace_router_arp_entry_by_id(const std::string &name, const std::string &address, const ArpEntryJsonObject &value); - void replace_router_arp_entry_list_by_id(const std::string &name, const std::vector &value); + uint32_t read_router_route_pathcost_by_id(const std::string &name, const std::string &network, const std::string &nexthop); + void replace_router_arp_table_by_id(const std::string &name, const std::string &address, const ArpTableJsonObject &value); + void replace_router_arp_table_list_by_id(const std::string &name, const std::vector &value); void replace_router_by_id(const std::string &name, const RouterJsonObject &value); void replace_router_ports_by_id(const std::string &name, const std::string &portsName, const PortsJsonObject &value); void replace_router_ports_list_by_id(const std::string &name, const std::vector &value); - void replace_router_ports_secondaryip_by_id(const std::string &name, const std::string &portsName, const std::string &ip, const std::string &netmask, const PortsSecondaryipJsonObject &value); + void replace_router_ports_secondaryip_by_id(const std::string &name, const std::string &portsName, const std::string &ip, const PortsSecondaryipJsonObject &value); void replace_router_ports_secondaryip_list_by_id(const std::string &name, const std::string &portsName, const std::vector &value); - void replace_router_route_by_id(const std::string &name, const std::string &network, const std::string &netmask, const std::string &nexthop, const RouteJsonObject &value); + void replace_router_route_by_id(const std::string &name, const std::string &network, const std::string &nexthop, const RouteJsonObject &value); void replace_router_route_list_by_id(const std::string &name, const std::vector &value); - void update_router_arp_entry_by_id(const std::string &name, const std::string &address, const ArpEntryJsonObject &value); - void update_router_arp_entry_interface_by_id(const std::string &name, const std::string &address, const std::string &value); - void update_router_arp_entry_list_by_id(const std::string &name, const std::vector &value); - void update_router_arp_entry_mac_by_id(const std::string &name, const std::string &address, const std::string &value); + void update_router_arp_table_by_id(const std::string &name, const std::string &address, const ArpTableJsonObject &value); + void update_router_arp_table_interface_by_id(const std::string &name, const std::string &address, const std::string &value); + void update_router_arp_table_list_by_id(const std::string &name, const std::vector &value); + void update_router_arp_table_mac_by_id(const std::string &name, const std::string &address, const std::string &value); void update_router_by_id(const std::string &name, const RouterJsonObject &value); void update_router_list_by_id(const std::vector &value); void update_router_ports_by_id(const std::string &name, const std::string &portsName, const PortsJsonObject &value); void update_router_ports_ip_by_id(const std::string &name, const std::string &portsName, const std::string &value); void update_router_ports_list_by_id(const std::string &name, const std::vector &value); void update_router_ports_mac_by_id(const std::string &name, const std::string &portsName, const std::string &value); - void update_router_ports_netmask_by_id(const std::string &name, const std::string &portsName, const std::string &value); - void update_router_ports_secondaryip_by_id(const std::string &name, const std::string &portsName, const std::string &ip, const std::string &netmask, const PortsSecondaryipJsonObject &value); + void update_router_ports_secondaryip_by_id(const std::string &name, const std::string &portsName, const std::string &ip, const PortsSecondaryipJsonObject &value); void update_router_ports_secondaryip_list_by_id(const std::string &name, const std::string &portsName, const std::vector &value); - void update_router_route_by_id(const std::string &name, const std::string &network, const std::string &netmask, const std::string &nexthop, const RouteJsonObject &value); + void update_router_route_by_id(const std::string &name, const std::string &network, const std::string &nexthop, const RouteJsonObject &value); void update_router_route_list_by_id(const std::string &name, const std::vector &value); - void update_router_route_pathcost_by_id(const std::string &name, const std::string &network, const std::string &netmask, const std::string &nexthop, const uint32_t &value); + void update_router_route_pathcost_by_id(const std::string &name, const std::string &network, const std::string &nexthop, const uint32_t &value); /* help related */ - std::vector> read_router_arp_entry_list_by_id_get_list(const std::string &name); + std::vector> read_router_arp_table_list_by_id_get_list(const std::string &name); std::vector> read_router_list_by_id_get_list(); std::vector> read_router_ports_list_by_id_get_list(const std::string &name); std::vector> read_router_ports_secondaryip_list_by_id_get_list(const std::string &name, const std::string &portsName); @@ -113,5 +106,4 @@ namespace RouterApiImpl { } } } -} diff --git a/src/services/pcn-router/src/base/ArpTableBase.cpp b/src/services/pcn-router/src/base/ArpTableBase.cpp new file mode 100644 index 000000000..ff9b979f0 --- /dev/null +++ b/src/services/pcn-router/src/base/ArpTableBase.cpp @@ -0,0 +1,44 @@ +/** +* router API generated from router.yang +* +* NOTE: This file is auto generated by polycube-codegen +* https://github.com/polycube-network/polycube-codegen +*/ + + +/* Do not edit this file manually */ + + +#include "ArpTableBase.h" +#include "../Router.h" + + +ArpTableBase::ArpTableBase(Router &parent) + : parent_(parent) {} + +ArpTableBase::~ArpTableBase() {} + +void ArpTableBase::update(const ArpTableJsonObject &conf) { + + if (conf.macIsSet()) { + setMac(conf.getMac()); + } + if (conf.interfaceIsSet()) { + setInterface(conf.getInterface()); + } +} + +ArpTableJsonObject ArpTableBase::toJsonObject() { + ArpTableJsonObject conf; + + conf.setAddress(getAddress()); + conf.setMac(getMac()); + conf.setInterface(getInterface()); + + return conf; +} + +std::shared_ptr ArpTableBase::logger() { + return parent_.logger(); +} + diff --git a/src/services/pcn-router/src/interface/ArpEntryInterface.h b/src/services/pcn-router/src/base/ArpTableBase.h similarity index 50% rename from src/services/pcn-router/src/interface/ArpEntryInterface.h rename to src/services/pcn-router/src/base/ArpTableBase.h index b4e595118..31165ac85 100644 --- a/src/services/pcn-router/src/interface/ArpEntryInterface.h +++ b/src/services/pcn-router/src/base/ArpTableBase.h @@ -1,35 +1,42 @@ /** -* router API * router API generated from router.yang * -* OpenAPI spec version: 1.0.0 -* -* NOTE: This class is auto generated by the swagger code generator program. -* https://github.com/polycube-network/swagger-codegen.git -* branch polycube +* NOTE: This file is auto generated by polycube-codegen +* https://github.com/polycube-network/polycube-codegen */ /* Do not edit this file manually */ /* -* ArpEntryInterface.h +* ArpTableBase.h * * */ #pragma once -#include "../serializer/ArpEntryJsonObject.h" +#include "../serializer/ArpTableJsonObject.h" + + + -using namespace io::swagger::server::model; -class ArpEntryInterface { -public: +#include - virtual void update(const ArpEntryJsonObject &conf) = 0; - virtual ArpEntryJsonObject toJsonObject() = 0; +using namespace polycube::service::model; + +class Router; + +class ArpTableBase { + public: + + ArpTableBase(Router &parent); + + virtual ~ArpTableBase(); + virtual void update(const ArpTableJsonObject &conf); + virtual ArpTableJsonObject toJsonObject(); /// /// Destination IP address @@ -47,5 +54,8 @@ class ArpEntryInterface { /// virtual std::string getInterface() = 0; virtual void setInterface(const std::string &value) = 0; -}; + std::shared_ptr logger(); + protected: + Router &parent_; +}; diff --git a/src/services/pcn-router/src/base/PortsBase.cpp b/src/services/pcn-router/src/base/PortsBase.cpp new file mode 100644 index 000000000..1538ca339 --- /dev/null +++ b/src/services/pcn-router/src/base/PortsBase.cpp @@ -0,0 +1,77 @@ +/** +* router API generated from router.yang +* +* NOTE: This file is auto generated by polycube-codegen +* https://github.com/polycube-network/polycube-codegen +*/ + + +/* Do not edit this file manually */ + + +#include "PortsBase.h" +#include "../Router.h" + +PortsBase::PortsBase(polycube::service::Cube &parent, + std::shared_ptr port) + : Port(port), parent_(dynamic_cast(parent)) {} + + +PortsBase::~PortsBase() {} + +void PortsBase::update(const PortsJsonObject &conf) { + set_conf(conf.getBase()); + + if (conf.ipIsSet()) { + setIp(conf.getIp()); + } + if (conf.secondaryipIsSet()) { + for (auto &i : conf.getSecondaryip()) { + auto ip = i.getIp(); + auto m = getSecondaryip(ip); + m->update(i); + } + } + if (conf.macIsSet()) { + setMac(conf.getMac()); + } +} + +PortsJsonObject PortsBase::toJsonObject() { + PortsJsonObject conf; + conf.setBase(to_json()); + + conf.setName(getName()); + conf.setIp(getIp()); + for(auto &i : getSecondaryipList()) { + conf.addPortsSecondaryip(i->toJsonObject()); + } + conf.setMac(getMac()); + + return conf; +} +void PortsBase::addSecondaryipList(const std::vector &conf) { + for (auto &i : conf) { + std::string ip_ = i.getIp(); + addSecondaryip(ip_, i); + } +} + +void PortsBase::replaceSecondaryip(const std::string &ip, const PortsSecondaryipJsonObject &conf) { + delSecondaryip(ip); + std::string ip_ = conf.getIp(); + addSecondaryip(ip_, conf); +} + +void PortsBase::delSecondaryipList() { + auto elements = getSecondaryipList(); + for (auto &i : elements) { + std::string ip_ = i->getIp(); + delSecondaryip(ip_); + } +} + +std::shared_ptr PortsBase::logger() { + return parent_.logger(); +} + diff --git a/src/services/pcn-router/src/base/PortsBase.h b/src/services/pcn-router/src/base/PortsBase.h new file mode 100644 index 000000000..7e1e5fe52 --- /dev/null +++ b/src/services/pcn-router/src/base/PortsBase.h @@ -0,0 +1,73 @@ +/** +* router API generated from router.yang +* +* NOTE: This file is auto generated by polycube-codegen +* https://github.com/polycube-network/polycube-codegen +*/ + + +/* Do not edit this file manually */ + +/* +* PortsBase.h +* +* +*/ + +#pragma once + +#include "../serializer/PortsJsonObject.h" + +#include "../PortsSecondaryip.h" + + + +#include "polycube/services/cube.h" +#include "polycube/services/port.h" + +#include "polycube/services/utils.h" +#include "polycube/services/fifo_map.hpp" + +#include + +using namespace polycube::service::model; + +class Router; +class Ports; + +class PortsBase: public polycube::service::Port { + public: + PortsBase(polycube::service::Cube &parent, + std::shared_ptr port); + + virtual ~PortsBase(); + virtual void update(const PortsJsonObject &conf); + virtual PortsJsonObject toJsonObject(); + + /// + /// IP address and prefix of the port + /// + virtual std::string getIp() = 0; + virtual void setIp(const std::string &value) = 0; + + /// + /// Additional IP addresses for the port + /// + virtual std::shared_ptr getSecondaryip(const std::string &ip) = 0; + virtual std::vector> getSecondaryipList() = 0; + virtual void addSecondaryip(const std::string &ip, const PortsSecondaryipJsonObject &conf) = 0; + virtual void addSecondaryipList(const std::vector &conf); + virtual void replaceSecondaryip(const std::string &ip, const PortsSecondaryipJsonObject &conf); + virtual void delSecondaryip(const std::string &ip) = 0; + virtual void delSecondaryipList(); + + /// + /// MAC address of the port + /// + virtual std::string getMac() = 0; + virtual void setMac(const std::string &value) = 0; + + std::shared_ptr logger(); + protected: + Router &parent_; +}; diff --git a/src/services/pcn-router/src/base/PortsSecondaryipBase.cpp b/src/services/pcn-router/src/base/PortsSecondaryipBase.cpp new file mode 100644 index 000000000..b0ebed2b1 --- /dev/null +++ b/src/services/pcn-router/src/base/PortsSecondaryipBase.cpp @@ -0,0 +1,36 @@ +/** +* router API generated from router.yang +* +* NOTE: This file is auto generated by polycube-codegen +* https://github.com/polycube-network/polycube-codegen +*/ + + +/* Do not edit this file manually */ + + +#include "PortsSecondaryipBase.h" +#include "../Router.h" + + +PortsSecondaryipBase::PortsSecondaryipBase(Ports &parent) + : parent_(parent) {} + +PortsSecondaryipBase::~PortsSecondaryipBase() {} + +void PortsSecondaryipBase::update(const PortsSecondaryipJsonObject &conf) { + +} + +PortsSecondaryipJsonObject PortsSecondaryipBase::toJsonObject() { + PortsSecondaryipJsonObject conf; + + conf.setIp(getIp()); + + return conf; +} + +std::shared_ptr PortsSecondaryipBase::logger() { + return parent_.logger(); +} + diff --git a/src/services/pcn-router/src/base/PortsSecondaryipBase.h b/src/services/pcn-router/src/base/PortsSecondaryipBase.h new file mode 100644 index 000000000..22ee27256 --- /dev/null +++ b/src/services/pcn-router/src/base/PortsSecondaryipBase.h @@ -0,0 +1,49 @@ +/** +* router API generated from router.yang +* +* NOTE: This file is auto generated by polycube-codegen +* https://github.com/polycube-network/polycube-codegen +*/ + + +/* Do not edit this file manually */ + +/* +* PortsSecondaryipBase.h +* +* +*/ + +#pragma once + +#include "../serializer/PortsSecondaryipJsonObject.h" + + + + + + +#include + +using namespace polycube::service::model; + +class Ports; + +class PortsSecondaryipBase { + public: + + PortsSecondaryipBase(Ports &parent); + + virtual ~PortsSecondaryipBase(); + virtual void update(const PortsSecondaryipJsonObject &conf); + virtual PortsSecondaryipJsonObject toJsonObject(); + + /// + /// Secondary IP address and prefix of the port + /// + virtual std::string getIp() = 0; + + std::shared_ptr logger(); + protected: + Ports &parent_; +}; diff --git a/src/services/pcn-router/src/base/RouteBase.cpp b/src/services/pcn-router/src/base/RouteBase.cpp new file mode 100644 index 000000000..c9ca7c4fc --- /dev/null +++ b/src/services/pcn-router/src/base/RouteBase.cpp @@ -0,0 +1,42 @@ +/** +* router API generated from router.yang +* +* NOTE: This file is auto generated by polycube-codegen +* https://github.com/polycube-network/polycube-codegen +*/ + + +/* Do not edit this file manually */ + + +#include "RouteBase.h" +#include "../Router.h" + + +RouteBase::RouteBase(Router &parent) + : parent_(parent) {} + +RouteBase::~RouteBase() {} + +void RouteBase::update(const RouteJsonObject &conf) { + + if (conf.pathcostIsSet()) { + setPathcost(conf.getPathcost()); + } +} + +RouteJsonObject RouteBase::toJsonObject() { + RouteJsonObject conf; + + conf.setNetwork(getNetwork()); + conf.setNexthop(getNexthop()); + conf.setInterface(getInterface()); + conf.setPathcost(getPathcost()); + + return conf; +} + +std::shared_ptr RouteBase::logger() { + return parent_.logger(); +} + diff --git a/src/services/pcn-router/src/interface/RouteInterface.h b/src/services/pcn-router/src/base/RouteBase.h similarity index 58% rename from src/services/pcn-router/src/interface/RouteInterface.h rename to src/services/pcn-router/src/base/RouteBase.h index 72b2957a7..6655da080 100644 --- a/src/services/pcn-router/src/interface/RouteInterface.h +++ b/src/services/pcn-router/src/base/RouteBase.h @@ -1,19 +1,15 @@ /** -* router API * router API generated from router.yang * -* OpenAPI spec version: 1.0.0 -* -* NOTE: This class is auto generated by the swagger code generator program. -* https://github.com/polycube-network/swagger-codegen.git -* branch polycube +* NOTE: This file is auto generated by polycube-codegen +* https://github.com/polycube-network/polycube-codegen */ /* Do not edit this file manually */ /* -* RouteInterface.h +* RouteBase.h * * */ @@ -23,24 +19,30 @@ #include "../serializer/RouteJsonObject.h" -using namespace io::swagger::server::model; -class RouteInterface { -public: - virtual void update(const RouteJsonObject &conf) = 0; - virtual RouteJsonObject toJsonObject() = 0; + + +#include + +using namespace polycube::service::model; + +class Router; + +class RouteBase { + public: + + RouteBase(Router &parent); + + virtual ~RouteBase(); + virtual void update(const RouteJsonObject &conf); + virtual RouteJsonObject toJsonObject(); /// /// Destination network IP /// virtual std::string getNetwork() = 0; - /// - /// Destination network netmask - /// - virtual std::string getNetmask() = 0; - /// /// Next hop; if destination is local will be shown 'local' instead of the ip address /// @@ -56,5 +58,8 @@ class RouteInterface { /// virtual uint32_t getPathcost() = 0; virtual void setPathcost(const uint32_t &value) = 0; -}; + std::shared_ptr logger(); + protected: + Router &parent_; +}; diff --git a/src/services/pcn-router/src/base/RouterBase.cpp b/src/services/pcn-router/src/base/RouterBase.cpp new file mode 100644 index 000000000..cacfa7a99 --- /dev/null +++ b/src/services/pcn-router/src/base/RouterBase.cpp @@ -0,0 +1,146 @@ +/** +* router API generated from router.yang +* +* NOTE: This file is auto generated by polycube-codegen +* https://github.com/polycube-network/polycube-codegen +*/ + + +/* Do not edit this file manually */ + + +#include "RouterBase.h" + +RouterBase::RouterBase(const std::string name) { + logger()->set_pattern("[%Y-%m-%d %H:%M:%S.%e] [Router] [%n] [%l] %v"); +} + + + +RouterBase::~RouterBase() {} + +void RouterBase::update(const RouterJsonObject &conf) { + set_conf(conf.getBase()); + + if (conf.portsIsSet()) { + for (auto &i : conf.getPorts()) { + auto name = i.getName(); + auto m = getPorts(name); + m->update(i); + } + } + if (conf.routeIsSet()) { + for (auto &i : conf.getRoute()) { + auto network = i.getNetwork(); + auto nexthop = i.getNexthop(); + auto m = getRoute(network, nexthop); + m->update(i); + } + } + if (conf.arpTableIsSet()) { + for (auto &i : conf.getArpTable()) { + auto address = i.getAddress(); + auto m = getArpTable(address); + m->update(i); + } + } +} + +RouterJsonObject RouterBase::toJsonObject() { + RouterJsonObject conf; + conf.setBase(to_json()); + + conf.setName(getName()); + for (auto &i : getPortsList()) { + conf.addPorts(i->toJsonObject()); + } + for(auto &i : getRouteList()) { + conf.addRoute(i->toJsonObject()); + } + for(auto &i : getArpTableList()) { + conf.addArpTable(i->toJsonObject()); + } + + return conf; +} +void RouterBase::addPortsList(const std::vector &conf) { + for (auto &i : conf) { + std::string name_ = i.getName(); + addPorts(name_, i); + } +} + +void RouterBase::replacePorts(const std::string &name, const PortsJsonObject &conf) { + delPorts(name); + std::string name_ = conf.getName(); + addPorts(name_, conf); +} + +void RouterBase::delPortsList() { + auto elements = getPortsList(); + for (auto &i : elements) { + std::string name_ = i->getName(); + delPorts(name_); + } +} + +void RouterBase::addPorts(const std::string &name, const PortsJsonObject &conf) { + add_port(name, conf); +} + +void RouterBase::delPorts(const std::string &name) { + remove_port(name); +} + +std::shared_ptr RouterBase::getPorts(const std::string &name) { + return get_port(name); +} + +std::vector> RouterBase::getPortsList() { + return get_ports(); +} +void RouterBase::addRouteList(const std::vector &conf) { + for (auto &i : conf) { + std::string network_ = i.getNetwork(); + std::string nexthop_ = i.getNexthop(); + addRoute(network_, nexthop_, i); + } +} + +void RouterBase::replaceRoute(const std::string &network, const std::string &nexthop, const RouteJsonObject &conf) { + delRoute(network, nexthop); + std::string network_ = conf.getNetwork(); + std::string nexthop_ = conf.getNexthop(); + addRoute(network_, nexthop_, conf); +} + +void RouterBase::delRouteList() { + auto elements = getRouteList(); + for (auto &i : elements) { + std::string network_ = i->getNetwork(); + std::string nexthop_ = i->getNexthop(); + delRoute(network_, nexthop_); + } +} +void RouterBase::addArpTableList(const std::vector &conf) { + for (auto &i : conf) { + std::string address_ = i.getAddress(); + addArpTable(address_, i); + } +} + +void RouterBase::replaceArpTable(const std::string &address, const ArpTableJsonObject &conf) { + delArpTable(address); + std::string address_ = conf.getAddress(); + addArpTable(address_, conf); +} + +void RouterBase::delArpTableList() { + auto elements = getArpTableList(); + for (auto &i : elements) { + std::string address_ = i->getAddress(); + delArpTable(address_); + } +} + + diff --git a/src/services/pcn-router/src/base/RouterBase.h b/src/services/pcn-router/src/base/RouterBase.h new file mode 100644 index 000000000..97cb9cd5b --- /dev/null +++ b/src/services/pcn-router/src/base/RouterBase.h @@ -0,0 +1,78 @@ +/** +* router API generated from router.yang +* +* NOTE: This file is auto generated by polycube-codegen +* https://github.com/polycube-network/polycube-codegen +*/ + + +/* Do not edit this file manually */ + +/* +* RouterBase.h +* +* +*/ + +#pragma once + +#include "../serializer/RouterJsonObject.h" + +#include "../ArpTable.h" +#include "../Ports.h" +#include "../Route.h" + +#include "polycube/services/cube.h" +#include "polycube/services/port.h" + + + +#include "polycube/services/utils.h" +#include "polycube/services/fifo_map.hpp" + +#include + +using namespace polycube::service::model; + + +class RouterBase: public virtual polycube::service::Cube { + public: + RouterBase(const std::string name); + + virtual ~RouterBase(); + virtual void update(const RouterJsonObject &conf); + virtual RouterJsonObject toJsonObject(); + + /// + /// Entry of the ports table + /// + virtual std::shared_ptr getPorts(const std::string &name); + virtual std::vector> getPortsList(); + virtual void addPorts(const std::string &name, const PortsJsonObject &conf); + virtual void addPortsList(const std::vector &conf); + virtual void replacePorts(const std::string &name, const PortsJsonObject &conf); + virtual void delPorts(const std::string &name); + virtual void delPortsList(); + + /// + /// Entry associated with the routing table + /// + virtual std::shared_ptr getRoute(const std::string &network, const std::string &nexthop) = 0; + virtual std::vector> getRouteList() = 0; + virtual void addRoute(const std::string &network, const std::string &nexthop, const RouteJsonObject &conf) = 0; + virtual void addRouteList(const std::vector &conf); + virtual void replaceRoute(const std::string &network, const std::string &nexthop, const RouteJsonObject &conf); + virtual void delRoute(const std::string &network,const std::string &nexthop) = 0; + virtual void delRouteList(); + + /// + /// Entry associated with the ARP table + /// + virtual std::shared_ptr getArpTable(const std::string &address) = 0; + virtual std::vector> getArpTableList() = 0; + virtual void addArpTable(const std::string &address, const ArpTableJsonObject &conf) = 0; + virtual void addArpTableList(const std::vector &conf); + virtual void replaceArpTable(const std::string &address, const ArpTableJsonObject &conf); + virtual void delArpTable(const std::string &address) = 0; + virtual void delArpTableList(); +}; diff --git a/src/services/pcn-router/src/interface/PortsInterface.h b/src/services/pcn-router/src/interface/PortsInterface.h deleted file mode 100644 index 420e9f04f..000000000 --- a/src/services/pcn-router/src/interface/PortsInterface.h +++ /dev/null @@ -1,64 +0,0 @@ -/** -* router API -* router API generated from router.yang -* -* OpenAPI spec version: 1.0.0 -* -* NOTE: This class is auto generated by the swagger code generator program. -* https://github.com/polycube-network/swagger-codegen.git -* branch polycube -*/ - - -/* Do not edit this file manually */ - -/* -* PortsInterface.h -* -* -*/ - -#pragma once - -#include "../serializer/PortsJsonObject.h" - -#include "../PortsSecondaryip.h" - -using namespace io::swagger::server::model; - -class PortsInterface { -public: - - virtual void update(const PortsJsonObject &conf) = 0; - virtual PortsJsonObject toJsonObject() = 0; - - /// - /// IP address of the port - /// - virtual std::string getIp() = 0; - virtual void setIp(const std::string &value) = 0; - - /// - /// Netmask of the port - /// - virtual std::string getNetmask() = 0; - virtual void setNetmask(const std::string &value) = 0; - - /// - /// Secondary IP address for the port - /// - virtual std::shared_ptr getSecondaryip(const std::string &ip, const std::string &netmask) = 0; - virtual std::vector> getSecondaryipList() = 0; - virtual void addSecondaryip(const std::string &ip, const std::string &netmask, const PortsSecondaryipJsonObject &conf) = 0; - virtual void addSecondaryipList(const std::vector &conf) = 0; - virtual void replaceSecondaryip(const std::string &ip, const std::string &netmask, const PortsSecondaryipJsonObject &conf) = 0; - virtual void delSecondaryip(const std::string &ip,const std::string &netmask) = 0; - virtual void delSecondaryipList() = 0; - - /// - /// MAC address of the port - /// - virtual std::string getMac() = 0; - virtual void setMac(const std::string &value) = 0; -}; - diff --git a/src/services/pcn-router/src/interface/PortsSecondaryipInterface.h b/src/services/pcn-router/src/interface/PortsSecondaryipInterface.h deleted file mode 100644 index 8368df38b..000000000 --- a/src/services/pcn-router/src/interface/PortsSecondaryipInterface.h +++ /dev/null @@ -1,44 +0,0 @@ -/** -* router API -* router API generated from router.yang -* -* OpenAPI spec version: 1.0.0 -* -* NOTE: This class is auto generated by the swagger code generator program. -* https://github.com/polycube-network/swagger-codegen.git -* branch polycube -*/ - - -/* Do not edit this file manually */ - -/* -* PortsSecondaryipInterface.h -* -* -*/ - -#pragma once - -#include "../serializer/PortsSecondaryipJsonObject.h" - - -using namespace io::swagger::server::model; - -class PortsSecondaryipInterface { -public: - - virtual void update(const PortsSecondaryipJsonObject &conf) = 0; - virtual PortsSecondaryipJsonObject toJsonObject() = 0; - - /// - /// Seconadary IP address of the port - /// - virtual std::string getIp() const = 0; - - /// - /// Secondary netmask of the port - /// - virtual std::string getNetmask() const = 0; -}; - diff --git a/src/services/pcn-router/src/interface/RouterInterface.h b/src/services/pcn-router/src/interface/RouterInterface.h deleted file mode 100644 index 1b127d021..000000000 --- a/src/services/pcn-router/src/interface/RouterInterface.h +++ /dev/null @@ -1,70 +0,0 @@ -/** -* router API -* router API generated from router.yang -* -* OpenAPI spec version: 1.0.0 -* -* NOTE: This class is auto generated by the swagger code generator program. -* https://github.com/polycube-network/swagger-codegen.git -* branch polycube -*/ - - -/* Do not edit this file manually */ - -/* -* RouterInterface.h -* -* -*/ - -#pragma once - -#include "../serializer/RouterJsonObject.h" - -#include "../ArpEntry.h" -#include "../Ports.h" -#include "../Route.h" - -using namespace io::swagger::server::model; - -class RouterInterface { -public: - - virtual void update(const RouterJsonObject &conf) = 0; - virtual RouterJsonObject toJsonObject() = 0; - - /// - /// Entry of the ports table - /// - virtual std::shared_ptr getPorts(const std::string &name) = 0; - virtual std::vector> getPortsList() = 0; - virtual void addPorts(const std::string &name, const PortsJsonObject &conf) = 0; - virtual void addPortsList(const std::vector &conf) = 0; - virtual void replacePorts(const std::string &name, const PortsJsonObject &conf) = 0; - virtual void delPorts(const std::string &name) = 0; - virtual void delPortsList() = 0; - - /// - /// Entry associated with the routing table - /// - virtual std::shared_ptr getRoute(const std::string &network, const std::string &netmask, const std::string &nexthop) = 0; - virtual std::vector> getRouteList() = 0; - virtual void addRoute(const std::string &network, const std::string &netmask, const std::string &nexthop, const RouteJsonObject &conf) = 0; - virtual void addRouteList(const std::vector &conf) = 0; - virtual void replaceRoute(const std::string &network, const std::string &netmask, const std::string &nexthop, const RouteJsonObject &conf) = 0; - virtual void delRoute(const std::string &network,const std::string &netmask,const std::string &nexthop) = 0; - virtual void delRouteList() = 0; - - /// - /// Entry associated with the ARP table - /// - virtual std::shared_ptr getArpEntry(const std::string &address) = 0; - virtual std::vector> getArpEntryList() = 0; - virtual void addArpEntry(const std::string &address, const ArpEntryJsonObject &conf) = 0; - virtual void addArpEntryList(const std::vector &conf) = 0; - virtual void replaceArpEntry(const std::string &address, const ArpEntryJsonObject &conf) = 0; - virtual void delArpEntry(const std::string &address) = 0; - virtual void delArpEntryList() = 0; -}; - diff --git a/src/services/pcn-router/src/serializer/ArpEntryJsonObject.cpp b/src/services/pcn-router/src/serializer/ArpTableJsonObject.cpp similarity index 56% rename from src/services/pcn-router/src/serializer/ArpEntryJsonObject.cpp rename to src/services/pcn-router/src/serializer/ArpTableJsonObject.cpp index 0b3209696..272ca27ab 100644 --- a/src/services/pcn-router/src/serializer/ArpEntryJsonObject.cpp +++ b/src/services/pcn-router/src/serializer/ArpTableJsonObject.cpp @@ -1,12 +1,8 @@ /** -* router API * router API generated from router.yang * -* OpenAPI spec version: 1.0.0 -* -* NOTE: This class is auto generated by the swagger code generator program. -* https://github.com/polycube-network/swagger-codegen.git -* branch polycube +* NOTE: This file is auto generated by polycube-codegen +* https://github.com/polycube-network/polycube-codegen */ @@ -14,21 +10,20 @@ -#include "ArpEntryJsonObject.h" +#include "ArpTableJsonObject.h" #include -namespace io { -namespace swagger { -namespace server { +namespace polycube { +namespace service { namespace model { -ArpEntryJsonObject::ArpEntryJsonObject() { +ArpTableJsonObject::ArpTableJsonObject() { m_addressIsSet = false; m_macIsSet = false; m_interfaceIsSet = false; } -ArpEntryJsonObject::ArpEntryJsonObject(const nlohmann::json &val) : +ArpTableJsonObject::ArpTableJsonObject(const nlohmann::json &val) : JsonObjectBase(val) { m_addressIsSet = false; m_macIsSet = false; @@ -48,7 +43,7 @@ ArpEntryJsonObject::ArpEntryJsonObject(const nlohmann::json &val) : } } -nlohmann::json ArpEntryJsonObject::toJson() const { +nlohmann::json ArpTableJsonObject::toJson() const { nlohmann::json val = nlohmann::json::object(); if (!getBase().is_null()) { val.update(getBase()); @@ -69,46 +64,46 @@ nlohmann::json ArpEntryJsonObject::toJson() const { return val; } -std::string ArpEntryJsonObject::getAddress() const { +std::string ArpTableJsonObject::getAddress() const { return m_address; } -void ArpEntryJsonObject::setAddress(std::string value) { +void ArpTableJsonObject::setAddress(std::string value) { m_address = value; m_addressIsSet = true; } -bool ArpEntryJsonObject::addressIsSet() const { +bool ArpTableJsonObject::addressIsSet() const { return m_addressIsSet; } -std::string ArpEntryJsonObject::getMac() const { +std::string ArpTableJsonObject::getMac() const { return m_mac; } -void ArpEntryJsonObject::setMac(std::string value) { +void ArpTableJsonObject::setMac(std::string value) { m_mac = value; m_macIsSet = true; } -bool ArpEntryJsonObject::macIsSet() const { +bool ArpTableJsonObject::macIsSet() const { return m_macIsSet; } -std::string ArpEntryJsonObject::getInterface() const { +std::string ArpTableJsonObject::getInterface() const { return m_interface; } -void ArpEntryJsonObject::setInterface(std::string value) { +void ArpTableJsonObject::setInterface(std::string value) { m_interface = value; m_interfaceIsSet = true; } -bool ArpEntryJsonObject::interfaceIsSet() const { +bool ArpTableJsonObject::interfaceIsSet() const { return m_interfaceIsSet; } @@ -118,5 +113,4 @@ bool ArpEntryJsonObject::interfaceIsSet() const { } } } -} diff --git a/src/services/pcn-router/src/serializer/ArpEntryJsonObject.h b/src/services/pcn-router/src/serializer/ArpTableJsonObject.h similarity index 66% rename from src/services/pcn-router/src/serializer/ArpEntryJsonObject.h rename to src/services/pcn-router/src/serializer/ArpTableJsonObject.h index c621cda28..132dd5f6a 100644 --- a/src/services/pcn-router/src/serializer/ArpEntryJsonObject.h +++ b/src/services/pcn-router/src/serializer/ArpTableJsonObject.h @@ -1,19 +1,15 @@ /** -* router API * router API generated from router.yang * -* OpenAPI spec version: 1.0.0 -* -* NOTE: This class is auto generated by the swagger code generator program. -* https://github.com/polycube-network/swagger-codegen.git -* branch polycube +* NOTE: This file is auto generated by polycube-codegen +* https://github.com/polycube-network/polycube-codegen */ /* Do not edit this file manually */ /* -* ArpEntryJsonObject.h +* ArpTableJsonObject.h * * */ @@ -24,20 +20,19 @@ #include "JsonObjectBase.h" -namespace io { -namespace swagger { -namespace server { +namespace polycube { +namespace service { namespace model { /// /// /// -class ArpEntryJsonObject : public JsonObjectBase { +class ArpTableJsonObject : public JsonObjectBase { public: - ArpEntryJsonObject(); - ArpEntryJsonObject(const nlohmann::json &json); - ~ArpEntryJsonObject() final = default; + ArpTableJsonObject(); + ArpTableJsonObject(const nlohmann::json &json); + ~ArpTableJsonObject() final = default; nlohmann::json toJson() const final; @@ -74,5 +69,4 @@ class ArpEntryJsonObject : public JsonObjectBase { } } } -} diff --git a/src/services/pcn-router/src/serializer/JsonObjectBase.cpp b/src/services/pcn-router/src/serializer/JsonObjectBase.cpp index fe615f329..847d5d415 100644 --- a/src/services/pcn-router/src/serializer/JsonObjectBase.cpp +++ b/src/services/pcn-router/src/serializer/JsonObjectBase.cpp @@ -1,12 +1,8 @@ /** -* router API * router API generated from router.yang * -* OpenAPI spec version: 1.0.0 -* -* NOTE: This class is auto generated by the swagger code generator program. -* https://github.com/polycube-network/swagger-codegen.git -* branch polycube +* NOTE: This file is auto generated by polycube-codegen +* https://github.com/polycube-network/polycube-codegen */ @@ -14,9 +10,8 @@ #include "JsonObjectBase.h" -namespace io { -namespace swagger { -namespace server { +namespace polycube { +namespace service { namespace model { JsonObjectBase::JsonObjectBase(const nlohmann::json &base) : base_(base) {} @@ -72,4 +67,3 @@ void JsonObjectBase::setBase(const nlohmann::json &base) { } } } -} diff --git a/src/services/pcn-router/src/serializer/JsonObjectBase.h b/src/services/pcn-router/src/serializer/JsonObjectBase.h index 52f9da754..17ed8e922 100644 --- a/src/services/pcn-router/src/serializer/JsonObjectBase.h +++ b/src/services/pcn-router/src/serializer/JsonObjectBase.h @@ -1,12 +1,8 @@ /** -* router API * router API generated from router.yang * -* OpenAPI spec version: 1.0.0 -* -* NOTE: This class is auto generated by the swagger code generator program. -* https://github.com/polycube-network/swagger-codegen.git -* branch polycube +* NOTE: This file is auto generated by polycube-codegen +* https://github.com/polycube-network/polycube-codegen */ @@ -26,9 +22,8 @@ #include #include -namespace io { -namespace swagger { -namespace server { +namespace polycube { +namespace service { namespace model { class JsonObjectBase { @@ -58,4 +53,3 @@ class JsonObjectBase { } } } -} diff --git a/src/services/pcn-router/src/serializer/PortsJsonObject.cpp b/src/services/pcn-router/src/serializer/PortsJsonObject.cpp index e4c3cfc52..3a6a64f23 100644 --- a/src/services/pcn-router/src/serializer/PortsJsonObject.cpp +++ b/src/services/pcn-router/src/serializer/PortsJsonObject.cpp @@ -1,12 +1,8 @@ /** -* router API * router API generated from router.yang * -* OpenAPI spec version: 1.0.0 -* -* NOTE: This class is auto generated by the swagger code generator program. -* https://github.com/polycube-network/swagger-codegen.git -* branch polycube +* NOTE: This file is auto generated by polycube-codegen +* https://github.com/polycube-network/polycube-codegen */ @@ -17,15 +13,13 @@ #include "PortsJsonObject.h" #include -namespace io { -namespace swagger { -namespace server { +namespace polycube { +namespace service { namespace model { PortsJsonObject::PortsJsonObject() { m_nameIsSet = false; m_ipIsSet = false; - m_netmaskIsSet = false; m_secondaryipIsSet = false; m_macIsSet = false; } @@ -34,7 +28,6 @@ PortsJsonObject::PortsJsonObject(const nlohmann::json &val) : JsonObjectBase(val) { m_nameIsSet = false; m_ipIsSet = false; - m_netmaskIsSet = false; m_secondaryipIsSet = false; m_macIsSet = false; @@ -47,10 +40,6 @@ PortsJsonObject::PortsJsonObject(const nlohmann::json &val) : setIp(val.at("ip").get()); } - if (val.count("netmask")) { - setNetmask(val.at("netmask").get()); - } - if (val.count("secondaryip")) { for (auto& item : val["secondaryip"]) { PortsSecondaryipJsonObject newItem{ item }; @@ -79,10 +68,6 @@ nlohmann::json PortsJsonObject::toJson() const { val["ip"] = m_ip; } - if (m_netmaskIsSet) { - val["netmask"] = m_netmask; - } - { nlohmann::json jsonArray; for (auto& item : m_secondaryip) { @@ -129,23 +114,10 @@ bool PortsJsonObject::ipIsSet() const { return m_ipIsSet; } - - -std::string PortsJsonObject::getNetmask() const { - return m_netmask; -} - -void PortsJsonObject::setNetmask(std::string value) { - m_netmask = value; - m_netmaskIsSet = true; -} - -bool PortsJsonObject::netmaskIsSet() const { - return m_netmaskIsSet; +void PortsJsonObject::unsetIp() { + m_ipIsSet = false; } - - const std::vector& PortsJsonObject::getSecondaryip() const{ return m_secondaryip; } @@ -185,5 +157,4 @@ void PortsJsonObject::unsetMac() { } } } -} diff --git a/src/services/pcn-router/src/serializer/PortsJsonObject.h b/src/services/pcn-router/src/serializer/PortsJsonObject.h index 6bf89c745..fe75c8bac 100644 --- a/src/services/pcn-router/src/serializer/PortsJsonObject.h +++ b/src/services/pcn-router/src/serializer/PortsJsonObject.h @@ -1,12 +1,8 @@ /** -* router API * router API generated from router.yang * -* OpenAPI spec version: 1.0.0 -* -* NOTE: This class is auto generated by the swagger code generator program. -* https://github.com/polycube-network/swagger-codegen.git -* branch polycube +* NOTE: This file is auto generated by polycube-codegen +* https://github.com/polycube-network/polycube-codegen */ @@ -26,9 +22,8 @@ #include "PortsSecondaryipJsonObject.h" #include -namespace io { -namespace swagger { -namespace server { +namespace polycube { +namespace service { namespace model { @@ -51,21 +46,15 @@ class PortsJsonObject : public JsonObjectBase { bool nameIsSet() const; /// - /// IP address of the port + /// IP address and prefix of the port /// std::string getIp() const; void setIp(std::string value); bool ipIsSet() const; + void unsetIp(); /// - /// Netmask of the port - /// - std::string getNetmask() const; - void setNetmask(std::string value); - bool netmaskIsSet() const; - - /// - /// Secondary IP address for the port + /// Additional IP addresses for the port /// const std::vector& getSecondaryip() const; void addPortsSecondaryip(PortsSecondaryipJsonObject value); @@ -85,8 +74,6 @@ class PortsJsonObject : public JsonObjectBase { bool m_nameIsSet; std::string m_ip; bool m_ipIsSet; - std::string m_netmask; - bool m_netmaskIsSet; std::vector m_secondaryip; bool m_secondaryipIsSet; std::string m_mac; @@ -96,5 +83,3 @@ class PortsJsonObject : public JsonObjectBase { } } } -} - diff --git a/src/services/pcn-router/src/serializer/PortsSecondaryipJsonObject.cpp b/src/services/pcn-router/src/serializer/PortsSecondaryipJsonObject.cpp index 6f25d62ff..6bf821f94 100644 --- a/src/services/pcn-router/src/serializer/PortsSecondaryipJsonObject.cpp +++ b/src/services/pcn-router/src/serializer/PortsSecondaryipJsonObject.cpp @@ -1,12 +1,8 @@ /** -* router API * router API generated from router.yang * -* OpenAPI spec version: 1.0.0 -* -* NOTE: This class is auto generated by the swagger code generator program. -* https://github.com/polycube-network/swagger-codegen.git -* branch polycube +* NOTE: This file is auto generated by polycube-codegen +* https://github.com/polycube-network/polycube-codegen */ @@ -17,29 +13,22 @@ #include "PortsSecondaryipJsonObject.h" #include -namespace io { -namespace swagger { -namespace server { +namespace polycube { +namespace service { namespace model { PortsSecondaryipJsonObject::PortsSecondaryipJsonObject() { m_ipIsSet = false; - m_netmaskIsSet = false; } PortsSecondaryipJsonObject::PortsSecondaryipJsonObject(const nlohmann::json &val) : JsonObjectBase(val) { m_ipIsSet = false; - m_netmaskIsSet = false; if (val.count("ip")) { setIp(val.at("ip").get()); } - - if (val.count("netmask")) { - setNetmask(val.at("netmask").get()); - } } nlohmann::json PortsSecondaryipJsonObject::toJson() const { @@ -52,10 +41,6 @@ nlohmann::json PortsSecondaryipJsonObject::toJson() const { val["ip"] = m_ip; } - if (m_netmaskIsSet) { - val["netmask"] = m_netmask; - } - return val; } @@ -74,23 +59,7 @@ bool PortsSecondaryipJsonObject::ipIsSet() const { -std::string PortsSecondaryipJsonObject::getNetmask() const { - return m_netmask; -} - -void PortsSecondaryipJsonObject::setNetmask(std::string value) { - m_netmask = value; - m_netmaskIsSet = true; -} - -bool PortsSecondaryipJsonObject::netmaskIsSet() const { - return m_netmaskIsSet; -} - - - -} } } } diff --git a/src/services/pcn-router/src/serializer/PortsSecondaryipJsonObject.h b/src/services/pcn-router/src/serializer/PortsSecondaryipJsonObject.h index 66679822f..0d456fd7f 100644 --- a/src/services/pcn-router/src/serializer/PortsSecondaryipJsonObject.h +++ b/src/services/pcn-router/src/serializer/PortsSecondaryipJsonObject.h @@ -1,12 +1,8 @@ /** -* router API * router API generated from router.yang * -* OpenAPI spec version: 1.0.0 -* -* NOTE: This class is auto generated by the swagger code generator program. -* https://github.com/polycube-network/swagger-codegen.git -* branch polycube +* NOTE: This file is auto generated by polycube-codegen +* https://github.com/polycube-network/polycube-codegen */ @@ -24,9 +20,8 @@ #include "JsonObjectBase.h" -namespace io { -namespace swagger { -namespace server { +namespace polycube { +namespace service { namespace model { @@ -42,28 +37,17 @@ class PortsSecondaryipJsonObject : public JsonObjectBase { /// - /// Seconadary IP address of the port + /// Secondary IP address and prefix of the port /// std::string getIp() const; void setIp(std::string value); bool ipIsSet() const; - /// - /// Secondary netmask of the port - /// - std::string getNetmask() const; - void setNetmask(std::string value); - bool netmaskIsSet() const; - private: std::string m_ip; bool m_ipIsSet; - std::string m_netmask; - bool m_netmaskIsSet; }; } } } -} - diff --git a/src/services/pcn-router/src/serializer/RouteJsonObject.cpp b/src/services/pcn-router/src/serializer/RouteJsonObject.cpp index 6668d9bbe..4e958a58a 100644 --- a/src/services/pcn-router/src/serializer/RouteJsonObject.cpp +++ b/src/services/pcn-router/src/serializer/RouteJsonObject.cpp @@ -1,12 +1,8 @@ /** -* router API * router API generated from router.yang * -* OpenAPI spec version: 1.0.0 -* -* NOTE: This class is auto generated by the swagger code generator program. -* https://github.com/polycube-network/swagger-codegen.git -* branch polycube +* NOTE: This file is auto generated by polycube-codegen +* https://github.com/polycube-network/polycube-codegen */ @@ -17,14 +13,12 @@ #include "RouteJsonObject.h" #include -namespace io { -namespace swagger { -namespace server { +namespace polycube { +namespace service { namespace model { RouteJsonObject::RouteJsonObject() { m_networkIsSet = false; - m_netmaskIsSet = false; m_nexthopIsSet = false; m_interfaceIsSet = false; m_pathcostIsSet = false; @@ -33,7 +27,6 @@ RouteJsonObject::RouteJsonObject() { RouteJsonObject::RouteJsonObject(const nlohmann::json &val) : JsonObjectBase(val) { m_networkIsSet = false; - m_netmaskIsSet = false; m_nexthopIsSet = false; m_interfaceIsSet = false; m_pathcostIsSet = false; @@ -43,10 +36,6 @@ RouteJsonObject::RouteJsonObject(const nlohmann::json &val) : setNetwork(val.at("network").get()); } - if (val.count("netmask")) { - setNetmask(val.at("netmask").get()); - } - if (val.count("nexthop")) { setNexthop(val.at("nexthop").get()); } @@ -70,10 +59,6 @@ nlohmann::json RouteJsonObject::toJson() const { val["network"] = m_network; } - if (m_netmaskIsSet) { - val["netmask"] = m_netmask; - } - if (m_nexthopIsSet) { val["nexthop"] = m_nexthop; } @@ -104,21 +89,6 @@ bool RouteJsonObject::networkIsSet() const { -std::string RouteJsonObject::getNetmask() const { - return m_netmask; -} - -void RouteJsonObject::setNetmask(std::string value) { - m_netmask = value; - m_netmaskIsSet = true; -} - -bool RouteJsonObject::netmaskIsSet() const { - return m_netmaskIsSet; -} - - - std::string RouteJsonObject::getNexthop() const { return m_nexthop; } @@ -172,5 +142,4 @@ void RouteJsonObject::unsetPathcost() { } } } -} diff --git a/src/services/pcn-router/src/serializer/RouteJsonObject.h b/src/services/pcn-router/src/serializer/RouteJsonObject.h index a4f464a98..dcf8bf416 100644 --- a/src/services/pcn-router/src/serializer/RouteJsonObject.h +++ b/src/services/pcn-router/src/serializer/RouteJsonObject.h @@ -1,12 +1,8 @@ /** -* router API * router API generated from router.yang * -* OpenAPI spec version: 1.0.0 -* -* NOTE: This class is auto generated by the swagger code generator program. -* https://github.com/polycube-network/swagger-codegen.git -* branch polycube +* NOTE: This file is auto generated by polycube-codegen +* https://github.com/polycube-network/polycube-codegen */ @@ -24,9 +20,8 @@ #include "JsonObjectBase.h" -namespace io { -namespace swagger { -namespace server { +namespace polycube { +namespace service { namespace model { @@ -48,13 +43,6 @@ class RouteJsonObject : public JsonObjectBase { void setNetwork(std::string value); bool networkIsSet() const; - /// - /// Destination network netmask - /// - std::string getNetmask() const; - void setNetmask(std::string value); - bool netmaskIsSet() const; - /// /// Next hop; if destination is local will be shown 'local' instead of the ip address /// @@ -81,8 +69,6 @@ class RouteJsonObject : public JsonObjectBase { private: std::string m_network; bool m_networkIsSet; - std::string m_netmask; - bool m_netmaskIsSet; std::string m_nexthop; bool m_nexthopIsSet; std::string m_interface; @@ -94,5 +80,4 @@ class RouteJsonObject : public JsonObjectBase { } } } -} diff --git a/src/services/pcn-router/src/serializer/RouterJsonObject.cpp b/src/services/pcn-router/src/serializer/RouterJsonObject.cpp index 8cf2bd138..fdc39f9a4 100644 --- a/src/services/pcn-router/src/serializer/RouterJsonObject.cpp +++ b/src/services/pcn-router/src/serializer/RouterJsonObject.cpp @@ -1,12 +1,8 @@ /** -* router API * router API generated from router.yang * -* OpenAPI spec version: 1.0.0 -* -* NOTE: This class is auto generated by the swagger code generator program. -* https://github.com/polycube-network/swagger-codegen.git -* branch polycube +* NOTE: This file is auto generated by polycube-codegen +* https://github.com/polycube-network/polycube-codegen */ @@ -17,16 +13,15 @@ #include "RouterJsonObject.h" #include -namespace io { -namespace swagger { -namespace server { +namespace polycube { +namespace service { namespace model { RouterJsonObject::RouterJsonObject() { m_nameIsSet = false; m_portsIsSet = false; m_routeIsSet = false; - m_arpEntryIsSet = false; + m_arpTableIsSet = false; } RouterJsonObject::RouterJsonObject(const nlohmann::json &val) : @@ -34,7 +29,7 @@ RouterJsonObject::RouterJsonObject(const nlohmann::json &val) : m_nameIsSet = false; m_portsIsSet = false; m_routeIsSet = false; - m_arpEntryIsSet = false; + m_arpTableIsSet = false; if (val.count("name")) { @@ -59,13 +54,13 @@ RouterJsonObject::RouterJsonObject(const nlohmann::json &val) : m_routeIsSet = true; } - if (val.count("arp-entry")) { - for (auto& item : val["arp-entry"]) { - ArpEntryJsonObject newItem{ item }; - m_arpEntry.push_back(newItem); + if (val.count("arp-table")) { + for (auto& item : val["arp-table"]) { + ArpTableJsonObject newItem{ item }; + m_arpTable.push_back(newItem); } - m_arpEntryIsSet = true; + m_arpTableIsSet = true; } } @@ -103,12 +98,12 @@ nlohmann::json RouterJsonObject::toJson() const { { nlohmann::json jsonArray; - for (auto& item : m_arpEntry) { + for (auto& item : m_arpTable) { jsonArray.push_back(JsonObjectBase::toJson(item)); } if (jsonArray.size() > 0) { - val["arp-entry"] = jsonArray; + val["arp-table"] = jsonArray; } } @@ -166,27 +161,26 @@ void RouterJsonObject::unsetRoute() { m_routeIsSet = false; } -const std::vector& RouterJsonObject::getArpEntry() const{ - return m_arpEntry; +const std::vector& RouterJsonObject::getArpTable() const{ + return m_arpTable; } -void RouterJsonObject::addArpEntry(ArpEntryJsonObject value) { - m_arpEntry.push_back(value); - m_arpEntryIsSet = true; +void RouterJsonObject::addArpTable(ArpTableJsonObject value) { + m_arpTable.push_back(value); + m_arpTableIsSet = true; } -bool RouterJsonObject::arpEntryIsSet() const { - return m_arpEntryIsSet; +bool RouterJsonObject::arpTableIsSet() const { + return m_arpTableIsSet; } -void RouterJsonObject::unsetArpEntry() { - m_arpEntryIsSet = false; +void RouterJsonObject::unsetArpTable() { + m_arpTableIsSet = false; } } } } -} diff --git a/src/services/pcn-router/src/serializer/RouterJsonObject.h b/src/services/pcn-router/src/serializer/RouterJsonObject.h index 48ffb112b..2d3e68ad5 100644 --- a/src/services/pcn-router/src/serializer/RouterJsonObject.h +++ b/src/services/pcn-router/src/serializer/RouterJsonObject.h @@ -1,12 +1,8 @@ /** -* router API * router API generated from router.yang * -* OpenAPI spec version: 1.0.0 -* -* NOTE: This class is auto generated by the swagger code generator program. -* https://github.com/polycube-network/swagger-codegen.git -* branch polycube +* NOTE: This file is auto generated by polycube-codegen +* https://github.com/polycube-network/polycube-codegen */ @@ -23,15 +19,14 @@ #include "JsonObjectBase.h" +#include "ArpTableJsonObject.h" #include "RouteJsonObject.h" #include "PortsJsonObject.h" #include -#include "ArpEntryJsonObject.h" #include "polycube/services/cube.h" -namespace io { -namespace swagger { -namespace server { +namespace polycube { +namespace service { namespace model { @@ -72,10 +67,10 @@ class RouterJsonObject : public JsonObjectBase { /// /// Entry associated with the ARP table /// - const std::vector& getArpEntry() const; - void addArpEntry(ArpEntryJsonObject value); - bool arpEntryIsSet() const; - void unsetArpEntry(); + const std::vector& getArpTable() const; + void addArpTable(ArpTableJsonObject value); + bool arpTableIsSet() const; + void unsetArpTable(); private: std::string m_name; @@ -84,12 +79,11 @@ class RouterJsonObject : public JsonObjectBase { bool m_portsIsSet; std::vector m_route; bool m_routeIsSet; - std::vector m_arpEntry; - bool m_arpEntryIsSet; + std::vector m_arpTable; + bool m_arpTableIsSet; }; } } } -} diff --git a/src/services/pcn-router/test/bridge/test2_2_4.sh b/src/services/pcn-router/test/bridge/test2_2_4.sh index f40460bc7..062ee0b90 100755 --- a/src/services/pcn-router/test/bridge/test2_2_4.sh +++ b/src/services/pcn-router/test/bridge/test2_2_4.sh @@ -44,7 +44,7 @@ polycubectl router add r2 type=$TYPE polycubectl simplebridge add br1 type=$TYPE polycubectl simplebridge add br2 type=$TYPE -router_add_port r1 to_br1 10.10.2.1 255.255.255.0 +router_add_port r1 to_br1 10.10.2.1/24 bridge_add_port br1 veth1 bridge_add_port br1 veth2 @@ -57,9 +57,9 @@ bridge_add_port br2 veth4 router_add_port_as_gateway r2 br2 2 br2 -router_add_route r1 10.0.2.0 255.255.255.0 10.1.0.2 -router_add_route r2 10.0.1.0 255.255.255.0 10.1.0.1 -router_add_route r2 10.10.2.1 255.255.255.255 10.1.0.1 +router_add_route r1 10.0.2.0/24 10.1.0.2 +router_add_route r2 10.0.1.0/24 10.1.0.1 +router_add_route r2 10.10.2.1/32 10.1.0.1 #sleep 40s #for fill filtering database diff --git a/src/services/pcn-router/test/bridge/test2_2_4_special.sh b/src/services/pcn-router/test/bridge/test2_2_4_special.sh index 231eba965..451a72015 100755 --- a/src/services/pcn-router/test/bridge/test2_2_4_special.sh +++ b/src/services/pcn-router/test/bridge/test2_2_4_special.sh @@ -46,16 +46,16 @@ bridge_add_port br1 veth2 polycubectl simplebridge br1 ports add to_r2 router_add_port_as_gateway r2 br2 2 br2 -router_add_port r2 to_br1 10.0.1.253 255.255.255.0 +router_add_port r2 to_br1 10.0.1.253/24 bridge_add_port br2 veth3 bridge_add_port br2 veth4 polycubectl connect br1:to_r2 r2:to_br1 -router_add_route r1 10.0.2.0 255.255.255.0 10.0.1.253 +router_add_route r1 10.0.2.0/24 10.0.1.253 -router_add_route r2 10.0.1.0 255.255.255.0 10.0.1.254 #ignored, local entry is preferred +router_add_route r2 10.0.1.0/24 10.0.1.254 #ignored, local entry is preferred sudo ip netns exec ns1 ping 10.0.1.2 -c 2 -i 0.5 sudo ip netns exec ns1 ping 10.0.2.1 -c 2 -i 0.5 diff --git a/src/services/pcn-router/test/bridge/test2_2_5.sh b/src/services/pcn-router/test/bridge/test2_2_5.sh index 443bd456b..8a0413468 100755 --- a/src/services/pcn-router/test/bridge/test2_2_5.sh +++ b/src/services/pcn-router/test/bridge/test2_2_5.sh @@ -38,37 +38,37 @@ add_routers 2 add_bridges 2 router_add_port_as_gateway r1 br1 1 br1 -router_add_secondary r1 br1 10.0.2.254 255.255.255.0 #DG for veth2 +router_add_secondary r1 br1 10.0.2.254/24 #DG for veth2 connect_router_p_to_p r1 r2 1 -router_add_secondary r1 r2 10.10.0.1 255.255.255.252 -router_add_secondary r2 r1 10.10.0.2 255.255.255.252 #secondary nexthop +router_add_secondary r1 r2 10.10.0.1/30 +router_add_secondary r2 r1 10.10.0.2/30 #secondary nexthop bridge_add_port br1 veth1 bridge_add_port br1 veth2 router_add_port_as_gateway r2 br2 3 br2 -router_add_secondary r2 br2 10.0.4.254 255.255.255.0 #DG for veth4 -router_add_secondary r2 br2 10.0.5.254 255.255.255.0 #DG for veth5 +router_add_secondary r2 br2 10.0.4.254/24 #DG for veth4 +router_add_secondary r2 br2 10.0.5.254/24 #DG for veth5 bridge_add_port br2 veth3 bridge_add_port br2 veth4 bridge_add_port br2 veth5 -router_add_route r1 10.0.3.0 255.255.255.0 10.1.0.2 5 -router_add_route r1 10.0.4.0 255.255.255.0 10.1.0.2 5 -router_add_route r1 10.0.5.0 255.255.255.0 10.1.0.2 5 +router_add_route r1 10.0.3.0/24 10.1.0.2 5 +router_add_route r1 10.0.4.0/24 10.1.0.2 5 +router_add_route r1 10.0.5.0/24 10.1.0.2 5 -router_add_route r2 10.0.1.0 255.255.255.0 10.1.0.1 5 -router_add_route r2 10.0.2.0 255.255.255.0 10.1.0.1 5 +router_add_route r2 10.0.1.0/24 10.1.0.1 5 +router_add_route r2 10.0.2.0/24 10.1.0.1 5 #minor patchost -router_add_route r1 10.0.3.0 255.255.255.0 10.10.0.2 2 +router_add_route r1 10.0.3.0/24 10.10.0.2 2 ping_cycle 5 ping_special 5 10.10.0.1 10.10.0.2 -polycubectl router r1 ports to_r2 secondaryip del 10.10.0.1 255.255.255.252 +polycubectl router r1 ports to_r2 secondaryip del 10.10.0.1/30 ping_cycle 5 diff --git a/src/services/pcn-router/test/helpers.bash b/src/services/pcn-router/test/helpers.bash index 3662c9475..6b7b4fd0d 100755 --- a/src/services/pcn-router/test/helpers.bash +++ b/src/services/pcn-router/test/helpers.bash @@ -27,7 +27,7 @@ function del_routers { } function router_add_port_as_gateway { #$3 network number #$4 bridge name - polycubectl router $1 ports add to_$2 ip=10.0.$3.254 netmask=255.255.255.0 + polycubectl router $1 ports add to_$2 ip=10.0.$3.254/24 if [[ $# -eq 4 ]] ; then polycubectl simplebridge $4 ports add to_$1 polycubectl connect $4:to_$1 $1:to_$4 @@ -38,30 +38,30 @@ function router_add_port_as_gateway { #$3 network number #$4 bridge name } -function router_add_port { #$3 ip $4 netmask - polycubectl router $1 ports add $2 ip=$3 netmask=$4 +function router_add_port { #$3 ip + polycubectl router $1 ports add $2 ip=$3 } function connect_router_p_to_p { #$1 router name 1, $2 router name 2, $3 network point to point connection - polycubectl router $1 ports add to_$2 ip=10.$3.0.1 netmask=255.255.255.252 - polycubectl router $2 ports add to_$1 ip=10.$3.0.2 netmask=255.255.255.252 + polycubectl router $1 ports add to_$2 ip=10.$3.0.1/30 + polycubectl router $2 ports add to_$1 ip=10.$3.0.2/30 polycubectl connect $1:to_$2 $2:to_$1 } function connect_router_secondary_p_to_p { #$1 router name 1, $2 router name 2, $3 network point to point connection - polycubectl router $1 ports to_$2 secondaryip add 10.$3.0.1 255.255.255.252 - polycubectl router $2 ports to_$1 secondaryip add 10.$3.0.2 255.255.255.252 + polycubectl router $1 ports to_$2 secondaryip add 10.$3.0.1/30 + polycubectl router $2 ports to_$1 secondaryip add 10.$3.0.2/30 polycubectl connect $1:to_$2 $2:to_$1 } function router_add_secondary { - polycubectl router $1 ports to_$2 secondaryip add $3 $4 + polycubectl router $1 ports to_$2 secondaryip add $3 } function router_add_secondary_as_gateway { -polycubectl router $1 ports to_$2 secondaryip add 10.0.$3.254 255.255.255.0 +polycubectl router $1 ports to_$2 secondaryip add 10.0.$3.254/24 if [[ $# -eq 4 ]] ; then polycubectl simplebridge $4 ports add to_$1 polycubectl connect $4:to_$1 $1:to_$4 @@ -72,10 +72,10 @@ polycubectl router $1 ports to_$2 secondaryip add 10.0.$3.254 255.255.255.0 function router_add_route { - if [[ $# -eq 5 ]] ; then - polycubectl router $1 route add $2 $3 $4 pathcost=$5 + if [[ $# -eq 4 ]] ; then + polycubectl router $1 route add $2 $3 pathcost=$4 else - polycubectl router $1 route add $2 $3 $4 + polycubectl router $1 route add $2 $3 fi } diff --git a/src/services/pcn-router/test/test1_3s.sh b/src/services/pcn-router/test/test1_3s.sh index e05a5171c..81f7788bb 100755 --- a/src/services/pcn-router/test/test1_3s.sh +++ b/src/services/pcn-router/test/test1_3s.sh @@ -41,23 +41,23 @@ set -e add_routers 1 # Creates three ports on the router, each one attached to a different namespace -router_add_port r1 to_veth1 10.0.0.120 255.255.255.0 -router_add_port r1 to_veth2 10.10.20.10 255.255.255.0 -router_add_port r1 to_veth3 10.30.10.10 255.255.255.0 +router_add_port r1 to_veth1 10.0.0.120/24 +router_add_port r1 to_veth2 10.10.20.10/24 +router_add_port r1 to_veth3 10.30.10.10/24 # Configure secondary addresses on port veth1 -router_add_secondary r1 veth1 10.10.10.1 255.255.255.0 -router_add_secondary r1 veth1 10.10.21.2 255.255.255.0 +router_add_secondary r1 veth1 10.10.10.1/24 +router_add_secondary r1 veth1 10.10.21.2/24 router_add_secondary_as_gateway r1 veth1 1 # Configure secondary addresses on port veth2 -router_add_secondary r1 veth2 10.14.1.1 255.255.255.0 -router_add_secondary r1 veth2 10.1.15.2 255.255.255.0 +router_add_secondary r1 veth2 10.14.1.1/24 +router_add_secondary r1 veth2 10.1.15.2/24 router_add_secondary_as_gateway r1 veth2 2 # Configure secondary addresses on port veth3 -router_add_secondary r1 veth3 11.1.1.1 255.255.255.0 -router_add_secondary r1 veth3 12.1.1.1 255.255.255.0 +router_add_secondary r1 veth3 11.1.1.1/24 +router_add_secondary r1 veth3 12.1.1.1/24 router_add_secondary_as_gateway r1 veth3 3 #ns1 on port veth1 diff --git a/src/services/pcn-router/test/test3_3s.sh b/src/services/pcn-router/test/test3_3s.sh index 7a2f2b0c5..ba8942c20 100755 --- a/src/services/pcn-router/test/test3_3s.sh +++ b/src/services/pcn-router/test/test3_3s.sh @@ -43,11 +43,11 @@ polycubectl router add r3 type=$TYPE router_add_port_as_gateway r1 veth1 1 -router_add_port r1 to_r2 10.10.10.10 255.255.255.0 -router_add_port r2 to_r1 10.10.20.10 255.255.255.0 +router_add_port r1 to_r2 10.10.10.10/24 +router_add_port r2 to_r1 10.10.20.10/24 connect_router_secondary_p_to_p r1 r2 1 -router_add_port r2 to_veth2 12.10.1.1 255.255.255.0 +router_add_port r2 to_veth2 12.10.1.1/24 router_add_secondary_as_gateway r2 veth2 2 connect_router_p_to_p r1 r3 2 @@ -55,17 +55,17 @@ connect_router_p_to_p r2 r3 3 router_add_port_as_gateway r3 veth3 3 -#router_add_route r1 10.0.2.0 255.255.255.0 10.1.0.2 -#router_add_route r1 10.0.3.0 255.255.255.0 10.2.0.2 -router_add_route r1 0.0.0.0 0.0.0.0 10.1.0.2 +#router_add_route r1 10.0.2.0/24 10.1.0.2 +#router_add_route r1 10.0.3.0/24 10.2.0.2 +router_add_route r1 0.0.0.0/0 10.1.0.2 -router_add_route r2 10.0.1.0 255.255.255.0 10.1.0.1 -router_add_route r2 10.0.3.0 255.255.255.0 10.3.0.2 +router_add_route r2 10.0.1.0/24 10.1.0.1 +router_add_route r2 10.0.3.0/24 10.3.0.2 -router_add_route r3 10.0.1.0 255.255.255.0 10.2.0.1 -router_add_route r3 10.0.2.0 255.255.255.0 10.3.0.1 -router_add_route r3 10.10.10.10 255.255.255.255 10.2.0.1 -router_add_route r3 10.10.20.10 255.255.255.255 10.3.0.1 +router_add_route r3 10.0.1.0/24 10.2.0.1 +router_add_route r3 10.0.2.0/24 10.3.0.1 +router_add_route r3 10.10.10.10/32 10.2.0.1 +router_add_route r3 10.10.20.10/32 10.3.0.1 router_routingtable_show r1 router_routingtable_show r2 @@ -78,5 +78,3 @@ ping_cycle 3 #test ICMP ttl exceeded packet test_fail sudo ip netns exec ns1 ping 10.0.2.2 -b -t1 -c 2 -i 0.5 - - diff --git a/src/services/pcn-router/test/test_shadow/test1.sh b/src/services/pcn-router/test/test_shadow/test1.sh index 0acc6bf8f..fbdd83a4b 100755 --- a/src/services/pcn-router/test/test_shadow/test1.sh +++ b/src/services/pcn-router/test/test_shadow/test1.sh @@ -17,7 +17,7 @@ polycubectl router add r1 shadow=true sudo ip netns ls # Add port p1 -router_add_port r1 p1 10.0.0.1 255.255.255.0 +router_add_port r1 p1 10.0.0.1/24 sudo ip netns exec pcn-r1 ip -c a # Change the Ip address of the p1 port from Linux diff --git a/src/services/pcn-router/test/test_shadow/test4.sh b/src/services/pcn-router/test/test_shadow/test4.sh index 58889a21b..1ec913fce 100755 --- a/src/services/pcn-router/test/test_shadow/test4.sh +++ b/src/services/pcn-router/test/test_shadow/test4.sh @@ -27,7 +27,7 @@ set -e # Create the router r1 (shadow) and the port p1 polycubectl router add r1 shadow=true -router_add_port r1 p1 10.0.0.1 255.255.255.0 +router_add_port r1 p1 10.0.0.1/24 # Show router r1 polycubectl router r1 show