Skip to content

Instantly share code, notes, and snippets.

@jpillora
Last active August 26, 2021 16:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpillora/8330573 to your computer and use it in GitHub Desktop.
Save jpillora/8330573 to your computer and use it in GitHub Desktop.
Mininet LOCAL port not responding
#!/usr/bin/python
from mininet.net import Mininet
from mininet.node import OVSSwitch
from mininet.cli import CLI
from mininet.log import setLogLevel
if __name__ == '__main__':
setLogLevel( 'info' ) # for CLI output
net = Mininet( switch=OVSSwitch, build=False )
print "*** Creating switches"
s1 = net.addSwitch( 's1' )
s2 = net.addSwitch( 's2' )
print "*** Creating links"
net.addLink( s1, s2 )
print "*** Starting network"
net.build()
s1.start([])
s2.start([])
print "*** Running CLI"
CLI( net )
print "*** Stopping network"
net.stop()
#now, run the config-switches.sh script
echo "Setting IP/Mac Addresses"
ifconfig s1 10.42.42.1 netmask 255.255.255.0 up
ifconfig s1 hw ether 00:00:00:00:00:01
ifconfig s2 10.42.42.2 netmask 255.255.255.0 up
ifconfig s2 hw ether 00:00:00:00:00:02
echo "Installing ARP entries"
arp -i s1 -s 10.42.42.2 00:00:00:00:00:02
arp -i s2 -s 10.42.42.1 00:00:00:00:00:01
echo "Installing Flows"
ovs-ofctl add-flow s1 dl_dst=00:00:00:00:00:02,action=1
ovs-ofctl add-flow s1 dl_dst=00:00:00:00:00:01,action=LOCAL
ovs-ofctl add-flow s2 dl_dst=00:00:00:00:00:01,action=1
ovs-ofctl add-flow s2 dl_dst=00:00:00:00:00:02,action=LOCAL
# s1-eth1(1)---s2-eth1(1)
# | |
# s1(LOCAL) s2(LOCAL)
echo "Pinging between LOCAL ports"
ping -I s1 10.42.42.2
# No reply from s2, though ICMP are arriving on the interface:
# tcpdump -i s2 icmp
# through the course of debugging, I've tried to create the above
# mininet scenario + config, using only OVS commands.
# this seems to demonstrate my problem:
# flow counters increment and
# tcpdump displays the ICMP passing through the interface
# though there are no ICMP replies, so I think i need to attach s2 to the linux loopback?
echo "=========\n Creating Switches and Ports..."
ovs-vsctl add-br s1
ovs-vsctl add-br s2
ovs-vsctl add-port s1 s1-eth0
ovs-vsctl add-port s2 s2-eth0
echo "=========\n Setting IP Address..."
S1_MAC=`ifconfig s1 | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'`
S2_MAC=`ifconfig s2 | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'`
#LOCAL port up with IP + MAC addresses
ifconfig s1 10.42.42.1 up
ifconfig s2 10.42.42.2 up
echo "=========\n Adding flows..."
#flows to enable outbound+inbound traffic (sX-eth0 is OF port 3)
ovs-ofctl add-flow s1 dl_dst=$S2_MAC,action=3
ovs-ofctl add-flow s1 dl_dst=$S1_MAC,action=LOCAL
ovs-ofctl add-flow s2 dl_dst=$S1_MAC,action=3
ovs-ofctl add-flow s2 dl_dst=$S2_MAC,action=LOCAL
echo "=========\n Linking..."
ovs-vsctl set interface s1-eth0 type=patch options:peer=s2-eth0
ovs-vsctl set interface s2-eth0 type=patch options:peer=s1-eth0
echo "=========\n Adding ARP entries..."
#ARP entry for the other switch
arp -i s1 -s 10.42.42.2 $S2_MAC
arp -i s2 -s 10.42.42.1 $S1_MAC
sleep 1
arp
# It should now look like
# s1-eth0(1)---s2-eth0(1)
# | |
# s1(LOCAL) s2(LOCAL)
echo "=========\n Pinging s1 -> s2 + Packet monitoring s2"
tcpdump -e -i s2 icmp &
sleep 1
ping -i 1 -w 2 -I s2 10.42.42.1
# No reply from s2, though ICMP are arriving on the interface...
sleep 1
killall tcpdump
echo "=========\n Cleaning up Switch 1 and Switch 2..."
ovs-vsctl del-br s1
ovs-vsctl del-br s2
# =========
# Creating Switches and Ports...
# =========
# Setting IP+MAC Addresses...
# =========
# Adding flows...
# =========
# Linking...
# =========
# Adding ARP entries...
# =========
# Pinging s1 -> s2 + Packet monitoring s2
# tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
# listening on s2, link-type EN10MB (Ethernet), capture size 65535 bytes
# PING 10.42.42.2 (10.42.42.2) from 10.42.42.1 s1: 56(84) bytes of data.
# 17:54:00.317631 3e:16:d4:58:b6:4c (oui Unknown) > 00:00:00:00:00:02 (oui Ethernet), ethertype IPv4 (0x0800), length 98: 10.42.42.1 > 10.42.42.2: ICMP echo request, id 19656, seq 1, length 64
# 17:54:01.318904 3e:16:d4:58:b6:4c (oui Unknown) > 00:00:00:00:00:02 (oui Ethernet), ethertype IPv4 (0x0800), length 98: 10.42.42.1 > 10.42.42.2: ICMP echo request, id 19656, seq 2, length 64
# 17:54:02.319942 3e:16:d4:58:b6:4c (oui Unknown) > 00:00:00:00:00:02 (oui Ethernet), ethertype IPv4 (0x0800), length 98: 10.42.42.1 > 10.42.42.2: ICMP echo request, id 19656, seq 3, length 64
# --- 10.42.42.2 ping statistics ---
# 3 packets transmitted, 0 received, 100% packet loss, time 2002ms
# 3 packets captured
# 3 packets received by filter
# 0 packets dropped by kernel
# =========
# Cleaning up Switch 1 and Switch 2...
# adding TAP devices to example 3 above
# THIS DOES NOT WORK
# echo "=========\n Creating TAP Interfaces..."
ip tuntap add dev s1-tap mode tap user root
ip tuntap add dev s2-tap mode tap user root
echo "=========\n Creating Switches and Ports..."
ovs-vsctl add-br s1
ovs-vsctl add-br s2
# place the linux TAP interfaces inside OVS
ovs-vsctl add-port s1 s1-tap
ovs-vsctl add-port s2 s2-tap
ovs-vsctl add-port s1 s1-eth0
ovs-vsctl add-port s2 s2-eth0
echo "=========\n Setting IP+MAC Addresses..."
#LOCAL port up with IP + MAC addresses
ifconfig s1 10.42.42.1 netmask 255.255.255.0 up
ifconfig s1 hw ether 00:00:00:00:00:01
ifconfig s2 10.42.42.2 netmask 255.255.255.0 up
ifconfig s2 hw ether 00:00:00:00:00:02
# set new IP addresses
# ip addr add /24 dev s1
# ip link set s1 up
# ip link set s1 address 00:00:00:00:00:01
# ip addr add 10.42.42.2/24 dev s2
# ip link set s2 up
# ip link set s2 address 00:00:00:00:00:02
echo "=========\n Adding flows..."
#flows to enable outbound+inbound traffic (sX-eth0 is OF port 3)
ovs-ofctl add-flow s1 dl_dst=00:00:00:00:00:02,action=4
ovs-ofctl add-flow s1 dl_dst=00:00:00:00:00:01,action=LOCAL
ovs-ofctl add-flow s2 dl_dst=00:00:00:00:00:01,action=4
ovs-ofctl add-flow s2 dl_dst=00:00:00:00:00:02,action=LOCAL
echo "=========\n Linking..."
ovs-vsctl set interface s1-eth0 type=patch options:peer=s2-eth0
ovs-vsctl set interface s2-eth0 type=patch options:peer=s1-eth0
echo "=========\n DEBUG"
ifconfig
ovs-ofctl show s1
ovs-ofctl show s2
echo "=========\n Cleaning up..."
ovs-vsctl del-br s1
ovs-vsctl del-br s2
exit 1
echo "=========\n Adding ARP entries..."
#ARP entry for the other switch
arp -i s1 -s 10.42.42.2 00:00:00:00:00:02
arp -i s2 -s 10.42.42.1 00:00:00:00:00:01
sleep 1
# It should now look like
# s1-eth0(1)---s2-eth0(1)
# | |
# s1(LOCAL) s2(LOCAL)
echo "=========\n Pinging s1 -> s2 + Packet monitoring s2"
tcpdump -e -i s2 icmp &
sleep 1
ping -i 1 -w 3 -c 3 -I s1 10.42.42.2
# No reply from s2, though ICMP are arriving on the interface...
sleep 1
killall tcpdump
echo "=========\n Cleaning up..."
ovs-vsctl del-br s1
ovs-vsctl del-br s2
ip tuntap del s1-tap mode tap
ip tuntap del s2-tap mode tap
echo "========="
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment