blob: 0be2e6802ea19d55ac2006d648c0697c83b8081a [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
Carolina Fernandezb1cef5c2016-11-22 19:18:40 +010014 def config( self, vlan=10, **params ):
Luca Prete084caaf2016-10-18 15:55:10 +020015 """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')
Carolina Fernandezb1cef5c2016-11-22 19:18:40 +010046 s5 = self.addSwitch('s5')
Luca Prete9829bf12016-11-10 21:49:53 -080047 s6 = self.addSwitch('s6')
Luca Prete084caaf2016-10-18 15:55:10 +020048
Luca Prete9829bf12016-11-10 21:49:53 -080049 h1 = self.addHost('h1', cls=VLANHost, vlan=100, mac='00:00:00:00:00:01')
50 h2 = self.addHost('h2', cls=VLANHost, vlan=200, mac='00:00:00:00:00:02')
51 h3 = self.addHost('h3', cls=VLANHost, vlan=300, mac='00:00:00:00:00:03')
52 h4 = self.addHost('h4', cls=VLANHost, vlan=400, mac='00:00:00:00:00:04')
53 h5 = self.addHost('h5', mac='00:00:00:00:00:05')
54 h6 = self.addHost('h6', mac='00:00:00:00:00:06')
Luca Prete084caaf2016-10-18 15:55:10 +020055
Luca Prete9829bf12016-11-10 21:49:53 -080056 self.addLink(s1, h1, port1=1, port2=0)
57 self.addLink(s2, h2, port1=1, port2=0)
58 self.addLink(s3, h3, port1=1, port2=0)
59 self.addLink(s4, h4, port1=1, port2=0)
60 self.addLink(s5, h5, port1=1, port2=0)
61 self.addLink(s6, h6, port1=1, port2=0)
Luca Prete084caaf2016-10-18 15:55:10 +020062
Luca Prete084caaf2016-10-18 15:55:10 +020063 self.addLink(s1, s2)
Luca Prete084caaf2016-10-18 15:55:10 +020064 self.addLink(s2, s3)
65 self.addLink(s3, s4)
Luca Prete9829bf12016-11-10 21:49:53 -080066 self.addLink(s4, s1)
67 self.addLink(s4, s2)
68 self.addLink(s1, s5)
69 self.addLink(s4, s5)
70 self.addLink(s2, s6)
71 self.addLink(s3, s6)
Luca Prete084caaf2016-10-18 15:55:10 +020072
73topos = { 'vpls': ( lambda: VplsTopo() ) }
74
75if __name__ == '__main__':
76 from onosnet import run
77 run(VplsTopo())