blob: 0124541810d5911c4ae9392acfc168783b31a423 [file] [log] [blame]
Luca Prete084caaf2016-10-18 15:55:10 +02001#!/usr/bin/env python
2
3from mininet.cli import CLI
4from mininet.node import Link, Host
5from mininet.net import Mininet
6from mininet.node import RemoteController
7from mininet.term import makeTerm
8from mininet.topo import Topo
9from functools import partial
10
11class VLANHost( Host ):
12 "Host connected to VLAN interface"
13
14 def config( self, vlan=100, **params ):
15 """Configure VLANHost according to (optional) parameters:
16 vlan: VLAN ID for default interface"""
17
18 r = super( VLANHost, self ).config( **params )
19
20 intf = self.defaultIntf()
21 # remove IP from default, "physical" interface
22 self.cmd( 'ifconfig %s inet 0' % intf )
23 # create VLAN interface
24 self.cmd( 'vconfig add %s %d' % ( intf, vlan ) )
25 # assign the host's IP to the VLAN interface
26 self.cmd( 'ifconfig %s.%d inet %s' % ( intf, vlan, params['ip'] ) )
27 # update the intf name and host's intf map
28 newName = '%s.%d' % ( intf, vlan )
29 # update the (Mininet) interface to refer to VLAN interface name
30 intf.name = newName
31 # add VLAN interface to host's name to intf map
32 self.nameToIntf[ newName ] = intf
33
34 return r
35
36class VplsTopo(Topo):
37 ''' VPLS demo Topology '''
38
39 def __init__(self):
40 Topo.__init__(self)
41
42 s1 = self.addSwitch('s1')
43 s2 = self.addSwitch('s2')
44 s3 = self.addSwitch('s3')
45 s4 = self.addSwitch('s4')
46
47 v100h1 = self.addHost('v100h1', cls=VLANHost, vlan=100, mac='00:00:00:00:00:01')
48 v200h1 = self.addHost('v200h1', cls=VLANHost, vlan=200, mac='00:00:00:00:00:02')
49 v300h1 = self.addHost('v300h1', cls=VLANHost, vlan=300, mac='00:00:00:00:00:03')
50 v400h1 = self.addHost('v400h1', cls=VLANHost, vlan=400, mac='00:00:00:00:00:04')
51
52 self.addLink(s1, v100h1, port1=1, port2=0)
53 self.addLink(s2, v200h1, port1=1, port2=0)
54 self.addLink(s3, v300h1, port1=1, port2=0)
55 self.addLink(s4, v400h1, port1=1, port2=0)
56
57 self.addLink(s1, s4)
58 self.addLink(s1, s2)
59 self.addLink(s2, s4)
60 self.addLink(s2, s3)
61 self.addLink(s3, s4)
62
63topos = { 'vpls': ( lambda: VplsTopo() ) }
64
65if __name__ == '__main__':
66 from onosnet import run
67 run(VplsTopo())