---
# System prepended metadata

title: Hub *versus* Switch
tags: [mininet-wifi-tutorials]

---

---
tags: mininet-wifi-tutorials
---

#  Hub *versus* Switch

## Activity 1: How a hub device works


First of all you need to identify the network topology that will be generated by the code below:

```python=
#!/usr/bin/python

'''@author: Ramon Fontes
   @email: ramon.fontes@imd.ufrn.br'''


import sys

from mininet.node import Controller
from mininet.log import setLogLevel, info
from mininet.cli import CLI
from mininet.net import Mininet


def topology():
    "Create a network."
    net = Mininet()

    info("*** Creating nodes\n")
    h1 = net.addHost('h1', ip='10.0.0.1/8')
    h2 = net.addHost('h2', ip='10.0.0.2/8')
    h3 = net.addHost('h3', ip='10.0.0.3/8')
    h4 = net.addHost('h4', ip='10.0.0.4/8')
    s1 = net.addSwitch('s1', failMode='standalone')

    info("*** Creating Links\n")
    net.addLink(h1, s1)
    net.addLink(h2, s1)
    net.addLink(h3, s1)
    net.addLink(h4, s1)

    info("*** Starting network\n")
    net.build()
    s1.start([])

    s1.cmd('ovs-ofctl add-flow s1 action=flood')
    for h in net.hosts:
        print "disable ipv6"
        h.cmd("sysctl -w net.ipv6.conf.all.disable_ipv6=1")
        h.cmd("sysctl -w net.ipv6.conf.default.disable_ipv6=1")
        h.cmd("sysctl -w net.ipv6.conf.lo.disable_ipv6=1")

    for sw in net.switches:
        print "disable ipv6"
        sw.cmd("sysctl -w net.ipv6.conf.all.disable_ipv6=1")
        sw.cmd("sysctl -w net.ipv6.conf.default.disable_ipv6=1")
        sw.cmd("sysctl -w net.ipv6.conf.lo.disable_ipv6=1")

    info("*** Running CLI\n")
    CLI(net)

    info("*** Stopping network\n")
    net.stop()


if __name__ == '__main__':
    setLogLevel('info')
    topology()
```

Since you have identified the network topology of the code above, you need to save and run it. Considering that the filename is my-hub-topo<span>.py, run it with the command below:

```
~$ sudo python my-hub-topo.py
```

Then, run Wireshark from **h1** and **h2**

```
mininet> h1 wireshark &
mininet> h2 wireshark &
```

and start capturing packets with Wireshark on ports h1-eth0 and h2-eth0.

Finally, make a ping between **h1** and **h4**.


```
mininet> h1 ping -c2 h4
```

:::info
Question #1 :mega: What can be concluded about the transmitted/received packets by/from **h1** and **h4**?
:::


:::info
Question #2 :mega: Describe the packets you can observe in Wireshark.
:::


## Activity 2: How a switch device works


First of all you need to identify the network topology that will be generated by the code below:

```python=
#!/usr/bin/python

'''@author: Ramon Fontes
   @email: ramonfontes@ifba.edu.br'''


import sys

from mininet.node import Controller
from mininet.log import setLogLevel, info
from mininet.cli import CLI
from mininet.net import Mininet


def topology():
    "Create a network."
    net = Mininet()

    info("*** Creating nodes\n")
    h1 = net.addHost('h1', ip='10.0.0.1/8')
    h2 = net.addHost('h2', ip='10.0.0.2/8')
    h3 = net.addHost('h3', ip='10.0.0.3/8')
    h4 = net.addHost('h4', ip='10.0.0.4/8')
    s1 = net.addSwitch('s1', failMode='standalone')

    info("*** Creating Links\n")
    net.addLink(h1, s1)
    net.addLink(h2, s1)
    net.addLink(h3, s1)
    net.addLink(h4, s1)

    info("*** Starting network\n")
    net.build()
    s1.start([])
    
    for h in net.hosts:
        print "disable ipv6"
        h.cmd("sysctl -w net.ipv6.conf.all.disable_ipv6=1")
        h.cmd("sysctl -w net.ipv6.conf.default.disable_ipv6=1")
        h.cmd("sysctl -w net.ipv6.conf.lo.disable_ipv6=1")

    for sw in net.switches:
        print "disable ipv6"
        sw.cmd("sysctl -w net.ipv6.conf.all.disable_ipv6=1")
        sw.cmd("sysctl -w net.ipv6.conf.default.disable_ipv6=1")
        sw.cmd("sysctl -w net.ipv6.conf.lo.disable_ipv6=1")

    info("*** Running CLI\n")
    CLI(net)

    info("*** Stopping network\n")
    net.stop()


if __name__ == '__main__':
    setLogLevel('info')
    topology()
```


Since you have identified the network topology of the code above, you need to save and run it. Considering that the filename is my-switch-topo<span>.py, run it with the command below:

```
~$ sudo python my-switch-topo.py
```

Then, run Wireshark from **h1** and **h2**

```
mininet> h1 wireshark &
mininet> h2 wireshark &
```

and start capturing packets with Wireshark on ports h1-eth0 and h2-eth0.

Finally, make a ping between **h1** and **h4**.


```
mininet> h1 ping -c2 h4
```

:::info
Question #1 :mega: What can be concluded about the transmitted/received packets by/from **h1** and **h4**?
:::


:::info
Question #2 :mega: What can you conclude about the way a switch device work? Compare the results with the results obtained in Activity 1.
:::