3 from mininet.node import Host
4 from mininet.topo import Topo
8 """Host connected to VLAN interface"""
10 def config(self, vlan=100, **params):
11 """Configure VLANHost according to (optional) parameters
12 vlan: VLAN ID for default interface"""
14 hostid = super(Host, self).config(**params)
16 intf = self.defaultIntf()
17 # remove IP from default, "physical" interface
18 self.cmd("ifconfig %s inet 0" % intf)
19 # create VLAN interface
20 self.cmd("vconfig add %s %d" % (intf, vlan))
21 # assign the host's IP to the VLAN interface
22 self.cmd("ifconfig %s.%d inet %s" % (intf, vlan, params["ip"]))
23 # update the intf name and host's intf map
24 new_name = "%s.%d" % (intf, vlan)
25 # update the (Mininet) interface to refer to VLAN interface name
27 # add VLAN interface to host's name to intf map
28 self.nameToIntf[new_name] = intf
34 """Simple topology example."""
37 """Create custom topo."""
42 # Add hosts and switches
43 host1 = self.addHost("h1", cls=VLANHost, vlan=200)
44 host2 = self.addHost("h2", cls=VLANHost, vlan=300)
45 host3 = self.addHost("h3", cls=VLANHost, vlan=200)
46 host4 = self.addHost("h4", cls=VLANHost, vlan=300)
47 host5 = self.addHost("h5", cls=VLANHost, vlan=200)
48 host6 = self.addHost("h6", cls=VLANHost, vlan=300)
50 s1 = self.addSwitch("s1")
51 s2 = self.addSwitch("s2")
52 s3 = self.addSwitch("s3")
55 self.addLink(s2, host1)
56 self.addLink(s2, host2)
57 self.addLink(s2, host3)
59 self.addLink(s3, host4)
60 self.addLink(s3, host5)
61 self.addLink(s3, host6)
64 topos = {"vlantopo": (lambda: VlanTopo())}