updates to clear broker from physical node

This commit is contained in:
Blake Harnden 2019-10-16 17:11:21 -07:00
parent 61a4e228a1
commit 8aef9f273f
3 changed files with 48 additions and 46 deletions

View file

@ -153,7 +153,7 @@ class Session(object):
self.services.default_services = { self.services.default_services = {
"mdr": ("zebra", "OSPFv3MDR", "IPForward"), "mdr": ("zebra", "OSPFv3MDR", "IPForward"),
"PC": ("DefaultRoute",), "PC": ("DefaultRoute",),
"prouter": ("zebra", "OSPFv2", "OSPFv3", "IPForward"), "prouter": (),
"router": ("zebra", "OSPFv2", "OSPFv3", "IPForward"), "router": ("zebra", "OSPFv2", "OSPFv3", "IPForward"),
"host": ("DefaultRoute", "SSH"), "host": ("DefaultRoute", "SSH"),
} }
@ -192,32 +192,33 @@ class Session(object):
for name in self.servers: for name in self.servers:
server = self.servers[name] server = self.servers[name]
host = server.host self.create_gre_tunnel(node, server)
key = self.tunnelkey(node_id, IpAddress.to_int(host))
# local to server def create_gre_tunnel(self, node, server):
logging.info( host = server.host
"local tunnel node(%s) to remote(%s) key(%s)", node.name, host, key key = self.tunnelkey(node.id, IpAddress.to_int(host))
) tunnel = self.tunnels.get(key)
local_tap = GreTap(session=self, remoteip=host, key=key) if tunnel is not None:
local_tap.net_client.create_interface(node.brname, local_tap.localname) return tunnel
# server to local # local to server
logging.info( logging.info(
"remote tunnel node(%s) to local(%s) key(%s)", "local tunnel node(%s) to remote(%s) key(%s)", node.name, host, key
node.name, )
self.address, local_tap = GreTap(session=self, remoteip=host, key=key)
key, local_tap.net_client.create_interface(node.brname, local_tap.localname)
)
remote_tap = GreTap(
session=self, remoteip=self.address, key=key, server=server
)
remote_tap.net_client.create_interface(
node.brname, remote_tap.localname
)
# save tunnels for shutdown # server to local
self.tunnels[key] = (local_tap, remote_tap) logging.info(
"remote tunnel node(%s) to local(%s) key(%s)", node.name, self.address, key
)
remote_tap = GreTap(session=self, remoteip=self.address, key=key, server=server)
remote_tap.net_client.create_interface(node.brname, remote_tap.localname)
# save tunnels for shutdown
tunnel = (local_tap, remote_tap)
self.tunnels[key] = tunnel
return tunnel
def tunnelkey(self, n1_id, n2_id): def tunnelkey(self, n1_id, n2_id):
""" """

View file

@ -9,15 +9,19 @@ import threading
from core import utils from core import utils
from core.constants import MOUNT_BIN, UMOUNT_BIN from core.constants import MOUNT_BIN, UMOUNT_BIN
from core.emulator.enumerations import NodeTypes from core.emulator.enumerations import NodeTypes
from core.errors import CoreCommandError from core.errors import CoreCommandError, CoreError
from core.nodes.base import CoreNodeBase from core.nodes.base import CoreNodeBase
from core.nodes.interface import CoreInterface from core.nodes.interface import CoreInterface
from core.nodes.network import CoreNetwork, GreTap from core.nodes.network import CoreNetwork, GreTap
class PhysicalNode(CoreNodeBase): class PhysicalNode(CoreNodeBase):
def __init__(self, session, _id=None, name=None, nodedir=None, start=True): def __init__(
CoreNodeBase.__init__(self, session, _id, name, start=start) self, session, _id=None, name=None, nodedir=None, start=True, server=None
):
CoreNodeBase.__init__(self, session, _id, name, start, server)
if not self.server:
raise CoreError("physical nodes must be assigned to a remote server")
self.nodedir = nodedir self.nodedir = nodedir
self.up = start self.up = start
self.lock = threading.RLock() self.lock = threading.RLock()
@ -86,7 +90,6 @@ class PhysicalNode(CoreNodeBase):
def adoptnetif(self, netif, ifindex, hwaddr, addrlist): def adoptnetif(self, netif, ifindex, hwaddr, addrlist):
""" """
The broker builds a GreTap tunnel device to this physical node.
When a link message is received linking this node to another part of When a link message is received linking this node to another part of
the emulation, no new interface is created; instead, adopt the the emulation, no new interface is created; instead, adopt the
GreTap netif as the node interface. GreTap netif as the node interface.
@ -157,26 +160,21 @@ class PhysicalNode(CoreNodeBase):
if ifindex is None: if ifindex is None:
ifindex = self.newifindex() ifindex = self.newifindex()
if self.up:
# this is reached when this node is linked to a network node
# tunnel to net not built yet, so build it now and adopt it
gt = self.session.broker.addnettunnel(net.id)
if gt is None or len(gt) != 1:
raise ValueError(
"error building tunnel from adding a new network interface: %s" % gt
)
gt = gt[0]
net.detach(gt)
self.adoptnetif(gt, ifindex, hwaddr, addrlist)
return ifindex
# this is reached when configuring services (self.up=False)
if ifname is None: if ifname is None:
ifname = "gt%d" % ifindex ifname = "gt%d" % ifindex
netif = GreTap(node=self, name=ifname, session=self.session, start=False) if self.up:
self.adoptnetif(netif, ifindex, hwaddr, addrlist) # this is reached when this node is linked to a network node
return ifindex # tunnel to net not built yet, so build it now and adopt it
_, remote_tap = self.session.create_gre_tunnel(net, self.server)
# net.detach(remote_tap)
self.adoptnetif(remote_tap, ifindex, hwaddr, addrlist)
return ifindex
else:
# this is reached when configuring services (self.up=False)
netif = GreTap(node=self, name=ifname, session=self.session, start=False)
self.adoptnetif(netif, ifindex, hwaddr, addrlist)
return ifindex
def privatedir(self, path): def privatedir(self, path):
if path[0] != "/": if path[0] != "/":
@ -223,6 +221,9 @@ class PhysicalNode(CoreNodeBase):
os.chmod(node_file.name, mode) os.chmod(node_file.name, mode)
logging.info("created nodefile: '%s'; mode: 0%o", node_file.name, mode) logging.info("created nodefile: '%s'; mode: 0%o", node_file.name, mode)
def node_net_cmd(self, args, wait=True):
return self.net_cmd(args, wait=wait)
class Rj45Node(CoreNodeBase, CoreInterface): class Rj45Node(CoreNodeBase, CoreInterface):
""" """

View file

@ -19,7 +19,7 @@ array set g_node_types_default {
4 {mdr mdr.gif mdr.gif {zebra OSPFv3MDR IPForward} \ 4 {mdr mdr.gif mdr.gif {zebra OSPFv3MDR IPForward} \
netns {built-in type for wireless routers}} netns {built-in type for wireless routers}}
5 {prouter router_green.gif router_green.gif \ 5 {prouter router_green.gif router_green.gif \
{zebra OSPFv2 OSPFv3 IPForward} \ {} \
physical {built-in type for physical nodes}} physical {built-in type for physical nodes}}
} }