Skip to content

Configuring NetASM Switch from Command Line

Muhammad Shahbaz edited this page Jun 13, 2015 · 12 revisions

Now, we we will learn how to configure a NetASM Switch using a command line utility called ctl. Uinsg this utility, we can configure various aspects of the NetASM switch like:

  • Specifying a new policy
  • Adding/Deleting/Querying switch ports
  • Adding/Deleting/Querying entries from a table (if present in the specified policy)

Complete list of options is provided here.

This time we will use a new policy (or NetASM program) called table_based_simple. It's a very cutdown version of OpenFlow 1.0. This policy has two tables called match and params. match table is used to match against a single Ethernet filed (eth_src). The params table is used to read the parameters. In this case, we only have one parameter to read in order to decide which port to send the packet to (i.e., outport_bitmap).

We will run the NetASM datapath in standalone mode without specifying any policy or ports. We will do so using the ctl utility.

$ sudopy python /home/vagrant/pox/pox.py --no-openflow netasm.back_ends.soft_switch.datapath --ctl_port --standalone

Note: this time we are specifying a new argument --ctl_port. This enables the switch to receive commands from the ctl utility. The default port value is 7791. However, you can change this value using --ctl_port=<port>.

In a new terminal, run the following command.

$ sudopy ./pox/pox.py --no-openflow datapaths.ctl --cmd=show

This will show the list of current ports assigned to the switch. At this moment, we haven't assigned any ports, so the list will be empty.

POX 0.2.0 (carp) / Copyright 2011-2013 James McCauley, et al.
INFO:ctl:Switch sw1

Now, assign ports to the switch. Before running the following command, make sure that you have created the given virtual ethernet pairs. You can find information on how to set these up, here.

$ sudopy ./pox/pox.py --no-openflow datapaths.ctl --cmd="add-port sw1 veth1"
$ sudopy ./pox/pox.py --no-openflow datapaths.ctl --cmd="add-port sw1 veth3"
$ sudopy ./pox/pox.py --no-openflow datapaths.ctl --cmd="add-port sw1 veth5"

Note: we used the add-port option for adding a port to the switch. However, add-port also requires the switch name that you want to add the port to. In our case, it is sw1. You can find the name for your switch using the show command, above.

If we run the show command again, we will see the following output.

POX 0.2.0 (carp) / Copyright 2011-2013 James McCauley, et al.
INFO:ctl:Switch sw1
   1 veth1
   2 veth3
   3 veth5

Now, let's specify the table_based_simple policy to the switch.

$ sudopy ./pox/pox.py --no-openflow datapaths.ctl --cmd="set-policy sw1 netasm.examples.netasm.controller_assisted.table_based_simple"

Running show command again, will show the current policy installed on the switch.

INFO:ctl:Switch sw1 (netasm.examples.netasm.controller_assisted.table_based_simple)
   1 veth1
   2 veth3
   3 veth5

Once, the switch is setup and policy is installed, we have to install flow rules to actually enable the packets to pass through the switch. We will do this using the add-table-entry option provided by the ctl utility.

Let's install the following rule.

  • 00:00:00:00:00:01 --> port 2 # forward all traffic from ethernet source MAC (00:00:00:00:00:01) to port 2
$ ./pox/pox.py --no-openflow datapaths.ctl --cmd="add-table-entry sw1 match_table 0 {'eth_src':(0x000000000001,0xFFFFFFFFFFFF)}"
$ ./pox/pox.py --no-openflow datapaths.ctl --cmd="add-table-entry sw1 params_table 0 {'outport_bitmap':2}"

Note: (a) outport_bitmap as obvious from its name is a bitmap, so, specifying the value 2 actually means 10 (in bits). Where bit:1, if set, sends packets to port 2. (b) When writing flow rules like this {'eth_src':(0x000000000001,0xFFFFFFFFFFFF)}, it shouldn't have any space, otherwise, it will cause an error. The 0xFFFFFFFFFFFF is the mask.

Now, to test if a packet having a source MAC address 00:00:00:00:00:01 is actually forwarded to port 2, let's start tcpdump on both veth2 and veth4 interfaces in separate terminals.

[Terminal A]

$ sudo tcpdump -i veth2

[Terminal B]

$ sudo tcpdump -i veth4

From another terminal, first change the MAC address of veth0 to 00:00:00:00:00:01 and then run ping.

$ sudo ifconfig veth0 hw ether 00:00:00:00:00:01
$ ping -I veth0 10.0.0.1

You should start seeing the following output on Terminal A, only, and not on Terminal B.

tcpdump: WARNING: veth2: no IPv4 address assigned
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on veth2, link-type EN10MB (Ethernet), capture size 65535 bytes
04:22:36.464569 ARP, Request who-has 10.0.0.1 tell vagrant-ubuntu-trusty-64, length 28
04:22:37.430538 ARP, Request who-has 10.0.0.1 tell vagrant-ubuntu-trusty-64, length 28
04:22:38.461756 ARP, Request who-has 10.0.0.1 tell vagrant-ubuntu-trusty-64, length 28
04:22:39.442962 ARP, Request who-has 10.0.0.1 tell vagrant-ubuntu-trusty-64, length 28
04:22:40.469272 ARP, Request who-has 10.0.0.1 tell vagrant-ubuntu-trusty-64, length 28
04:22:41.445691 ARP, Request who-has 10.0.0.1 tell vagrant-ubuntu-trusty-64, length 28

Clone this wiki locally