Lab 2: Open vSwitch Virtual Switch Practice

(1) Basic requirements

a) Execute the ovs-vsctl show command in the /home/username/student number/lab2/ directory, and the screenshot of the execution result of the p0 and p1 connectivity tests;

b) A screenshot of opening Mininet CLI and executing the pingall command in the /home/username/student ID/lab2/ directory, a screenshot of the command result of viewing the OVS flow table in the above directory, and a screenshot of the wireshark packet capture. Please do not repeat the rest of the text, otherwise it will be deducted Minute;

Start Mininet CLI and execute the pingall command

View the command result of the OVS flow table

wireshark capture

(2) Advanced reading requirements SDNLAB experiment Use Mininet, write Python code, generate the SDN topology in (1), and use OVS commands directly in the code, so that you can directly run the Python program to complete the same VLAN division as (1).

code

#!/usr/bin/env python

from mininet.net import Mininet
from mininet.node import Controller, RemoteController, OVSController
from mininet.node import CPULimitedHost, Host, Node
from mininet.node import OVSKernelSwitch, UserSwitch
from mininet.node import IVSSwitch
from mininet.cli import CLI
from mininet.log import setLogLevel, info
from mininet.link import TCLink, Intf
from subprocess import call

def myNetwork():

    net = Mininet( topo=None,
                   build=False,
                   ipBase='10.0.0.0/8')

    info( '*** Adding controller\n' )
    c0=net.addController(name='c0',
                      controller=Controller,
                      protocol='tcp',
                      port=6633)

    info( '*** Add switches\n')
    s1 = net.addSwitch('s1', cls=OVSKernelSwitch)
    s2 = net.addSwitch('s2', cls=OVSKernelSwitch)

    info( '*** Add hosts\n')
    h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute=None)
    h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute=None)
    h3 = net.addHost('h3', cls=Host, ip='10.0.0.3', defaultRoute=None)
    h4 = net.addHost('h4', cls=Host, ip='10.0.0.4', defaultRoute=None)

    info( '*** Add links\n')
    net.addLink(h1, s1,1,1)
    net.addLink(s1, h2,2,1)
    net.addLink(s1, s2,3,3)
    net.addLink(s2, h4,2,1)
    net.addLink(s2, h3,1,1)

    info( '*** Starting network\n')
    net.build()
    info( '*** Starting controllers\n')
    for controller in net.controllers:
        controller.start()

    info( '*** Starting switches\n')
    net.get('s1').start([c0])
    net.get('s2').start([c0])

    info( '*** Post configure switches and hosts\n')
    s1.cmd('sudo ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,in_port=1,actions=push_vlan:0x8100,set_field:4096-\>vlan_vid,output:3')
    s1.cmd('sudo ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,in_port=2,actions=push_vlan:0x8100,set_field:4097-\>vlan_vid,output:3')
    s1.cmd('sudo ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,dl_vlan=0,actions=pop_vlan,output:1')
    s1.cmd('sudo ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,dl_vlan=1,actions=pop_vlan,output:2')
    s2.cmd('sudo ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,in_port=1,actions=push_vlan:0x8100,set_field:4096-\>vlan_vid,output:3')
    s2.cmd('sudo ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,in_port=2,actions=push_vlan:0x8100,set_field:4097-\>vlan_vid,output:3')
    s2.cmd('sudo ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,dl_vlan=0,actions=pop_vlan,output:1')
    s2.cmd('sudo ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,dl_vlan=1,actions=pop_vlan,output:2')
    CLI(net)
    net.stop()

if __name__ == '__main__':
    setLogLevel( 'info' )
    myNetwork()

Start Mininet CLI and execute pingall command

wireshark capture

Personal summary

  • When creating a port on an ovs switch, if you make a mistake, enter ovs-vsctl del-prot switch name port name Delete the port and create it again

  • When using the ovs command to add a flow table, you should first open the Mininet CLI, then open a new terminal and enter the ovs command

  • When wireshark captures packets, use sudo wireshark to enter the interface and select the port, then open a terminal to open Mininet CLI and execute the pingall command to see the packet information. The packets that are specially marked are the packets received and sent by the port we selected.

  • For advanced code, use a visual tool to generate the corresponding topology and generate a py file, then open py and add the link port and OVS command in the code.

  • The difficulty of this experiment is not much different from the last experiment. It is basically done by copying and pasting. I think the main thing is to try it boldly. After finishing it, I feel a little confused and feel inexplicable. I will look at the relevant theories later. Understand what each line of code does

  • Familiar with the use of ovs command and wireshark capture

Posted by shawon22 on Fri, 23 Sep 2022 21:17:04 +0300