1 # Copyright 2016 Cisco Systems, Inc. All rights reserved.
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
4 # not use this file except in compliance with the License. You may obtain
5 # a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
17 class Interface(object):
19 def __init__(self, name, device, tx_packets, rx_packets):
27 def set_packets(self, tx, rx):
33 def set_packets_diff(self, tx, rx):
35 'tx': tx - self.packets['tx'],
36 'rx': rx - self.packets['rx'],
40 return self.name is None
42 def get_packet_count(self, traffic_type):
43 return self.packets.get(traffic_type, 0)
47 return Interface(None, None, 0, 0)
50 class Network(object):
52 def __init__(self, interfaces=None, reverse=False):
53 if interfaces is None:
55 self.interfaces = interfaces
56 self.reverse = reverse
58 def add_interface(self, interface):
59 self.interfaces.append(interface)
61 def get_interfaces(self):
62 return self.interfaces[::-1] if self.reverse else self.interfaces