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 | |
| 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 | |
| 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') |
| 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 | |
| 63 | topos = { 'vpls': ( lambda: VplsTopo() ) } |
| 64 | |
| 65 | if __name__ == '__main__': |
| 66 | from onosnet import run |
| 67 | run(VplsTopo()) |