Skip to content

Commit d303462

Browse files
authored
Merge pull request #178 from francescomessina/update_router
Update router to the ip/prefix notation, removing the netmask
2 parents 515b518 + 3273990 commit d303462

Some content is hidden

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

78 files changed

+1830
-2249
lines changed

Documentation/cubes.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,10 @@ For instance:
158158
# create port2 on br1 (simplebridge), it doesn't require any further parameters
159159
polycubectl br1 ports add port2
160160

161-
# create portX on r1 (router), it requires ip and netmask parameters
162-
polycubectl r1 ports add port1 ip=10.0.1.1 netmask=255.255.255.0
163-
polycubectl r1 ports add port2 ip=10.0.2.1 netmask=255.255.255.0
164-
polycubectl r1 ports add port1 ip=10.0.3.1 netmask=255.255.255.0
161+
# create portX on r1 (router), it doesn't require mandatory parameters, but it is useful to assign an ip (during or after creation)
162+
polycubectl r1 ports add port1 ip=10.0.1.1/24
163+
polycubectl r1 ports add port2 ip=10.0.2.1/24
164+
polycubectl r1 ports add port1 ip=10.0.3.1/24
165165

166166
Connect Ports
167167
^^^^^^^^^^^^^

Documentation/tutorials/tutorial2/tutorial2.rst

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,13 @@ Before trying to add a port, let's use the ``polycubectl`` help to get the info
7777

7878
Other parameters:
7979
peer=value string Peer name, such as a network interfaces (e.g., 'veth0') or another cube (e.g., 'br1:port2')
80-
ip=value string IP address of the port
81-
netmask=value string Netmask of the port
80+
ip=value string IP address and prefix of the port
8281
mac=value string MAC address of the port
8382
Example:
84-
polycubectl r1 ports add port1 peer=r0:port1 ip=207.46.130.1 netmask=255.255.255.0 mac=B3:23:45:F5:3A
83+
polycubectl r1 ports add port1 peer=r0:port1 ip=207.46.130.1/24 mac=B3:23:45:F5:3A
8584

8685

87-
The output indicates that a port name is expected ``Keyword``, and following it the ``peer``, ``ip``, ``netmask`` and ``mac`` are supported parameters.
86+
The output indicates that a port name is expected ``Keyword``, and following it the ``peer``, ``ip`` and ``mac`` are supported parameters.
8887

8988

9089
**Connect** ``veth1`` **to** ``r1``
@@ -93,7 +92,7 @@ The output indicates that a port name is expected ``Keyword``, and following it
9392
::
9493

9594
# create new port on r1 and set the IP parameters
96-
polycubectl r1 ports add to_veth1 ip=10.0.1.254 netmask=255.255.255.0
95+
polycubectl r1 ports add to_veth1 ip=10.0.1.254/24
9796
# connect port to netdev
9897
polycubectl connect r1:to_veth1 veth1
9998

@@ -102,8 +101,8 @@ The router automatically adds a new local entry in the routing table.
102101
::
103102

104103
polycubectl r1 show route
105-
interface netmask network nexthop pathcost
106-
to_veth1 255.255.255.0 10.0.1.0 local 0
104+
interface network nexthop pathcost
105+
to_veth1 10.0.1.0/24 local 0
107106

108107

109108

@@ -112,7 +111,7 @@ The router automatically adds a new local entry in the routing table.
112111
::
113112

114113
# create new port on r1 and set the IP parameters
115-
polycubectl r1 ports add to_veth2 ip=10.0.2.254 netmask=255.255.255.0
114+
polycubectl r1 ports add to_veth2 ip=10.0.2.254/24
116115

117116
# connect router port to netdev interface
118117
polycubectl r1 ports to_veth2 set peer=veth2
@@ -126,7 +125,7 @@ The router automatically adds a new local entry in the routing table.
126125

127126
# create new port on r1 and set the IP parameters
128127
# notice that in this case 'peer' is also set so the port is also connected to the netdev
129-
polycubectl r1 ports add to_veth3 ip=10.0.3.254 netmask=255.255.255.0 peer=veth3
128+
polycubectl r1 ports add to_veth3 ip=10.0.3.254/24 peer=veth3
130129

131130

132131
Step 3: Check configuration
@@ -144,16 +143,16 @@ You should see an output similar to the next one, where ports are ``up`` and hav
144143
loglevel: info
145144

