Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interface parameter abstractions #43

Merged
merged 2 commits into from
Jul 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions docs/addressing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,46 @@ when creating the IPNet object.
finally:
net.stop()

You can also declare your subnets by declaring a Subnet overlay.

.. testcode:: static addressing 2

from ipmininet.iptopo import IPTopo
from ipmininet.overlay import Subnet
from ipmininet.ipnet import IPNet
from ipmininet.cli import IPCLI

class MyTopology(IPTopo):

def build(self, *args, **kwargs):

r1 = self.addRouter("r1")
r2 = self.addRouter("r2")
h1 = self.addHost("h1")
h2 = self.addHost("h2")

self.addLink(r1, r2)
self.addLink(r1, h1)
self.addLink(r2, h2)

# The interfaces of the nodes and links on their common LAN
# will get an address for each subnet.
self.addOverlay(Subnet(nodes=[r1, r2],
subnets=["2042:12::/64", "10.12.0.0/24"]))
self.addOverlay(Subnet(nodes=[r1, h1],
subnets=["2042:1a::/64", "10.51.0.0/24"]))
self.addOverlay(Subnet(links=[(r2, h2)],
subnets=["2042:2b::/64", "10.62.0.0/24"]))

super(MyTopology, self).build(*args, **kwargs)

net = IPNet(topo=MyTopology(), allocate_IPs=False) # Disable IP auto-allocation
try:
net.start()
IPCLI(net)
finally:
net.stop()

Static routing
--------------

Expand Down
48 changes: 24 additions & 24 deletions docs/daemons.rst
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@ We can pass parameters to links and interfaces when calling ``addLink()``:
router2 = self.addRouter("router2")

# Add link
self.addLink(router1, router2,
igp_cost=5, igp_area="0.0.0.1", # Link parameters
params1={"ospf_dead_int": 1}, # Router1 interface parameters
params2={"ospf_priority": 1}) # Router2 interface parameters
l = self.addLink(router1, router2,
igp_cost=5, igp_area="0.0.0.1") # Link parameters
l[router1].addParams(ospf_dead_int=1) # Router1 interface parameters
l[router2].addParams(ospf_priority=1) # Router2 interface parameters

super(MyTopology, self).build(*args, **kwargs)

Expand Down Expand Up @@ -255,10 +255,10 @@ It uses the following interface parameters:
router2 = self.addRouter("router2")

# Add link
self.addLink(router1, router2,
igp_cost=5, # Link parameters
params1={"ospf6_dead_int": 1}, # Router1 interface parameters
params2={"ospf6_priority": 1}) # Router2 interface parameters
l = self.addLink(router1, router2,
igp_cost=5) # Link parameters
l[router1].addParams(ospf6_dead_int=1) # Router1 interface parameters
l[router2].addParams(ospf6_priority=1) # Router2 interface parameters

super(MyTopology, self).build(*args, **kwargs)

Expand Down Expand Up @@ -301,15 +301,15 @@ This daemon also uses the following interface parameters:
h = self.addHost('h')
dns = self.addHost('dns')

self.addLink(r, h, params1={
"ip": ("2001:1341::1/64", "2001:2141::1/64"), # Static IP address
"ra": [AdvPrefix("2001:1341::/64", valid_lifetime=86400, preferred_lifetime=14400),
AdvPrefix("2001:2141::/64")],
"rdnss": [AdvRDNSS("2001:89ab::d", max_lifetime=25),
AdvRDNSS("2001:cdef::d", max_lifetime=25)]})
self.addLink(r, dns,
params1={"ip": ("2001:89ab::1/64", "2001:cdef::1/64")}, # Static IP address
params2={"ip": ("2001:89ab::d/64", "2001:cdef::d/64")}) # Static IP address
lrh = self.addLink(r, h)
lrh[r].addParams(ip=("2001:1341::1/64", "2001:2141::1/64"),
ra=[AdvPrefix("2001:1341::/64", valid_lifetime=86400, preferred_lifetime=14400),
AdvPrefix("2001:2141::/64")],
rdnss=[AdvRDNSS("2001:89ab::d", max_lifetime=25),
AdvRDNSS("2001:cdef::d", max_lifetime=25)])
lrdns = self.addLink(r, dns)
lrdns[r].addParams(ip=("2001:89ab::1/64", "2001:cdef::1/64")) # Static IP addresses
lrdns[dns].addParams(ip=("2001:89ab::d/64", "2001:cdef::d/64")) # Static IP addresses

