Luca Prete | 084caaf | 2016-10-18 15:55:10 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | from mininet.cli import CLI |
| 4 | from mininet.node import Link, Host |
| 5 | from mininet.net import Mininet |
| 6 | from mininet.node import RemoteController |
| 7 | from mininet.term import makeTerm |
| 8 | from mininet.topo import Topo |
| 9 | from functools import partial |
| 10 | |
| 11 | class VLANHost( Host ): |
| 12 | "Host connected to VLAN interface" |
| 13 | |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 14 | def config( self, vlan=10, **params ): |
Luca Prete | 084caaf | 2016-10-18 15:55:10 +0200 | [diff] [blame] | 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 | |
| 36 | class 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 Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 46 | s5 = self.addSwitch('s5') |
Luca Prete | 9829bf1 | 2016-11-10 21:49:53 -0800 | [diff] [blame] | 47 | s6 = self.addSwitch('s6') |
Luca Prete | 084caaf | 2016-10-18 15:55:10 +0200 | [diff] [blame] | 48 | |
Luca Prete | 9829bf1 | 2016-11-10 21:49:53 -0800 | [diff] [blame] | 49 | 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 Prete | 084caaf | 2016-10-18 15:55:10 +0200 | [diff] [blame] | 55 | |
Luca Prete | 9829bf1 | 2016-11-10 21:49:53 -0800 | [diff] [blame] | 56 | 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 Prete | 084caaf | 2016-10-18 15:55:10 +0200 | [diff] [blame] | 62 | |
Luca Prete | 084caaf | 2016-10-18 15:55:10 +0200 | [diff] [blame] | 63 | self.addLink(s1, s2) |
Luca Prete | 084caaf | 2016-10-18 15:55:10 +0200 | [diff] [blame] | 64 | self.addLink(s2, s3) |
| 65 | self.addLink(s3, s4) |
Luca Prete | 9829bf1 | 2016-11-10 21:49:53 -0800 | [diff] [blame] | 66 | 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 Prete | 084caaf | 2016-10-18 15:55:10 +0200 | [diff] [blame] | 72 | |
| 73 | topos = { 'vpls': ( lambda: VplsTopo() ) } |
| 74 | |
| 75 | if __name__ == '__main__': |
| 76 | from onosnet import run |
| 77 | run(VplsTopo()) |