Fix expected_status types
[integration/test.git] / csit / libraries / MininetTopo / vlan_vtn_test.py
1 #!/usr/bin/env python
2
3 from mininet.node import Host
4 from mininet.topo import Topo
5
6
7 class VLANHost(Host):
8     """Host connected to VLAN interface"""
9
10     def config(self, vlan=100, **params):
11         """Configure VLANHost according to (optional) parameters
12         vlan: VLAN ID for default interface"""
13
14         hostid = super(Host, self).config(**params)
15
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
26         intf.name = new_name
27         # add VLAN interface to host's name to intf map
28         self.nameToIntf[new_name] = intf
29         return hostid
30
31
32 class VlanTopo(Topo):
33
34     """Simple topology example."""
35
36     def __init__(self):
37         """Create custom topo."""
38
39         # Initialize topology
40         Topo.__init__(self)
41
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)
49
50         s1 = self.addSwitch("s1")
51         s2 = self.addSwitch("s2")
52         s3 = self.addSwitch("s3")
53
54         self.addLink(s1, s2)
55         self.addLink(s2, host1)
56         self.addLink(s2, host2)
57         self.addLink(s2, host3)
58         self.addLink(s1, s3)
59         self.addLink(s3, host4)
60         self.addLink(s3, host5)
61         self.addLink(s3, host6)
62
63
64 topos = {"vlantopo": (lambda: VlanTopo())}