Commit 7906d070 authored by Martín Ferrari's avatar Martín Ferrari

Some more api

parent b14c2a3c
......@@ -18,23 +18,30 @@ class Node(object):
def __init__(self):
self.pid = 0
def add_if(self, mac_address = None, mtu = None):
return Interface()
return Interface(mac_address, mtu)
def add_route(self, prefix, prefix_len, nexthop = None, interface = None):
assert nexthop or interface
def add_default_route(self, nexthop, interface = None):
return self.add_route('0.0.0.0', 0, nexthop, interface)
def start_process(self, args):
return Process()
def run_process(self, args):
return ("", "")
def get_routes(self):
return set()
class Link(object):
def connect(self, iface):
pass
class Interface(object):
def __init__(self):
def __init__(self, mac_address = None, mtu = None):
self.name = None
self.mac_address = None
def add_v4_address(self, addr, prefix_len, broadcast = None):
self.mac_address = mac_address
self.mtu = mtu
def add_v4_address(self, address, prefix_len, broadcast = None):
pass
def add_v6_address(self, addr, prefix_len):
def add_v6_address(self, address, prefix_len):
pass
class Process(object):
......
......@@ -147,10 +147,11 @@ class TestInterfaces(unittest.TestCase):
def test_interface_addresses(self):
node0 = netns.Node()
if0 = node0.add_if()
if0.add_v4_address(addr = '10.0.0.1', prefix_len = 24,
if0.add_v4_address(address = '10.0.0.1', prefix_len = 24,
broadcast = '10.0.0.255')
if0.add_v4_address(addr = '10.0.2.1', prefix_len = 26)
if0.add_v6_address(addr = 'fe80::222:19ff:fe22:615d', prefix_len = 64)
if0.add_v4_address(address = '10.0.2.1', prefix_len = 26)
if0.add_v6_address(address = 'fe80::222:19ff:fe22:615d',
prefix_len = 64)
devs = get_devs_netns(node0)
self.assertTrue( {
......
......@@ -6,7 +6,16 @@ import unittest
class TestRouting(unittest.TestCase):
def test_routing(self):
pass
node = netns.Node()
if0 = node.add_if()
if0.add_v4_address('10.0.0.1', 24)
node.add_default_route(nexthop = '10.0.0.2')
node.add_route(prefix = '10.1.0.0', prefix_len = 16,
nexthop = '10.0.0.3')
node.add_route(prefix = '11.1.0.1', prefix_len = 32, interface = if0)
routes = node.get_routes()
# FIXME:...
if __name__ == '__main__':
unittest.main()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment