diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/component_factory.py | 10 | ||||
-rwxr-xr-x | core/loader/loader.py | 40 | ||||
-rw-r--r-- | core/pktfwd_controller.py | 68 |
3 files changed, 116 insertions, 2 deletions
diff --git a/core/component_factory.py b/core/component_factory.py index 21cdd61d..af237e50 100644 --- a/core/component_factory.py +++ b/core/component_factory.py @@ -20,6 +20,7 @@ from core.vswitch_controller_p2p import VswitchControllerP2P from core.vswitch_controller_pvp import VswitchControllerPVP from core.vswitch_controller_pvvp import VswitchControllerPVVP from core.vnf_controller import VnfController +from core.pktfwd_controller import PktFwdController from tools.load_gen.stress.stress import Stress from tools.load_gen.stress_ng.stress_ng import StressNg from tools.load_gen.dummy.dummy import DummyLoadGen @@ -108,4 +109,13 @@ def create_loadgen(loadgen_type, loadgen_cfg): elif loadgen_type.find("stress") >= 0: return Stress(loadgen_cfg) +def create_pktfwd(pktfwd_class): + """Return a new packet forwarder controller + The returned controller is configured with the given + packet forwarder class. + + :param pktfwd_class: Reference to packet forwarder class to be used. + :return: packet forwarder controller + """ + return PktFwdController(pktfwd_class) diff --git a/core/loader/loader.py b/core/loader/loader.py index 39b50f09..0d9c83a6 100755 --- a/core/loader/loader.py +++ b/core/loader/loader.py @@ -21,6 +21,7 @@ from tools.pkt_gen.trafficgen import ITrafficGenerator from tools.collectors.collector import ICollector from vswitches.vswitch import IVSwitch from vnfs.vnf.vnf import IVnf +from tools.pkt_fwd.pkt_fwd import IPktFwd class Loader(object): """Loader class - main object context holder. @@ -57,6 +58,11 @@ class Loader(object): settings.getValue('VNF'), IVnf) + self._pktfwd_loader = LoaderServant( + settings.getValue('PKTFWD_DIR'), + settings.getValue('PKTFWD'), + IPktFwd) + def get_trafficgen(self): """Returns a new instance configured traffic generator. @@ -109,7 +115,7 @@ class Loader(object): :return: Dictionary of collectors. - key: name of the class which implements ICollector, - - value: Type of traffic generator which implements ICollector. + - value: Type of collector which implements ICollector. """ return self._metrics_loader.get_classes() @@ -140,7 +146,7 @@ class Loader(object): :return: Dictionary of vswitches. - key: name of the class which implements IVSwitch, - - value: Type of traffic generator which implements IVSwitch. + - value: Type of vswitch which implements IVSwitch. """ return self._vswitch_loader.get_classes() @@ -182,3 +188,33 @@ class Loader(object): """ return self._vnf_loader.get_classes_printable() + def get_pktfwd(self): + """Returns instance of currently configured packet forwarder implementation. + + :return: IPktFwd implementation if available, None otherwise. + """ + return self._pktfwd_loader.get_class()() + + def get_pktfwd_class(self): + """Returns type of currently configured packet forwarder implementation. + + :return: Type of IPktFwd implementation if available. + None otherwise. + """ + return self._pktfwd_loader.get_class() + + def get_pktfwds(self): + """Returns dictionary of all available packet forwarders. + + :return: Dictionary of packet forwarders. + - key: name of the class which implements IPktFwd, + - value: Type of packet forwarder which implements IPktFwd. + """ + return self._pktfwd_loader.get_classes() + + def get_pktfwds_printable(self): + """Returns all available packet forwarders in printable format. + + :return: String containing printable list of packet forwarders. + """ + return self._pktfwd_loader.get_classes_printable() diff --git a/core/pktfwd_controller.py b/core/pktfwd_controller.py new file mode 100644 index 00000000..4f300ce8 --- /dev/null +++ b/core/pktfwd_controller.py @@ -0,0 +1,68 @@ +# Copyright 2016 Intel Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Packet forwarder controller for Physical to Physical deployment +""" + +import logging + +from conf import settings + + +class PktFwdController(object): + """Packet forwarder controller for P2P deployment scenario. + + Attributes: + _pktfwd_class: The packet forwarder class to be used. + _pktfwd: The packet forwarder object controlled by this controller + """ + def __init__(self, pktfwd_class): + """Initializes up the prerequisites for the P2P deployment scenario. + + :vswitch_class: the vSwitch class to be used. + """ + self._logger = logging.getLogger(__name__) + self._pktfwd_class = pktfwd_class + self._pktfwd = pktfwd_class() + self._logger.debug('Creation using ' + str(self._pktfwd_class)) + + def setup(self): + """Sets up the packet forwarder for p2p. + """ + self._logger.debug('Setup using ' + str(self._pktfwd_class)) + + try: + self._pktfwd.start() + except: + self._pktfwd.stop() + raise + + def stop(self): + """Tears down the packet forwarder created in setup(). + """ + self._logger.debug('Stop using ' + str(self._pktfwd_class)) + self._pktfwd.stop() + + def __enter__(self): + self.setup() + + def __exit__(self, type_, value, traceback): + self.stop() + + def get_pktfwd(self): + """Get the controlled packet forwarder + + :return: The controlled IPktFwd + """ + return self._pktfwd |