Skip to content

Commit 6f2f01f

Browse files
pcn-router: code updated
- Changed IP addresses and routes from the notation with the netmask to the notation with prefix length (CIDR). - The new ports do not require a mandatory IP when they are created. - Changed the name arp-entry in arp-table Signed-off-by: Francesco Messina <francescomessina92@hotmail.com>
1 parent e2954e0 commit 6f2f01f

47 files changed

Lines changed: 1682 additions & 2119 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/polycubed/src/cube.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,13 @@ std::shared_ptr<PortIface> Cube::add_port(const std::string &name,
164164
peerB.set_status(IFACE_STATUS::UP);
165165
peerA.set_namespace(prefix_ns + get_name());
166166
peerA.set_status(IFACE_STATUS::UP);
167-
if (conf.count("ip") && conf.count("netmask")) {
168-
int prefix = polycube::service::utils::get_netmask_length(conf.at("netmask").get<std::string>());
169-
peerA.set_ip(conf.at("ip").get<std::string>(), prefix);
167+
if (conf.count("ip")) {
168+
std::string ip_address;
169+
std::string netmask;
170+
polycube::service::utils::split_ip_and_prefix(
171+
conf.at("ip").get<std::string>(), ip_address, netmask);
172+
int prefix = polycube::service::utils::get_netmask_length(netmask);
173+
peerA.set_ip(ip_address, prefix);
170174
} else if (conf.count("ipv6")) {
171175
peerA.set_ipv6(conf.at("ipv6").get<std::string>());
172176
}

src/services/pcn-router/datamodel/router.yang

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,19 @@ module router {
1919

2020
uses "polycube-standard-base:standard-base-yang-module" {
2121
augment ports {
22-
leaf ip {
23-
type inet:ipv4-address;
24-
mandatory true;
25-
description "IP address of the port";
26-
polycube-base:cli-example "207.46.130.1";
27-
}
28-
29-
leaf netmask {
30-
type inet:ipv4-address;
31-
mandatory true;
32-
description "Netmask of the port";
33-
polycube-base:cli-example "255.255.255.0";
22+
leaf ip {
23+
type inet:ipv4-prefix;
24+
description "IP address and prefix of the port";
25+
polycube-base:cli-example "10.0.0.1/24";
3426
}
3527

3628
list secondaryip {
37-
description "Secondary IP address for the port";
38-
key "ip netmask";
29+
description "Additional IP addresses for the port";
30+
key "ip";
3931
leaf ip {
40-
type inet:ipv4-address;
41-
mandatory true;
42-
description "Seconadary IP address of the port";
43-
polycube-base:cli-example "207.46.131.1";
44-
}
45-
46-
leaf netmask {
47-
type inet:ipv4-address;
48-
mandatory true;
49-
description "Secondary netmask of the port";
50-
polycube-base:cli-example "255.255.255.0";
32+
type inet:ipv4-prefix;
33+
description "Secondary IP address and prefix of the port";
34+
polycube-base:cli-example "10.0.0.2/24";
5135
}
5236
}
5337

@@ -60,20 +44,13 @@ module router {
6044
}
6145

6246
list route {
63-
key "network netmask nexthop";
47+
key "network nexthop";
6448
description "Entry associated with the routing table";
6549
leaf network {
66-
type inet:ipv4-address;
50+
type inet:ipv4-prefix;
6751
mandatory true;
6852
description "Destination network IP";
69-
polycube-base:cli-example "123.13.34.0";
70-
}
71-
72-
leaf netmask {
73-
type inet:ipv4-address;
74-
mandatory true;
75-
description "Destination network netmask";
76-
polycube-base:cli-example "255.255.255.0";
53+
polycube-base:cli-example "10.0.0.0/24";
7754
}
7855

7956
leaf nexthop {
@@ -99,7 +76,7 @@ module router {
9976
}
10077
}
10178

102-
list arp-entry {
79+
list arp-table {
10380
key "address";
10481
description "Entry associated with the ARP table";
10582
leaf address {
@@ -110,7 +87,7 @@ module router {
11087
}
11188

11289
leaf mac {
113-
type string;
90+
type yang:mac-address;
11491
mandatory true;
11592
description "Destination MAC address";
11693
polycube-base:cli-example "C5:13:2D:36:27:9B";

src/services/pcn-router/src/ArpEntry.cpp

Lines changed: 0 additions & 82 deletions
This file was deleted.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2018 The Polycube Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
// TODO: Modify these methods with your own implementation
18+
19+
#include "ArpTable.h"
20+
#include "Router.h"
21+
22+
ArpTable::ArpTable(Router &parent, const ArpTableJsonObject &conf)
23+
: ArpTableBase(parent) {
24+
logger()->info("Creating ArpTable instance");
25+
}
26+
27+
ArpTable::ArpTable(Router &parent, const std::string &mac,
28+
const std::string &ip, const std::string &interface)
29+
: ArpTableBase(parent), mac_(mac), ip_(ip), interface_(interface) {}
30+
31+
ArpTable::~ArpTable() {}
32+
33+
std::string ArpTable::getAddress() {
34+
// This method retrieves the address value.
35+
return ip_;
36+
}
37+
38+
std::string ArpTable::getMac() {
39+
// This method retrieves the mac value.
40+
return mac_;
41+
}
42+
43+
void ArpTable::setMac(const std::string &value) {
44+
throw std::runtime_error("ArpTable::setMac: Method not implemented");
45+
}
46+
47+
std::string ArpTable::getInterface() {
48+
// This method retrieves the interface value.
49+
return interface_;
50+
}
51+
52+
void ArpTable::setInterface(const std::string &value) {
53+
throw std::runtime_error("ArpTable::setInterface: Method not implemented");
54+
}
Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,28 @@
1616

1717
#pragma once
1818

19-
#include "../interface/ArpEntryInterface.h"
20-
#include "polycube/services/utils.h"
21-
22-
#include <spdlog/spdlog.h>
19+
#include "../base/ArpTableBase.h"
2320

2421
class Router;
2522

26-
using namespace io::swagger::server::model;
23+
using namespace polycube::service::model;
2724

2825
struct arp_entry {
2926
uint64_t mac;
3027
uint32_t port;
3128
} __attribute__((packed));
3229

33-
class ArpEntry : public ArpEntryInterface {
30+
class ArpTable : public ArpTableBase {
3431
public:
35-
ArpEntry(Router &parent, const ArpEntryJsonObject &conf);
36-
ArpEntry(Router &parent, const std::string &mac, const std::string &ip,
37-
const std::string &interface);
38-
virtual ~ArpEntry();
39-
40-
std::shared_ptr<spdlog::logger> logger();
41-
void update(const ArpEntryJsonObject &conf) override;
42-
ArpEntryJsonObject toJsonObject() override;
32+
ArpTable(Router &parent, const ArpTableJsonObject &conf);
33+
ArpTable(Router &parent, const std::string &mac, const std::string &ip,
34+
const std::string &interface);
35+
virtual ~ArpTable();
4336

4437
/// <summary>
45-
/// Outgoing interface
38+
/// Destination IP address
4639
/// </summary>
47-
std::string getInterface() override;
48-
void setInterface(const std::string &value) override;
40+
std::string getAddress() override;
4941

5042
/// <summary>
5143
/// Destination MAC address
@@ -54,13 +46,12 @@ class ArpEntry : public ArpEntryInterface {
5446
void setMac(const std::string &value) override;
5547

5648
/// <summary>
57-
/// Destination IP address
49+
/// Outgoing interface
5850
/// </summary>
59-
std::string getAddress() override;
51+
std::string getInterface() override;
52+
void setInterface(const std::string &value) override;
6053

6154
private:
62-
Router &parent_;
63-
6455
std::string mac_;
6556
std::string ip_;
6657
std::string interface_;

src/services/pcn-router/src/CMakeLists.txt

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,44 @@ include(${PROJECT_SOURCE_DIR}/cmake/LoadFileAsVariable.cmake)
22

33
aux_source_directory(serializer SERIALIZER_SOURCES)
44
aux_source_directory(api API_SOURCES)
5-
aux_source_directory(default-src SRC_SOURCES)
5+
aux_source_directory(base BASE_SOURCES)
66

77
include_directories(serializer)
8-
include_directories(interface)
9-
include_directories(default-src)
108
include_directories(/usr/include/libnl3)
119

10+
if (NOT DEFINED POLYCUBE_STANDALONE_SERVICE OR POLYCUBE_STANDALONE_SERVICE)
11+
find_package(PkgConfig REQUIRED)
12+
pkg_check_modules(POLYCUBE libpolycube)
13+
include_directories(${POLYCUBE_INCLUDE_DIRS})
14+
endif(NOT DEFINED POLYCUBE_STANDALONE_SERVICE OR POLYCUBE_STANDALONE_SERVICE)
15+
1216
# Needed to load files as variables
1317
include_directories(${CMAKE_CURRENT_BINARY_DIR})
1418

1519
add_library(pcn-router SHARED
1620
${SERIALIZER_SOURCES}
1721
${API_SOURCES}
18-
${SRC_SOURCES}
19-
ArpEntry.cpp
22+
${BASE_SOURCES}
23+
ArpTable.cpp
2024
Ports.cpp
2125
PortsSecondaryip.cpp
2226
Route.cpp
2327
Router.cpp
2428
Router-lib.cpp
2529
CircularBuffer.cpp
26-
UtilityMethods.cpp)
30+
Utils.cpp)
2731

28-
# load ebpf datapath code in std::string variables
29-
load_file_as_variable(pcn-router Router_dp.c router_code)
32+
# load ebpf datapath code a variable
33+
load_file_as_variable(pcn-router
34+
Router_dp.c
35+
router_code)
3036

3137
# load datamodel in a variable
32-
load_file_as_variable(pcn-router ../datamodel/router.yang router_datamodel)
38+
load_file_as_variable(pcn-router
39+
../datamodel/router.yang
40+
router_datamodel)
3341

34-
target_link_libraries(pcn-router
35-
polycube
36-
tins
37-
uuid)
42+
target_link_libraries(pcn-router ${POLYCUBE_LIBRARIES})
3843

3944
# Specify shared library install directory
4045

0 commit comments

Comments
 (0)