146145
ports:
147-
name uuid status peer ip netmask mac
148-
to_veth3 c51bb0ed-9e6f-44ed-a096-b13bc1011331 up veth3 10.0.3.254 255.255.255.0 72:59:a8:c2:c2:44
149-
to_veth2 48f8d130-aa32-4354-a1b5-105df9a8ad7b up veth2 10.0.2.254 255.255.255.0 d6:42:7f:65:b4:40
150-
to_veth1 46c685b9-4c80-4466-9d81-985598a07444 up veth1 10.0.1.254 255.255.255.0 52:f0:5f:2c:a5:a7
146+
name uuid status peer ip mac
147+
to_veth3 c51bb0ed-9e6f-44ed-a096-b13bc1011331 up veth3 10.0.3.254/24 72:59:a8:c2:c2:44
148+
to_veth2 48f8d130-aa32-4354-a1b5-105df9a8ad7b up veth2 10.0.2.254/24 d6:42:7f:65:b4:40
149+
to_veth1 46c685b9-4c80-4466-9d81-985598a07444 up veth1 10.0.1.254/24 52:f0:5f:2c:a5:a7
151150

152151
route:
153-
network netmask nexthop interface pathcost
154-
10.0.1.0 255.255.255.0 local to_veth1 0
155-
10.0.2.0 255.255.255.0 local to_veth2 0
156-
10.0.3.0 255.255.255.0 local to_veth3 0
152+
network nexthop interface pathcost
153+
10.0.1.0/24 local to_veth1 0
154+
10.0.2.0/24 local to_veth2 0
155+
10.0.3.0/24 local to_veth3 0
157156

158157

159158
Step 4: Test the connectivity between the namespaces and the router

Documentation/tutorials/tutorial3/tutorial3.rst

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Step 3: Add and connect ports on routers
103103
::
104104

105105
# Create new port on r1 and set the IP parameters
106-
polycubectl r1 ports add to_br1 ip=10.0.1.254 netmask=255.255.255.0
106+
polycubectl r1 ports add to_br1 ip=10.0.1.254/24
107107
# Create a bridge interface on br1
108108
polycubectl br1 ports add to_r1
109109
# Connect both ports
@@ -117,15 +117,15 @@ In order to permit more networks on the same router interface we need to add a s
117117
::
118118

119119
# Add a secondary address on r1 interface `to_br1`
120-
polycubectl r1 ports to_br1 secondaryip add 10.0.2.254 255.255.255.0
120+
polycubectl r1 ports to_br1 secondaryip add 10.0.2.254/24
121121

122122

123123
**Connect** ``r2`` **to** ``br2``
124124

125125
::
126126

127127
# Create new port on r2 and set the IP parameters
128-
polycubectl r2 ports add to_br2 ip=10.0.3.254 netmask=255.255.255.0
128+
polycubectl r2 ports add to_br2 ip=10.0.3.254/24
129129

130130
# Create a bridge interface on br2
131131
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
139139
::
140140

141141
# Add the secondary addresses on r2 interface `to_br2`
142-
polycubectl r2 ports to_br2 secondaryip add 10.0.4.254 255.255.255.0
143-
polycubectl r2 ports to_br2 secondaryip add 10.0.5.254 255.255.255.0
142+
polycubectl r2 ports to_br2 secondaryip add 10.0.4.254/24
143+
polycubectl r2 ports to_br2 secondaryip add 10.0.5.254/24
144144

145145
**Connect the routers**
146146

@@ -149,8 +149,8 @@ We need to create a point-to-point link between the routers to connect them. To
149149
::
150150

151151
# Create new port on r1 and r2 and set the IP parameters
152-
polycubectl r1 ports add to_r2 ip=10.1.0.1 netmask=255.255.255.252
153-
polycubectl r2 ports add to_r1 ip=10.1.0.2 netmask=255.255.255.252
152+
polycubectl r1 ports add to_r2 ip=10.1.0.1/30
153+
polycubectl r2 ports add to_r1 ip=10.1.0.2/30
154154

