diff options
author | Marcel Enguehard <mengueha+fdio@cisco.com> | 2017-07-19 11:26:26 +0200 |
---|---|---|
committer | Marcel Enguehard <mengueha+fdio@cisco.com> | 2017-07-19 11:51:26 +0000 |
commit | 3e6678f9c692553e8902da4d6fb1fe6c087db1f4 (patch) | |
tree | 580a46ca5de22a044319eabb295ad980d50589ec /netmodel/interfaces/process/__init__.py | |
parent | 08c4f765cf29dbd6e9a616c542552417eece14fc (diff) |
* GUI resource
* MemIf interface for VPP
* Better netmodel integration
* Draft documentation
* New tutorials
* Improved monitoring and error handling
* Refactored IP addresses and prefixes representation
* Improved image mgmt for LXD
* Various bugfixes and code refactoring
Change-Id: I90da6cf7b5716bc7deb6bf4e24d3f9f01b5a9b0f
Signed-off-by: Marcel Enguehard <mengueha+fdio@cisco.com>
Diffstat (limited to 'netmodel/interfaces/process/__init__.py')
-rw-r--r-- | netmodel/interfaces/process/__init__.py | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/netmodel/interfaces/process/__init__.py b/netmodel/interfaces/process/__init__.py index b985c32f..59bf6f9f 100644 --- a/netmodel/interfaces/process/__init__.py +++ b/netmodel/interfaces/process/__init__.py @@ -16,6 +16,7 @@ # limitations under the License. # +import logging import shlex import socket import subprocess @@ -27,10 +28,13 @@ from netmodel.network.prefix import Prefix from netmodel.model.attribute import Attribute from netmodel.model.filter import Filter from netmodel.model.object import Object -from netmodel.model.query import Query, ACTION_UPDATE -from netmodel.model.query import ACTION_SUBSCRIBE, FUNCTION_SUM +from netmodel.model.query import Query, ACTION_UPDATE, ACTION2STR +from netmodel.model.query import ACTION_SUBSCRIBE, ACTION_UNSUBSCRIBE +from netmodel.model.query import FUNCTION_SUM from netmodel.model.type import String, Integer, Double +log = logging.getLogger(__name__) + DEFAULT_INTERVAL = 1 # s KEY_FIELD = 'device_name' @@ -48,19 +52,19 @@ class Process(threading.Thread): class BWMThread(Process): SEP=';' - CMD="stdbuf -oL bwm-ng -t 1000 -N -o csv -c 0 -C '%s'" + CMD="stdbuf -oL bwm-ng -t 1000 -N -o csv -c 0 -C '%s'" # Parsing information (from README, specs section) # https://github.com/jgjl/bwm-ng/blob/master/README # # Type rate: - FIELDS_RATE = ['timestamp', 'iface_name', 'bytes_out_s', 'bytes_in_s', + FIELDS_RATE = ['timestamp', 'iface_name', 'bytes_out_s', 'bytes_in_s', 'bytes_total_s', 'bytes_in', 'bytes_out', 'packets_out_s', 'packets_in_s', 'packets_total_s', 'packets_in', 'packets_out', 'errors_out_s', 'errors_in_s', 'errors_in', 'errors_out'] # Type svg, sum, max - FIELDS_SUM = ['timestamp', 'iface_name', 'bytes_out', 'bytes_in', - 'bytes_total', 'packets_out', 'packets_in', 'packets_total', + FIELDS_SUM = ['timestamp', 'iface_name', 'bytes_out', 'bytes_in', + 'bytes_total', 'packets_out', 'packets_in', 'packets_total', 'errors_out', 'errors_in'] def __init__(self, interfaces, callback): @@ -74,7 +78,7 @@ class BWMThread(Process): def run(self): cmd = self.CMD % (self.SEP) - p = subprocess.Popen(shlex.split(cmd), stdout = subprocess.PIPE, + p = subprocess.Popen(shlex.split(cmd), stdout = subprocess.PIPE, stderr = subprocess.STDOUT) stdout = [] self._is_running = True @@ -85,18 +89,18 @@ class BWMThread(Process): break if line: record = self._parse_line(line.strip()) - # We use 'total' to push the statistics back to VICN + # We use 'total' to push the statistics back to VICN if record['iface_name'] == 'total': for interfaces in self.groups_of_interfaces: if not len(interfaces) > 1: # If the tuple contains only one interface, grab # the information from bwm_stats and sends it back - # to VICN + # to VICN if interfaces[0] not in self.bwm_stats: continue interface = self.bwm_stats[interfaces[0]] f_list = [[KEY_FIELD, '==', interface.device_name]] - query = Query(ACTION_UPDATE, Interface.__type__, + query = Query(ACTION_UPDATE, Interface.__type__, filter = Filter.from_list(f_list), params = interface.get_attribute_dict()) self._callback(query) @@ -133,7 +137,7 @@ class BWMThread(Process): # sum function specified because it is used to # match the subscribe query attrs = aggregated_interface.get_attribute_dict() - query = Query(ACTION_UPDATE, Interface.__type__, + query = Query(ACTION_UPDATE, Interface.__type__, filter = Filter.from_list([predicate]), params = attrs, aggregate = FUNCTION_SUM) @@ -148,7 +152,7 @@ class BWMThread(Process): bw_upstream = float(record['bytes_out_s']), bw_downstream = float(record['bytes_in_s']), ) - + self.bwm_stats[record['iface_name']] = interface rc = p.poll() @@ -176,17 +180,17 @@ class BWMInterface(BaseInterface): packet = Packet.from_query(reply, reply = True) self.receive(packet) - #-------------------------------------------------------------------------- + #-------------------------------------------------------------------------- # Router interface - #-------------------------------------------------------------------------- + #-------------------------------------------------------------------------- def send_impl(self, packet): query = packet.to_query() - assert query.action == ACTION_SUBSCRIBE - interval = query.params.get('interval', DEFAULT_INTERVAL) \ - if query.params else DEFAULT_INTERVAL - assert interval + if query.action not in [ACTION_SUBSCRIBE]: # , ACTION_UNSUBSCRIBE]: + log.warning("Ignore unknown action {}".format( + ACTION2STR[query.action])) + return # TODO: Add the sum operator. If sum the list of interfaces is # added to the BWMThread as a tuple, otherwise every single @@ -194,15 +198,18 @@ class BWMInterface(BaseInterface): # We currently simply extract it from the filter interfaces_list = [p.value for p in query.filter if p.key == KEY_FIELD] - + # interfaces is a list of tuple. If someone sbscribe to mulitple # interfaces interfaces will be a list of 1 tuple. The tuple will # contain the set of interfaces - assert len(interfaces_list) == 1 + if len(interfaces_list) != 1: + log.warning("interfaces_list should have len = 1: {}".format(interfaces_list)) + return + interfaces = interfaces_list[0] \ if isinstance(interfaces_list[0], tuple) \ else tuple([interfaces_list[0]]) - + # Check if interfaces is more than one. In this case, we only support # The SUM function on the list of field. if len(interfaces) > 1: |