# acknowledge the contributions of their colleagues of the SONATA
# partner consortium (www.sonata-nfv.eu).
import logging
-
import time
-from subprocess import Popen
import re
import requests
import os
import json
-
+import networkx as nx
+from subprocess import Popen
+# from gevent import monkey
from mininet.net import Containernet
from mininet.node import OVSSwitch, OVSKernelSwitch, Docker, RemoteController
from mininet.cli import CLI
from mininet.link import TCLink
from mininet.clean import cleanup
-import networkx as nx
from emuvim.dcemulator.monitoring import DCNetworkMonitor
from emuvim.dcemulator.node import Datacenter, EmulatorCompute
from emuvim.dcemulator.resourcemodel import ResourceModelRegistrar
+# ensure correct functionality of all gevent based REST servers
+# monkey.patch_all()
+
+# setup logging
LOG = logging.getLogger("dcemulator.net")
LOG.setLevel(logging.DEBUG)
switch_node = self.getNodeByName(src_sw)
self._set_vlan_tag(switch_node, src_sw_inport_name, vlan)
+ def getNodeByName(self, name):
+ """
+ Wraps Containernet's getNodeByName method to avoid
+ key not found exceptions.
+ """
+ try:
+ return super(DCNetwork, self).getNodeByName(name)
+ except BaseException as ex:
+ LOG.warning("Node not found: {}".format(name))
+ LOG.debug("Node not found: {}".format(ex))
+ return None
+
def _addMonitorFlow(self, vnf_src_name, vnf_dst_name, vnf_src_interface=None, vnf_dst_interface=None,
tag=None, **kwargs):
"""
cmd = kwargs.get('cmd')
path = kwargs.get('path')
index = kwargs.get('pathindex')
+ mod_dl_dst = kwargs.get('mod_dl_dst')
vlan = kwargs.get('vlan')
priority = kwargs.get('priority', DEFAULT_PRIORITY)
else: # middle nodes
match += ',dl_vlan=%s' % vlan
+ if mod_dl_dst:
+ action = {}
+ action['type'] = 'SET_FIELD'
+ action['field'] = 'eth_dst'
+ action['value'] = mod_dl_dst
+ flow['actions'].append(action)
# output action must come last
action = {}
:return:
"""
# try it nicely
- if self.ryu_process is not None:
- self.ryu_process.terminate()
- self.ryu_process.kill()
+ try:
+ if self.ryu_process is not None:
+ self.ryu_process.terminate()
+ self.ryu_process.kill()
+ except BaseException as ex:
+ LOG.warning("Error during Ryu stop: {}".format(ex))
# ensure its death ;-)
Popen(['pkill', '-f', 'ryu-manager'])
url = self.ryu_REST_api + '/' + str(prefix) + '/' + str(dpid)
else:
url = self.ryu_REST_api + '/' + str(prefix)
+
+ LOG.debug('sending RYU command: %s, payload: %s', url, data)
if data:
req = self.RyuSession.post(url, json=data)
else:
# do extra logging if status code is not 200 (OK)
if req.status_code is not requests.codes.ok:
- logging.info(
+ LOG.info(
'type {0} encoding: {1} text: {2} headers: {3} history: {4}'.format(req.headers['content-type'],
req.encoding, req.text,
req.headers, req.history))