155155
# Connects the routers
156156
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`
164164

165165
::
166166

167-
polycubectl r1 route add 10.0.3.0 255.255.255.0 10.1.0.2
168-
polycubectl r1 route add 10.0.4.0 255.255.255.0 10.1.0.2
169-
polycubectl r1 route add 10.0.5.0 255.255.255.0 10.1.0.2
167+
polycubectl r1 route add 10.0.3.0/24 10.1.0.2
168+
polycubectl r1 route add 10.0.4.0/24 10.1.0.2
169+
polycubectl r1 route add 10.0.5.0/24 10.1.0.2
170170

171171

172172
**Add static entries in the routing table of router `r2`**
@@ -175,8 +175,8 @@ We need to do the same on the router `r2`
175175

176176
::
177177

178-
polycubectl r2 route add 10.0.1.0 255.255.255.0 10.1.0.1
179-
polycubectl r2 route add 10.0.2.0 255.255.255.0 10.1.0.1
178+
polycubectl r2 route add 10.0.1.0/24 10.1.0.1
179+
polycubectl r2 route add 10.0.2.0/24 10.1.0.1
180180

181181

182182
**Show the routing tables of the routers**

scripts/install.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,14 @@ echo "Install polycube"
140140
cd $DIR/..
141141
if [ "$INSTALL_CLEAN_POLYCUBE" == true ] ; then
142142
$SUDO rm -rf build
143-
else
143+
#else
144144
# The above commands are executed only in case of a manual install;
145145
# Jenkins runs this script with "$INSTALL_CLEAN_POLYCUBE" = true
146146
# The above commands are useful in case you are re-running this
147147
# script on an existing install, i.e., update source code and
148148
# all the submodules
149-
git pull
150-
git submodule update --init --recursive
149+
#git pull
150+
#git submodule update --init --recursive
151151
fi
152152

153153
mkdir -p build && cd build

src/libs/polycube/include/polycube/services/utils.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@ uint32_t get_netmask_length(const std::string &netmask_string);
6565

6666
/* Take in ingress a prefix length like 24 and return the
6767
* "netmask" -> 255.255.255.0 in this case */
68-
std::string get_netmask_from_CIDR(const int cidr);
68+
std::string get_netmask_from_prefixlength(const int prefixlength);
69+
70+
/* Take in ingress an ip/prefix and return the ip address and the netmask
71+
* in the variables ip_address and netmask passed by reference */
72+
void split_ip_and_prefix(const std::string &ip_and_prefix,
73+
std::string &ip_address, std::string &netmask);
6974

7075
/*
7176
* formats a debug string, custom specifiers are evaluated by a

src/libs/polycube/src/utils.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,17 +296,33 @@ uint32_t get_netmask_length(const std::string &netmask_string) {
296296
throw std::runtime_error("IP Address is not in a valid format");
297297
}
298298

299-
std::string get_netmask_from_CIDR(const int cidr) {
299+
std::string get_netmask_from_prefixlength(const int prefixlength) {
300300
uint32_t ipv4Netmask;
301301

302+
if (prefixlength == 0) {
303+
return "0.0.0.0";
304+
}
305+
302306
ipv4Netmask = 0xFFFFFFFF;
303-
ipv4Netmask <<= 32 - cidr;
307+
ipv4Netmask <<= 32 - prefixlength;
304308
ipv4Netmask = ntohl(ipv4Netmask);
305309
struct in_addr addr = {ipv4Netmask};
306310

307311
return inet_ntoa(addr);
308312
}
309313

314+
void split_ip_and_prefix(const std::string &ip_and_prefix,
315+
std::string &ip_address, std::string &netmask) {
316+
// ip_and_prefix = ip_address/prefix
317+
std::istringstream split(ip_and_prefix);
318+
std::vector<std::string> info;
319+
char split_char = '/';
320+
for (std::string each; std::getline(split, each, split_char);
321+
info.push_back(each));
322+
ip_address = info[0];
323+
netmask = get_netmask_from_prefixlength(std::atoi(info[1].c_str()));
324+
}
325+
310326
} // namespace utils
311327
} // namespace service
312328
} // namespace polycube

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-nat/test/examples/example1.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ create_veth_net 2
3636
polycubectl nat add nat1
3737
polycubectl router add r1
3838

39-
polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip netmask=255.255.255.0
39+
polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip/24
4040
polycubectl router r1 ports to_veth1 set peer=veth1
41-
polycubectl router r1 ports add to_nat1 ip=$to_nat_ip netmask=255.255.255.0
41+
polycubectl router r1 ports add to_nat1 ip=$to_nat_ip/24
4242

4343
polycubectl nat1 ports add to_r1 type=INTERNAL
4444
polycubectl connect nat1:to_r1 r1:to_nat1

src/services/pcn-nat/test/examples/example2.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ create_veth_net 2
3636
polycubectl nat add nat1
3737
polycubectl router add r1
3838

39-
polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip netmask=255.255.255.0
39+
polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip/24
4040
polycubectl router r1 ports to_veth1 set peer=veth1
41-
polycubectl router r1 ports add to_nat1 ip=$to_nat_ip netmask=255.255.255.0
41+
polycubectl router r1 ports add to_nat1 ip=$to_nat_ip/24
4242

4343
polycubectl nat1 ports add to_r1 type=INTERNAL
4444
polycubectl connect nat1:to_r1 r1:to_nat1

src/services/pcn-nat/test/examples/example3.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ create_veth_net 2
3838
polycubectl nat add nat1
3939
polycubectl router add r1
4040

41-
polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip netmask=255.255.255.0
41+
polycubectl router r1 ports add to_veth1 ip=$to_veth1_ip/24
4242
polycubectl router r1 ports to_veth1 set peer=veth1
43-
polycubectl router r1 ports add to_nat1 ip=$to_nat_ip netmask=255.255.255.0
43+
polycubectl router r1 ports add to_nat1 ip=$to_nat_ip/24
4444

4545
polycubectl nat1 ports add to_r1 type=INTERNAL
4646
polycubectl connect nat1:to_r1 r1:to_nat1

0 commit comments

Comments
 (0)