super(MyTopology, self).build(*args, **kwargs)

Expand All @@ -331,13 +331,13 @@ of the interface. You can also give the name of the DNS server (instead of an IP
h = self.addHost('h')
dns = self.addHost('dns')

self.addLink(r, h, params1={
"ip": ("2001:1341::1/64", "2001:2141::1/64"), # Static IP address
"ra": [AdvConnectedPrefix(valid_lifetime=86400, preferred_lifetime=14400)],
"rdnss": [AdvRDNSS(dns, max_lifetime=25)]})
self.addLink(r, dns,
params1={"ip": ("2001:89ab::1/64", "2001:cdef::1/64")}, # Static IP address
params2={"ip": ("2001:89ab::d/64", "2001:cdef::d/64")}) # Static IP address
lrh = self.addLink(r, h)
lrh[r].addParams(ip=("2001:1341::1/64", "2001:2141::1/64"),
ra=[AdvConnectedPrefix(valid_lifetime=86400, preferred_lifetime=14400)],
rdnss=[AdvRDNSS(dns, max_lifetime=25)])
lrdns = self.addLink(r, dns)
lrdns[r].addParams(ip=("2001:89ab::1/64", "2001:cdef::1/64")) # Static IP addresses
lrdns[dns].addParams(ip=("2001:89ab::d/64", "2001:cdef::d/64")) # Static IP addresses

super(MyTopology, self).build(*args, **kwargs)

Expand Down
19 changes: 19 additions & 0 deletions ipmininet/examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ The following sections will detail the topologies.
- [GRETopo](#gretopo)
- [SSHd](#sshd)
- [RouterAdvNetwork](#routeradvnetwork)
- [SimpleOpenRNetwork](#simpleopenrnetwork)
- [StaticAddressNetwork](#staticaddressnetwork)
- [PartialStaticAddressNet](#partialstaticaddressnetwork)


## SimpleOSPFNetwork
Expand Down Expand Up @@ -157,3 +160,19 @@ isolate logs.
Use
[breeze](https://github.com/facebook/openr/blob/master/openr/docs/Breeze.md) to
investigate the routing state of OpenR.

## StaticAddressNetwork

_topo name_ : static_address_network
_args_ : n/a

This network has statically assigned addresses
instead of using the IPMininet auto-allocator.

## PartialStaticAddressNetwork

_topo name_ : partial_static_address_network
_args_ : n/a

This network has some statically assigned addresses
and the others are dynamically allocated.
6 changes: 5 additions & 1 deletion ipmininet/examples/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from .sshd import SSHTopo
from .router_adv_network import RouterAdvNet
from .simple_openr_network import SimpleOpenrNet
from .static_address_network import StaticAddressNet
from .partial_static_address_network import PartialStaticAddressNet


from mininet.log import lg, LEVELS
Expand All @@ -26,7 +28,9 @@
'gre': GRETopo,
'ssh': SSHTopo,
'router_adv_network': RouterAdvNet,
'simple_openr_network': SimpleOpenrNet}
'simple_openr_network': SimpleOpenrNet,
'static_address_network': StaticAddressNet,
'partial_static_address_network': PartialStaticAddressNet}

NET_ARGS = {'router_adv_network': {'use_v4': False,
'use_v6': True,
Expand Down
51 changes: 51 additions & 0 deletions ipmininet/examples/partial_static_address_network.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""This file contains a topology with statically assigned addresses on two of the LANs.
The remaining addresses will be dynamically allocated."""

from ipmininet.iptopo import IPTopo
from ipmininet.overlay import Subnet


class PartialStaticAddressNet(IPTopo):

def build(self, *args, **kwargs):
"""
+----+ +----+ +----+ +----+ +----+
| h1 +-------+ r1 +-------+ r2 +-------+ s2 +-------+ h3 |
+----+ +--+-+ +----+ +----+ +----+
|
| +----+ +----+
+---------+ s1 +-------+ h2 |
+--+-+ +----+
|
| +----+
+---------+ h4 |
+----+
"""
r1 = self.addRouter('r1')
r2 = self.addRouter('r2')

s1 = self.addSwitch('s1')
s2 = self.addSwitch('s2')

h1 = self.addHost('h1')
h2 = self.addHost('h2')
h3 = self.addHost('h3')
h4 = self.addHost('h4')

self.addLink(h1, r1)

self.addLink(r1, r2)

self.addLink(r1, s1)
self.addLink(s1, h2)
self.addLink(s1, h4)

lr2s2 = self.addLink(r2, s2)
lr2s2[r2].addParams(ip=("192.168.1.1/24", "fc00:1::1/64"))
ls2h3 = self.addLink(s2, h3)
ls2h3[h3].addParams(ip=("192.168.1.2/24", "fc00:1::2/64"))

self.addOverlay(Subnet(links=[(r1, r2)],
subnets=["192.168.0.0/24", "fc00::/64"]))

super(PartialStaticAddressNet, self).build(*args, **kwargs)
14 changes: 7 additions & 7 deletions ipmininet/examples/router_adv_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ def build(self, *args, **kwargs):
r.addDaemon(RADVD)
h = self.addHost('h')
dns = self.addHost('dns')
self.addLink(r, h, params1={
"ip": ("2001:1341::1/64", "2001:2141::1/64"),
"ra": [AdvConnectedPrefix()],
"rdnss": [AdvRDNSS(dns)]})
self.addLink(r, dns,
params1={"ip": ("2001:89ab::1/64", "2001:cdef::1/64")},
params2={"ip": ("2001:89ab::d/64", "2001:cdef::d/64")})
lrh = self.addLink(r, h)
lrh[r].addParams(ip=("2001:1341::1/64", "2001:2141::1/64"),
ra=[AdvConnectedPrefix()],
rdnss=[AdvRDNSS(dns)])
lrdns = self.addLink(r, dns)
lrdns[r].addParams(ip=("2001:89ab::1/64", "2001:cdef::1/64"))
lrdns[dns].addParams(ip=("2001:89ab::d/64", "2001:cdef::d/64"))

super(RouterAdvNet, self).build(*args, **kwargs)

Expand Down
58 changes: 58 additions & 0 deletions ipmininet/examples/static_address_network.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""This file contains a topology with statically assigned addresses"""

from ipmininet.iptopo import IPTopo
from ipmininet.overlay import Subnet


class StaticAddressNet(IPTopo):

def build(self, *args, **kwargs):
"""
+----+ +----+ +----+ +----+ +----+
| h1 +-------+ r1 +-------+ r2 +-------+ s2 +-------+ h3 |
+----+ +--+-+ +----+ +----+ +----+
|
| +----+ +----+
+---------+ s1 +-------+ h2 |
+--+-+ +----+
|
| +----+
+---------+ h4 |
+----+
"""
r1 = self.addRouter('r1')
r2 = self.addRouter('r2')

s1 = self.addSwitch('s1')
s2 = self.addSwitch('s2')

h1 = self.addHost('h1')
h2 = self.addHost('h2')
h3 = self.addHost('h3')
h4 = self.addHost('h4')

self.addLink(h1, r1)

self.addLink(r1, r2)

self.addLink(r1, s1)
self.addLink(s1, h2)
self.addLink(s1, h4)

# IP addresses can be set with interface parameters
lr2s2 = self.addLink(r2, s2)
lr2s2[r2].addParams(ip=("10.0.3.1/24", "2001:3c::1/64"))
ls2h3 = self.addLink(s2, h3)
ls2h3[h3].addParams(ip=("10.0.3.2/24", "2001:3c::2/64"))

# We can also declare the subnets on each LAN
# We can use nodes and/or links to specify the host and router interfaces
# requiring an address for each subnet
self.addOverlay(Subnet(nodes=[r1, h1],
subnets=["10.0.0.0/24", "2001:1a::/64"]))
self.addOverlay(Subnet(links=[(r1, r2)],
subnets=["10.1.0.0/24", "2001:12::/64"]))
self.addOverlay(Subnet(nodes=[r1, h2, h4],
subnets=["10.2.0.0/24", "2001:12b::/64"]))

super(StaticAddressNet, self).build(*args, **kwargs)
Loading