From 463618ddf873047a15e61bc64fbd188fe2d0409c Mon Sep 17 00:00:00 2001 From: "Blake J. Harnden" Date: Wed, 9 Aug 2017 10:03:43 -0700 Subject: [PATCH] small refactoring on how node maps are used, added logic to switch to using a map based on bsd nodes using previous logic --- daemon/core/bsd/nodes.py | 12 ++++++++++ daemon/core/misc/nodemaps.py | 22 +------------------ daemon/core/netns/openvswitch.py | 11 ++++++++++ daemon/examples/netns/basicrange.py | 2 +- daemon/examples/netns/daemonnodes.py | 2 +- daemon/examples/netns/distributed.py | 2 +- daemon/examples/netns/emane80211.py | 2 +- daemon/examples/netns/howmanynodes.py | 2 +- .../examples/netns/iperf-performance-chain.py | 2 +- daemon/examples/netns/ospfmanetmdrtest.py | 2 +- daemon/examples/netns/switch.py | 2 +- daemon/examples/netns/switchtest.py | 2 +- daemon/examples/netns/wlanemanetests.py | 2 +- daemon/examples/netns/wlantest.py | 2 +- daemon/sbin/core-daemon | 11 ++++++++-- daemon/tests/conftest.py | 4 ++-- 16 files changed, 46 insertions(+), 36 deletions(-) diff --git a/daemon/core/bsd/nodes.py b/daemon/core/bsd/nodes.py index 68e825eb..8978ba4e 100644 --- a/daemon/core/bsd/nodes.py +++ b/daemon/core/bsd/nodes.py @@ -206,3 +206,15 @@ class TunnelNode(NetgraphNet): nghooks = "upper lower" apitype = NodeTypes.TUNNEL.value policy = "ACCEPT" + + +BSD_NODES = { + NodeTypes.DEFAULT: CoreNode, + NodeTypes.SWITCH: SwitchNode, + NodeTypes.HUB: HubNode, + NodeTypes.WIRELESS_LAN: WlanNode, + NodeTypes.RJ45: RJ45Node, + NodeTypes.TUNNEL: TunnelNode, + NodeTypes.PEER_TO_PEER: PtpNet, + NodeTypes.CONTROL_NET: None +} diff --git a/daemon/core/misc/nodemaps.py b/daemon/core/misc/nodemaps.py index 72249aee..dfb9ad91 100644 --- a/daemon/core/misc/nodemaps.py +++ b/daemon/core/misc/nodemaps.py @@ -6,13 +6,12 @@ from core.emane.nodes import EmaneNet from core.emane.nodes import EmaneNode from core.enumerations import NodeTypes from core.netns import nodes -from core.netns import openvswitch from core.netns.vnet import GreTapBridge from core.phys import pnodes from core.xen import xen # legacy core nodes, that leverage linux bridges -CLASSIC_NODES = { +NODES = { NodeTypes.DEFAULT: nodes.CoreNode, NodeTypes.PHYSICAL: pnodes.PhysicalNode, NodeTypes.XEN: xen.XenNode, @@ -29,22 +28,3 @@ CLASSIC_NODES = { NodeTypes.PEER_TO_PEER: nodes.PtpNet, NodeTypes.CONTROL_NET: nodes.CtrlNet } - -# ovs nodes, that depend on ovs to leverage ovs based bridges -OVS_NODES = { - NodeTypes.DEFAULT: nodes.CoreNode, - NodeTypes.PHYSICAL: pnodes.PhysicalNode, - NodeTypes.XEN: xen.XenNode, - NodeTypes.TBD: None, - NodeTypes.SWITCH: openvswitch.OvsSwitchNode, - NodeTypes.HUB: openvswitch.OvsHubNode, - NodeTypes.WIRELESS_LAN: openvswitch.OvsWlanNode, - NodeTypes.RJ45: nodes.RJ45Node, - NodeTypes.TUNNEL: openvswitch.OvsTunnelNode, - NodeTypes.KTUNNEL: None, - NodeTypes.EMANE: EmaneNode, - NodeTypes.EMANE_NET: EmaneNet, - NodeTypes.TAP_BRIDGE: openvswitch.OvsGreTapBridge, - NodeTypes.PEER_TO_PEER: openvswitch.OvsPtpNet, - NodeTypes.CONTROL_NET: openvswitch.OvsCtrlNet -} diff --git a/daemon/core/netns/openvswitch.py b/daemon/core/netns/openvswitch.py index 36fa0d01..4ff2cc77 100644 --- a/daemon/core/netns/openvswitch.py +++ b/daemon/core/netns/openvswitch.py @@ -737,3 +737,14 @@ class OvsGreTapBridge(OvsNet): prior to instantiating the GreTap device (before addrconfig). """ self.grekey = key + + +OVS_NODES = { + NodeTypes.SWITCH: OvsSwitchNode, + NodeTypes.HUB: OvsHubNode, + NodeTypes.WIRELESS_LAN: OvsWlanNode, + NodeTypes.TUNNEL: OvsTunnelNode, + NodeTypes.TAP_BRIDGE: OvsGreTapBridge, + NodeTypes.PEER_TO_PEER: OvsPtpNet, + NodeTypes.CONTROL_NET: OvsCtrlNet +} diff --git a/daemon/examples/netns/basicrange.py b/daemon/examples/netns/basicrange.py index d8fdd869..ecf6db28 100755 --- a/daemon/examples/netns/basicrange.py +++ b/daemon/examples/netns/basicrange.py @@ -109,7 +109,7 @@ def main(): if __name__ == "__main__": # configure nodes to use - node_map = nodemaps.CLASSIC_NODES + node_map = nodemaps.NODES nodeutils.set_node_map(node_map) main() diff --git a/daemon/examples/netns/daemonnodes.py b/daemon/examples/netns/daemonnodes.py index 0f9399bd..daad6c2d 100755 --- a/daemon/examples/netns/daemonnodes.py +++ b/daemon/examples/netns/daemonnodes.py @@ -188,7 +188,7 @@ def main(): if __name__ == "__main__" or __name__ == "__builtin__": # configure nodes to use - node_map = nodemaps.CLASSIC_NODES + node_map = nodemaps.NODES nodeutils.set_node_map(node_map) main() diff --git a/daemon/examples/netns/distributed.py b/daemon/examples/netns/distributed.py index 81d49afa..b8e392f0 100755 --- a/daemon/examples/netns/distributed.py +++ b/daemon/examples/netns/distributed.py @@ -125,7 +125,7 @@ def main(): if __name__ == "__main__" or __name__ == "__builtin__": # configure nodes to use - node_map = nodemaps.CLASSIC_NODES + node_map = nodemaps.NODES nodeutils.set_node_map(node_map) main() diff --git a/daemon/examples/netns/emane80211.py b/daemon/examples/netns/emane80211.py index 857b577d..4dae69d0 100755 --- a/daemon/examples/netns/emane80211.py +++ b/daemon/examples/netns/emane80211.py @@ -101,7 +101,7 @@ def main(): if __name__ == "__main__" or __name__ == "__builtin__": # configure nodes to use - node_map = nodemaps.CLASSIC_NODES + node_map = nodemaps.NODES nodeutils.set_node_map(node_map) main() diff --git a/daemon/examples/netns/howmanynodes.py b/daemon/examples/netns/howmanynodes.py index 90f8b727..3387af6d 100755 --- a/daemon/examples/netns/howmanynodes.py +++ b/daemon/examples/netns/howmanynodes.py @@ -207,7 +207,7 @@ def main(): if __name__ == "__main__": # configure nodes to use - node_map = nodemaps.CLASSIC_NODES + node_map = nodemaps.NODES nodeutils.set_node_map(node_map) main() diff --git a/daemon/examples/netns/iperf-performance-chain.py b/daemon/examples/netns/iperf-performance-chain.py index d2ac98ba..cd9081a1 100755 --- a/daemon/examples/netns/iperf-performance-chain.py +++ b/daemon/examples/netns/iperf-performance-chain.py @@ -101,7 +101,7 @@ def main(): if __name__ == "__main__" or __name__ == "__builtin__": # configure nodes to use - node_map = nodemaps.CLASSIC_NODES + node_map = nodemaps.NODES nodeutils.set_node_map(node_map) main() diff --git a/daemon/examples/netns/ospfmanetmdrtest.py b/daemon/examples/netns/ospfmanetmdrtest.py index 97391cc3..3a6c8b8b 100755 --- a/daemon/examples/netns/ospfmanetmdrtest.py +++ b/daemon/examples/netns/ospfmanetmdrtest.py @@ -603,7 +603,7 @@ def main(): if __name__ == "__main__": # configure nodes to use - node_map = nodemaps.CLASSIC_NODES + node_map = nodemaps.NODES nodeutils.set_node_map(node_map) me = main() diff --git a/daemon/examples/netns/switch.py b/daemon/examples/netns/switch.py index 30fefc52..97d517e3 100755 --- a/daemon/examples/netns/switch.py +++ b/daemon/examples/netns/switch.py @@ -74,7 +74,7 @@ def main(): if __name__ == "__main__" or __name__ == "__builtin__": # configure nodes to use - node_map = nodemaps.CLASSIC_NODES + node_map = nodemaps.NODES nodeutils.set_node_map(node_map) main() diff --git a/daemon/examples/netns/switchtest.py b/daemon/examples/netns/switchtest.py index dcfac37c..c33ac09f 100755 --- a/daemon/examples/netns/switchtest.py +++ b/daemon/examples/netns/switchtest.py @@ -102,7 +102,7 @@ def main(): if __name__ == "__main__": # configure nodes to use - node_map = nodemaps.CLASSIC_NODES + node_map = nodemaps.NODES nodeutils.set_node_map(node_map) main() diff --git a/daemon/examples/netns/wlanemanetests.py b/daemon/examples/netns/wlanemanetests.py index 3db769ad..2f4b29d8 100755 --- a/daemon/examples/netns/wlanemanetests.py +++ b/daemon/examples/netns/wlanemanetests.py @@ -852,7 +852,7 @@ def main(): if __name__ == "__main__": # configure nodes to use - node_map = nodemaps.CLASSIC_NODES + node_map = nodemaps.NODES nodeutils.set_node_map(node_map) main() diff --git a/daemon/examples/netns/wlantest.py b/daemon/examples/netns/wlantest.py index f4d46519..fc046fdb 100755 --- a/daemon/examples/netns/wlantest.py +++ b/daemon/examples/netns/wlantest.py @@ -100,7 +100,7 @@ def main(): if __name__ == "__main__": # configure nodes to use - node_map = nodemaps.CLASSIC_NODES + node_map = nodemaps.NODES nodeutils.set_node_map(node_map) main() diff --git a/daemon/sbin/core-daemon b/daemon/sbin/core-daemon index 78a4cc57..59fbb861 100755 --- a/daemon/sbin/core-daemon +++ b/daemon/sbin/core-daemon @@ -336,9 +336,16 @@ def main(): if __name__ == "__main__": # configure nodes to use - node_map = nodemaps.CLASSIC_NODES + node_map = nodemaps.NODES if len(sys.argv) == 2 and sys.argv[1] == "ovs": - node_map = nodemaps.OVS_NODES + from core.netns.openvswitch import OVS_NODES + node_map.update(OVS_NODES) + + # update with BSD based nodes + if os.uname()[0] == "FreeBSD": + from core.bsd.nodes import BSD_NODES + node_map.update(BSD_NODES) + nodeutils.set_node_map(node_map) # load default services diff --git a/daemon/tests/conftest.py b/daemon/tests/conftest.py index f18e279a..878fb47a 100644 --- a/daemon/tests/conftest.py +++ b/daemon/tests/conftest.py @@ -245,7 +245,7 @@ class Core(object): class CoreServerTest(object): def __init__(self): # setup nodes - node_map = nodemaps.CLASSIC_NODES + node_map = nodemaps.NODES nodeutils.set_node_map(node_map) # load emane services @@ -321,7 +321,7 @@ class CoreServerTest(object): @pytest.fixture() def session(): # configure default nodes - node_map = nodemaps.CLASSIC_NODES + node_map = nodemaps.NODES nodeutils.set_node_map(node_map) # create and return session