Skip to content

Commit 4cde2de

Browse files
authored
Merge pull request #125 from gianlu33/project_stppbridge
Add bridge service
2 parents 8f0e9d1 + f90cad6 commit 4cde2de

154 files changed

Lines changed: 19787 additions & 40 deletions

File tree

Some content is hidden

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

Documentation/developers/datapath.rst

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,20 @@ The L3 (IP) and L4 (TCP, UDP) checksums has to be updated when fields in the pac
3636

3737
- **pcn_l4_csum_replace()**: wrapper of `BPF_FUNC_l4_csum_replace <https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=91bc4822c3d61b9bb7ef66d3b77948a4f9177954>`_
3838

39-
Services as :scm_web_file:`nat <src/services/pcn-nat/src/Nat_dp.c>` and :scm_web_file:`nat <src/services/pcn-loadbalancer-rp/src/Lbrp_dp.c>` show how to use these functions.
39+
Services as :scm_web:`nat <src/services/pcn-nat/src/Nat_dp.c>` and :scm_web:`nat <src/services/pcn-loadbalancer-rp/src/Lbrp_dp.c>` show how to use these functions.
40+
41+
Vlan Support
42+
************
43+
44+
The vlan handling in TC and XDP eBPF programs is a little bit different, so polycube includes a set of helpers to uniform this accross.
45+
46+
- bool pcn_is_vlan_present(struct CTXTYPE *pkt)
47+
48+
- int pcn_get_vlan_id(struct CTXTYPE *pkt, uint16_t *vlan_id, uint16_t *eth_proto);
49+
50+
- uint8_t pcn_vlan_pop_tag(struct CTXTYPE *pkt);
51+
52+
- uint8_t pcn_vlan_push_tag(struct CTXTYPE *pkt, u16 eth_proto, u32 vlan_id);
4053
4154

4255
Known limitations:

Documentation/services/pcn-bridge/bridge.rst

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,65 @@ Limitations
1414
-----------
1515

1616
- Currently it does not accept all vlans on a trunk port
17-
- This service still uses an old version of the polycube API, so some options like printing the whole instance or similar could be not available.
1817

1918
How to use
2019
----------
2120

22-
TODO.
21+
Create instances and ports
22+
::
23+
24+
# create the instance
25+
polycubectl bridge add br1
26+
27+
# add ports
28+
polycubectl br1 ports add p1
29+
30+
VLAN configuration
31+
::
32+
33+
# change VLAN in access mode
34+
polycubectl br1 ports p1 access set vlanid=2
35+
36+
# change port mode (access/trunk)
37+
polycubectl br1 ports p1 set mode=trunk
38+
39+
# add an allowed vlan in a trunk port
40+
polycubectl br1 ports p1 trunk allowed add 10
41+
42+
# change native vlan in a trunk port
43+
polycubectl br1 ports p1 trunk set native-vlan=2
44+
45+
# enable/disable native vlan in a trunk port
46+
polycubectl br1 ports p1 trunk set native-vlan-enabled=false
47+
48+
49+
Spanning Tree configuration
50+
::
51+
52+
# enable/disable spanning tree protocol
53+
polycubectl br1 set stp-enabled=true
54+
55+
# view active instances of STP
56+
polycubectl br1 stp show
57+
58+
# view a particular instance
59+
polycubectl br1 stp 1 show
60+
61+
# modify a parameter in an active instance
62+
polycubectl br1 stp 1 set priority=28672
63+
64+
# view STP configuration in a port
65+
polycubectl br1 ports p1 stp 1 show
66+
67+
# modify a paremeter in an active instance of a port
68+
polycubectl br1 ports p1 stp 1 set port-priority=64
2369

2470
Examples
2571
^^^^^^^^
72+
73+
.. toctree::
74+
:maxdepth: 2
75+
76+
example1/example1
77+
example2/example2
78+
example3/example3
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
Example 1 - Connectivity
2+
=========
3+
4+
In this example two network namespaces will be connected together by a bridge instance.
5+
6+
7+
The following code configures the network namespaces and virtual network interfaces to be used.
8+
9+
::
10+
11+
# copy and paste in your terminal
12+
13+
# namespace ns1 -> veth1 10.0.0.1/24
14+
# namespace ns2 -> veth2 10.0.0.2/24
15+
16+
for i in `seq 1 2`;
17+
do
18+
sudo ip netns del ns${i} > /dev/null 2>&1 # remove ns if already existed
19+
sudo ip link del veth${i} > /dev/null 2>&1
20+
21+
sudo ip netns add ns${i}
22+
sudo ip link add veth${i}_ type veth peer name veth${i}
23+
sudo ip link set veth${i}_ netns ns${i}
24+
sudo ip netns exec ns${i} ip link set dev veth${i}_ up
25+
sudo ip link set dev veth${i} up
26+
sudo ip netns exec ns${i} ifconfig veth${i}_ 10.0.0.${i}/24
27+
done
28+
29+
30+
Create a bridge instance, add and connects ports to virtual interfaces
31+
32+
::
33+
34+
# create instance
35+
polycubectl bridge add br1
36+
37+
# add and connect port to veth1
38+
polycubectl br1 ports add toveth1 peer=veth1
39+
40+
# add and connect port to veth2
41+
polycubectl br1 ports add toveth2 peer=veth2
42+
43+
44+
Ping between namespaces
45+
46+
::
47+
48+
# ping ns2 from ns1
49+
sudo ip netns exec ns1 ping 10.0.0.2
50+
51+
Print whole ``br1`` status
52+
53+
::
54+
55+
polycubectl br1 show
56+
57+
58+
Delete ports
59+
60+
::
61+
62+
polycubectl br1 ports del toveth1
63+
polycubectl br1 ports del toveth2
64+
65+
Remove ``br1``
66+
67+
::
68+
69+
polyubectl del br1
70+
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
Example 2 - VLAN
2+
=========
3+
4+
In this example we will test the VLAN support.
5+
We will configure two bridges, and four network namespaces connected to them.
6+
7+
::
8+
9+
veth1 veth3
10+
10.0.0.1/24 10.0.0.3/24
11+
| |
12+
| |
13+
VLAN 1 --> | | <-- VLAN 1
14+
+----------+ +----------+
15+
| br1 |-------------------------------------| br2 |
16+
| (cube) | ^ ^ | (cube) |
17+
+---------.+ | | +----------+
18+
VLAN 2 --> | TRUNK mode TRUNK mode | <-- VLAN 2
19+
| allowed 1,2 allowed 1,2 |
20+
| |
21+
veth2 veth4
22+
10.0.0.2/24 10.0.0.4/24
23+
24+
The following code configures the network namespaces and virtual network interfaces to be used.
25+
26+
::
27+
28+
# copy and paste in your terminal
29+
30+
# namespace ns1 -> veth1 10.0.0.1/24
31+
# namespace ns2 -> veth2 10.0.0.2/24
32+
# namespace ns3 -> veth3 10.0.0.3/24
33+
# namespace ns4 -> veth4 10.0.0.4/24
34+
35+
for i in `seq 1 4`;
36+
do
37+
sudo ip netns del ns${i} > /dev/null 2>&1 # remove ns if already existed
38+
sudo ip link del veth${i} > /dev/null 2>&1
39+
40+
sudo ip netns add ns${i}
41+
sudo ip link add veth${i}_ type veth peer name veth${i}
42+
sudo ip link set veth${i}_ netns ns${i}
43+
sudo ip netns exec ns${i} ip link set dev veth${i}_ up
44+
sudo ip link set dev veth${i} up
45+
sudo ip netns exec ns${i} ifconfig veth${i}_ 10.0.0.${i}/24
46+
done
47+
48+
49+
Create bridge instances, and connect virtual interfaces to them
50+
51+
::
52+
53+
# create instances
54+
polycubectl bridge add br1
55+
polycubectl bridge add br2
56+
57+
# create ports on br1
58+
polycubectl br1 ports add toveth1 peer=veth1
59+
polycubectl br1 ports add toveth2 peer=veth2
60+
polycubectl br1 ports add tobr2 mode=trunk
61+
62+
# create ports on br2
63+
polycubectl br2 ports add toveth3 peer=veth3
64+
polycubectl br2 ports add toveth4 peer=veth4
65+
polycubectl br2 ports add tobr1 mode=trunk
66+
67+
# connect the two bridges
68+
polycubectl connect br1:tobr2 br2:tobr1
69+
70+
Configure VLANs
71+
72+
::
73+
74+
# By default, ports are configured in access mode, with VLAN 1
75+
# Instead, ports in trunk mode have VLAN 1 allowed by default
76+
# (and that is also the native vlan)
77+
78+
# br1
79+
polycubectl br1 ports toveth2 access set vlanid=2
80+
polycubectl br1 ports tobr2 trunk allowed add 2
81+
82+
# br2
83+
polycubectl br2 ports toveth4 access set vlanid=2
84+
polycubectl br2 ports tobr1 trunk allowed add 2
85+
86+
Ping between namespaces
87+
88+
::
89+
90+
# ping ns3 from ns1
91+
sudo ip netns exec ns1 ping 10.0.0.3 # ok
92+
93+
# ping ns4 from ns2
94+
sudo ip netns exec ns2 ping 10.0.0.4 # ok
95+
96+
# ping ns4 from ns1
97+
sudo ip netns exec ns1 ping 10.0.0.4 # packet discarded by br2: not the same VLAN!
98+
99+
Delete bridges
100+
101+
::
102+
103+
polycubectl br1 del
104+
polycubectl br2 del
105+
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
Example 3 - Spanning Tree
2+
=========
3+
4+
In this example we will test the Spanning Tree configuration.
5+
We will have three bridges connected each other in a triangle.
6+
7+
::
8+
9+
priority: 32768 (default) priority: 28672
10+
| |
11+
+----------+ +----------+
12+
| br1 |-------------------------------------| br2 |
13+
| (cube) | | (cube) |
14+
+---------.+ +----------+
15+
| |
16+
| |
17+
| +----------+ |
18+
\-----------------| br3 |--------------------/
19+
| (cube) |
20+
+---------.+
21+
|
22+
priority: 24576
23+
24+
In this configuration, we expect that bridge ``br3`` will be the root bridge (lower priority).
25+
Furthermore, according to the STP algorithm, the port that should be blocked is port ``br1:tobr2``.
26+
27+
28+
Create bridge instances and connect them each other
29+
30+
::
31+
32+
# create instances
33+
polycubectl bridge add br1
34+
polycubectl bridge add br2
35+
polycubectl bridge add br3
36+
37+
# add ports
38+
polycubectl br1 ports add tobr2
39+
polycubectl br1 ports add tobr3
40+
polycubectl br2 ports add tobr1
41+
polycubectl br2 ports add tobr3
42+
polycubectl br3 ports add tobr1
43+
polycubectl br3 ports add tobr2
44+
45+
# connect ports
46+
polycubectl connect br1:tobr2 br2:tobr1
47+
polycubectl connect br1:tobr3 br3:tobr1
48+
polycubectl connect br2:tobr3 br3:tobr2
49+
50+
Enable STP in each bridge
51+
52+
::
53+
54+
polycubectl br1 set stp-enabled=true
55+
polycubectl br2 set stp-enabled=true
56+
polycubectl br3 set stp-enabled=true
57+
58+
Change priority of bridges
59+
60+
::
61+
62+
# In each bridge, STP instance of VLAN 1 is active by default
63+
# (all the ports are configured by default in access mode with VLAN 1)
64+
65+
# Default bridge priority: 32768
66+
polycubectl br2 stp 1 set priority=28672
67+
polycubectl br3 stp 1 set priority=24576
68+
69+
# Wait for convergence
70+
sleep 50
71+
72+
Check ports
73+
74+
::
75+
76+
# br1
77+
polycubectl br1 ports tobr2 stp 1 show state # blocking
78+
polycubectl br1 ports tobr3 stp 1 show state # forwarding
79+
80+
# br2
81+
polycubectl br2 ports tobr1 stp 1 show state # forwarding
82+
polycubectl br2 ports tobr3 stp 1 show state # forwarding
83+
84+
# br3
85+
polycubectl br3 ports tobr1 stp 1 show state # forwarding
86+
polycubectl br3 ports tobr2 stp 1 show state # forwarding
87+
88+
Delete bridges
89+
90+
::
91+
92+
polycubectl br1 del
93+
polycubectl br2 del
94+
polycubectl br3 del

src/polycubed/src/base_cube.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,22 @@ static __always_inline
477477
__wsum pcn_csum_diff(__be32 *from, u32 from_size, __be32 *to,
478478
u32 to_size, __wsum seed);
479479
480+
/* vlan related */
481+
static __always_inline
482+
bool pcn_is_vlan_present(struct CTXTYPE *pkt);
483+
484+
static __always_inline
485+
int pcn_get_vlan_id(struct CTXTYPE *pkt);
486+
487+
static __always_inline
488+
int pcn_get_vlan_proto(struct CTXTYPE *pkt);
489+
490+
static __always_inline
491+
int pcn_vlan_pop_tag(struct CTXTYPE *pkt);
492+
493+
static __always_inline
494+
int pcn_vlan_push_tag(struct CTXTYPE *pkt, u16 eth_proto, u32 vlan_id);
495+
480496
)";
481497

482498
} // namespace polycubed

0 commit comments

Comments
 (0)