diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 6e4aa79..f91a6bd 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -12,7 +12,7 @@ updates: commit-message: prefix: "[deps] " - package-ecosystem: "github-actions" # Check for GitHub Actions updates - directory: "/" + directory: "/" schedule: interval: "monthly" # Check for updates weekly commit-message: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a47c63b..4290280 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,6 @@ on: - gsoc23 jobs: - build: name: Python==${{ matrix.python-version }} runs-on: ubuntu-22.04 @@ -26,42 +25,42 @@ jobs: - "3.13" steps: - - uses: actions/checkout@v4 - with: - ref: ${{ github.event.pull_request.head.sha }} + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - cache: 'pip' - cache-dependency-path: | - **/requirements*.txt + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + cache: "pip" + cache-dependency-path: | + **/requirements*.txt - - name: Install Dependencies - id: deps - run: | - pip install -U pip wheel setuptools - pip install -U -r requirements-test.txt - pip install -U -e . + - name: Install Dependencies + id: deps + run: | + pip install -U pip wheel setuptools + pip install -U -r requirements-test.txt + pip install -U -e . - - name: QA checks - run: ./run-qa-checks + - name: QA checks + run: ./run-qa-checks - - name: Tests - if: ${{ !cancelled() && steps.deps.conclusion == 'success' }} - run: | - coverage run runtests.py - coverage xml + - name: Tests + if: ${{ !cancelled() && steps.deps.conclusion == 'success' }} + run: | + coverage run runtests.py + coverage xml - - name: Upload Coverage - if: ${{ success() }} - uses: coverallsapp/github-action@v2 - with: - parallel: true - format: cobertura - flag-name: python-${{ matrix.env.env }} - github-token: ${{ secrets.GITHUB_TOKEN }} + - name: Upload Coverage + if: ${{ success() }} + uses: coverallsapp/github-action@v2 + with: + parallel: true + format: cobertura + flag-name: python-${{ matrix.env.env }} + github-token: ${{ secrets.GITHUB_TOKEN }} coveralls: needs: build diff --git a/.github/workflows/pypi.yml b/.github/workflows/pypi.yml index 8b36d0d..28ae817 100644 --- a/.github/workflows/pypi.yml +++ b/.github/workflows/pypi.yml @@ -17,16 +17,16 @@ jobs: permissions: id-token: write steps: - - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: '3.10' - - name: Install dependencies - run: | - pip install -U pip - pip install build - - name: Build package - run: python -m build - - name: Publish package distributions to PyPI - uses: pypa/gh-action-pypi-publish@v1.12.4 + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.10" + - name: Install dependencies + run: | + pip install -U pip + pip install build + - name: Build package + run: python -m build + - name: Publish package distributions to PyPI + uses: pypa/gh-action-pypi-publish@v1.12.4 diff --git a/README.rst b/README.rst index b7e3094..fbe21f2 100644 --- a/README.rst +++ b/README.rst @@ -309,9 +309,7 @@ HTTPS example with self-signed SSL certificate using ``verify=False``: from netdiff import NetJsonParser - OlsrParser( - url="https://myserver.mydomain.com/topology.json", verify=False - ) + OlsrParser(url="https://myserver.mydomain.com/topology.json", verify=False) NetJSON output -------------- diff --git a/netdiff/exceptions.py b/netdiff/exceptions.py index a8bad6d..6490f9d 100644 --- a/netdiff/exceptions.py +++ b/netdiff/exceptions.py @@ -15,7 +15,7 @@ class ConversionException(NetdiffException): """ def __init__(self, *args, **kwargs): - self.data = kwargs.pop('data') + self.data = kwargs.pop("data") class ParserError(NetdiffException): diff --git a/netdiff/info.py b/netdiff/info.py index 4684bee..4b212a5 100644 --- a/netdiff/info.py +++ b/netdiff/info.py @@ -1,18 +1,18 @@ -VERSION = (1, 2, 0, 'alpha') +VERSION = (1, 2, 0, "alpha") __version__ = VERSION def get_version(): - version = '%s.%s' % (VERSION[0], VERSION[1]) + version = "%s.%s" % (VERSION[0], VERSION[1]) if VERSION[2]: - version = '%s.%s' % (version, VERSION[2]) - if VERSION[3:] == ('alpha', 0): - version = '%s pre-alpha' % version + version = "%s.%s" % (version, VERSION[2]) + if VERSION[3:] == ("alpha", 0): + version = "%s pre-alpha" % version else: - if VERSION[3] != 'final': + if VERSION[3] != "final": try: rev = VERSION[4] except IndexError: rev = 0 - version = '%s%s%s' % (version, VERSION[3][0:1], rev) + version = "%s%s%s" % (version, VERSION[3][0:1], rev) return version diff --git a/netdiff/parsers/base.py b/netdiff/parsers/base.py index d4c5093..dd3eddb 100644 --- a/netdiff/parsers/base.py +++ b/netdiff/parsers/base.py @@ -66,8 +66,8 @@ def __init__( data = self._get_file(file) elif data is None and url is None and file is None: raise ValueError( - 'no topology data supplied, on of the following arguments' - 'must be supplied: data, url or file' + "no topology data supplied, on of the following arguments" + "must be supplied: data, url or file" ) self.original_data = self.to_python(data) # avoid throwing NotImplementedError in tests @@ -76,9 +76,9 @@ def __init__( def _get_url(self, url): url = urlparse.urlparse(url) - if url.scheme in ['http', 'https']: + if url.scheme in ["http", "https"]: return self._get_http(url) - if url.scheme == 'telnet': + if url.scheme == "telnet": return self._get_telnet(url) def __sub__(self, other): @@ -102,7 +102,7 @@ def to_python(self, data): return json.loads(data) except ValueError: pass - raise ConversionException('Could not recognize format', data=data) + raise ConversionException("Could not recognize format", data=data) def _get_file(self, path): try: @@ -118,7 +118,7 @@ def _get_http(self, url): except Exception as e: raise TopologyRetrievalError(e) if response.status_code != 200: - msg = 'Expecting HTTP 200 ok, got {0}'.format(response.status_code) + msg = "Expecting HTTP 200 ok, got {0}".format(response.status_code) raise TopologyRetrievalError(msg) return response.content.decode() @@ -127,8 +127,8 @@ def _get_telnet(self, url): tn = telnetlib.Telnet(url.hostname, url.port, timeout=self.timeout) except Exception as e: raise TopologyRetrievalError(e) - tn.write(("\r\n").encode('ascii')) - data = tn.read_all().decode('ascii') + tn.write(("\r\n").encode("ascii")) + data = tn.read_all().decode("ascii") tn.close() return data diff --git a/netdiff/parsers/batman.py b/netdiff/parsers/batman.py index dae00ce..acc3523 100644 --- a/netdiff/parsers/batman.py +++ b/netdiff/parsers/batman.py @@ -5,12 +5,12 @@ class BatmanParser(BaseParser): """batman-adv parser""" - protocol = 'batman-adv' - version = '2015.0' - metric = 'TQ' + protocol = "batman-adv" + version = "2015.0" + metric = "TQ" # the default expected format - _format = 'alfred_vis' + _format = "alfred_vis" def to_python(self, data): """ @@ -25,20 +25,20 @@ def _txtinfo_to_python(self, data): """ Converts txtinfo format to python """ - self._format = 'txtinfo' + self._format = "txtinfo" # find interesting section - lines = data.split('\n') + lines = data.split("\n") try: - start = lines.index('Table: Topology') + 2 + start = lines.index("Table: Topology") + 2 except ValueError: - raise ParserError('Unrecognized format') + raise ParserError("Unrecognized format") topology_lines = [line for line in lines[start:] if line] # convert to python list parsed_lines = [] for line in topology_lines: - values = line.split(' ') + values = line.split(" ") parsed_lines.append( - {'source': values[0], 'target': values[1], 'cost': float(values[4])} + {"source": values[0], "target": values[1], "cost": float(values[4])} ) return parsed_lines @@ -59,9 +59,9 @@ def _get_aggregated_node_list(self, data): """ node_list = [] for node in data: - local_addresses = [node['primary']] - if 'secondary' in node: - local_addresses += node['secondary'] + local_addresses = [node["primary"]] + if "secondary" in node: + local_addresses += node["secondary"] node_list.append(local_addresses) return node_list @@ -72,7 +72,7 @@ def parse(self, data): * alfred_vis * txtinfo """ - method = getattr(self, '_parse_{0}'.format(self._format)) + method = getattr(self, "_parse_{0}".format(self._format)) return method(data) def _parse_alfred_vis(self, data): @@ -83,26 +83,26 @@ def _parse_alfred_vis(self, data): """ # initialize graph and list of aggregated nodes graph = self._init_graph() - if 'source_version' in data: - self.version = data['source_version'] - if 'vis' not in data: + if "source_version" in data: + self.version = data["source_version"] + if "vis" not in data: raise ParserError('Parse error, "vis" key not found') - node_list = self._get_aggregated_node_list(data['vis']) + node_list = self._get_aggregated_node_list(data["vis"]) # loop over topology section and create networkx graph for node in data["vis"]: for neigh in node["neighbors"]: graph.add_node( - node['primary'], + node["primary"], **{ - 'local_addresses': node.get('secondary', []), - 'clients': node.get('clients', []), + "local_addresses": node.get("secondary", []), + "clients": node.get("clients", []), } ) - primary_neigh = self._get_primary_address(neigh['neighbor'], node_list) + primary_neigh = self._get_primary_address(neigh["neighbor"], node_list) # networkx automatically ignores duplicated edges graph.add_edge( - node['primary'], primary_neigh, weight=float(neigh['metric']) + node["primary"], primary_neigh, weight=float(neigh["metric"]) ) return graph @@ -113,5 +113,5 @@ def _parse_txtinfo(self, data): """ graph = self._init_graph() for link in data: - graph.add_edge(link['source'], link['target'], weight=link['cost']) + graph.add_edge(link["source"], link["target"], weight=link["cost"]) return graph diff --git a/netdiff/parsers/bmx6.py b/netdiff/parsers/bmx6.py index a93bde2..f5edd1c 100644 --- a/netdiff/parsers/bmx6.py +++ b/netdiff/parsers/bmx6.py @@ -5,9 +5,9 @@ class Bmx6Parser(BaseParser): """Bmx6_b6m parser""" - protocol = 'BMX6_b6m' - version = '0' - metric = 'none' + protocol = "BMX6_b6m" + version = "0" + metric = "none" def parse(self, data): """ @@ -22,13 +22,13 @@ def parse(self, data): # loop over topology section and create networkx graph # this data structure does not contain cost information, so we set it as 1 for node in data: - for link in node['links']: - cost = (link['txRate'] + link['rxRate']) / 2.0 + for link in node["links"]: + cost = (link["txRate"] + link["rxRate"]) / 2.0 graph.add_edge( - node['name'], - link['name'], + node["name"], + link["name"], weight=cost, - tx_rate=link['txRate'], - rx_rate=link['rxRate'], + tx_rate=link["txRate"], + rx_rate=link["rxRate"], ) return graph diff --git a/netdiff/parsers/cnml.py b/netdiff/parsers/cnml.py index ec8b488..52d81f4 100644 --- a/netdiff/parsers/cnml.py +++ b/netdiff/parsers/cnml.py @@ -14,7 +14,7 @@ class CnmlParser(BaseParser): """CNML 0.1 parser""" - protocol = 'static' + protocol = "static" version = None metric = None @@ -22,14 +22,14 @@ def to_python(self, data): if isinstance(data, str): up = urlparse.urlparse(data) # if it looks like a file path - if os.path.isfile(data) or up.scheme in ['http', 'https']: + if os.path.isfile(data) or up.scheme in ["http", "https"]: return libcnml.CNMLParser(data) else: - raise ParserError('Could not decode CNML data') + raise ParserError("Could not decode CNML data") elif isinstance(data, libcnml.CNMLParser): return data else: - raise ParserError('Could not find valid data to parse') + raise ParserError("Could not find valid data to parse") def parse(self, data): """ diff --git a/netdiff/parsers/netjson.py b/netdiff/parsers/netjson.py index ccfc5d3..560d84e 100644 --- a/netdiff/parsers/netjson.py +++ b/netdiff/parsers/netjson.py @@ -13,36 +13,36 @@ def parse(self, data): """ graph = self._init_graph() # ensure is NetJSON NetworkGraph object - if 'type' not in data or data['type'] != 'NetworkGraph': - raise ParserError('Parse error, not a NetworkGraph object') + if "type" not in data or data["type"] != "NetworkGraph": + raise ParserError("Parse error, not a NetworkGraph object") # ensure required keys are present - required_keys = ['protocol', 'version', 'metric', 'nodes', 'links'] + required_keys = ["protocol", "version", "metric", "nodes", "links"] for key in required_keys: if key not in data: raise ParserError('Parse error, "{0}" key not found'.format(key)) # store metadata - self.protocol = data['protocol'] - self.version = data['version'] - self.revision = data.get('revision') # optional - self.metric = data['metric'] + self.protocol = data["protocol"] + self.version = data["version"] + self.revision = data.get("revision") # optional + self.metric = data["metric"] # create graph - for node in data['nodes']: + for node in data["nodes"]: graph.add_node( - node['id'], - label=node['label'] if 'label' in node else None, - local_addresses=node.get('local_addresses', []), - **node.get('properties', {}) + node["id"], + label=node["label"] if "label" in node else None, + local_addresses=node.get("local_addresses", []), + **node.get("properties", {}) ) - for link in data['links']: + for link in data["links"]: try: - source = link['source'] - dest = link['target'] - cost = link['cost'] - cost_text = link.get("cost_text", '') + source = link["source"] + dest = link["target"] + cost = link["cost"] + cost_text = link.get("cost_text", "") except KeyError as e: raise ParserError('Parse error, "%s" key not found' % e) - properties = link.get('properties', {}) + properties = link.get("properties", {}) graph.add_edge(source, dest, weight=cost, cost_text=cost_text, **properties) return graph diff --git a/netdiff/parsers/olsr.py b/netdiff/parsers/olsr.py index 2314433..626021b 100644 --- a/netdiff/parsers/olsr.py +++ b/netdiff/parsers/olsr.py @@ -5,9 +5,9 @@ class OlsrParser(BaseParser): """OLSR 1 jsoninfo parser""" - protocol = 'OLSR' - version = '0.8' - metric = 'ETX' + protocol = "OLSR" + version = "0.8" + metric = "ETX" def to_python(self, data): """ @@ -25,41 +25,41 @@ def parse(self, data): Additionally checks for "config" data in order to determine version and revision. """ graph = self._init_graph() - if 'topology' not in data: + if "topology" not in data: raise ParserError('Parse error, "topology" key not found') - elif 'mid' not in data: + elif "mid" not in data: raise ParserError('Parse error, "mid" key not found') # determine version and revision - if 'version' in data: - self.version = data['version']['releaseVersion'] - self.revision = data['version']['sourceHash'] - elif 'config' in data: - version_info = data['config']['olsrdVersion'].replace(' ', '').split('-') + if "version" in data: + self.version = data["version"]["releaseVersion"] + self.revision = data["version"]["sourceHash"] + elif "config" in data: + version_info = data["config"]["olsrdVersion"].replace(" ", "").split("-") self.version = version_info[1] # try to get only the git hash - if 'hash_' in version_info[-1]: - version_info[-1] = version_info[-1].split('hash_')[-1] + if "hash_" in version_info[-1]: + version_info[-1] = version_info[-1].split("hash_")[-1] self.revision = version_info[-1] # process alias list alias_dict = {} - for node in data['mid']: - local_addresses = [alias['ipAddress'] for alias in node['aliases']] - if 'main' in node: - alias_dict[node['main']['ipAddress']] = local_addresses + for node in data["mid"]: + local_addresses = [alias["ipAddress"] for alias in node["aliases"]] + if "main" in node: + alias_dict[node["main"]["ipAddress"]] = local_addresses else: - alias_dict[node['ipAddress']] = local_addresses + alias_dict[node["ipAddress"]] = local_addresses # loop over topology section and create networkx graph - for link in data['topology']: + for link in data["topology"]: try: - source = link['lastHopIP'] - target = link['destinationIP'] - cost = link['tcEdgeCost'] + source = link["lastHopIP"] + target = link["destinationIP"] + cost = link["tcEdgeCost"] properties = { - 'link_quality': link['linkQuality'], - 'neighbor_link_quality': link['neighborLinkQuality'], + "link_quality": link["linkQuality"], + "neighbor_link_quality": link["neighborLinkQuality"], } except KeyError as e: raise ParserError('Parse error, "%s" key not found' % e) @@ -69,7 +69,7 @@ def parse(self, data): continue graph.add_node(node, local_addresses=alias_dict[node]) # skip links with infinite cost - if cost == float('inf'): + if cost == float("inf"): continue # original olsrd cost (jsoninfo multiplies by 1024) cost = float(cost) / 1024.0 @@ -82,49 +82,49 @@ def _txtinfo_to_jsoninfo(self, data): converts olsr 1 txtinfo format to jsoninfo """ # replace INFINITE with inf, which is convertible to float - data = data.replace('INFINITE', 'inf') + data = data.replace("INFINITE", "inf") # find interesting section - lines = data.split('\n') + lines = data.split("\n") # process links in topology section try: - start = lines.index('Table: Topology') + 2 - end = lines[start:].index('') + start + start = lines.index("Table: Topology") + 2 + end = lines[start:].index("") + start except ValueError: - raise ParserError('Unrecognized format') + raise ParserError("Unrecognized format") topology_lines = lines[start:end] # convert topology section to jsoninfo format topology = [] for line in topology_lines: - values = line.split('\t') + values = line.split("\t") topology.append( { - 'destinationIP': values[0], - 'lastHopIP': values[1], - 'linkQuality': float(values[2]), - 'neighborLinkQuality': float(values[3]), - 'tcEdgeCost': float(values[4]) * 1024.0, + "destinationIP": values[0], + "lastHopIP": values[1], + "linkQuality": float(values[2]), + "neighborLinkQuality": float(values[3]), + "tcEdgeCost": float(values[4]) * 1024.0, } ) # process alias (MID) section try: - start = lines.index('Table: MID') + 2 - end = lines[start:].index('') + start + start = lines.index("Table: MID") + 2 + end = lines[start:].index("") + start except ValueError: - raise ParserError('Unrecognized format') + raise ParserError("Unrecognized format") mid_lines = lines[start:end] # convert mid section to jsoninfo format mid = [] for line in mid_lines: - values = line.split('\t') + values = line.split("\t") node = values[0] - aliases = values[1].split(';') + aliases = values[1].split(";") mid.append( { - 'ipAddress': node, - 'aliases': [{'ipAddress': alias} for alias in aliases], + "ipAddress": node, + "aliases": [{"ipAddress": alias} for alias in aliases], } ) - return {'topology': topology, 'mid': mid} + return {"topology": topology, "mid": mid} diff --git a/netdiff/parsers/openvpn.py b/netdiff/parsers/openvpn.py index 4707ca0..37ef221 100644 --- a/netdiff/parsers/openvpn.py +++ b/netdiff/parsers/openvpn.py @@ -8,15 +8,15 @@ class OpenvpnParser(BaseParser): """OpenVPN status log parser""" - protocol = 'OpenVPN Status Log' - version = '1' - metric = 'static' + protocol = "OpenVPN Status Log" + version = "1" + metric = "static" duplicate_cn = False # for internal use only - _server_common_name = 'openvpn-server' + _server_common_name = "openvpn-server" def __init__(self, *args, **kwargs): - self.duplicate_cn = kwargs.pop('duplicate_cn', OpenvpnParser.duplicate_cn) + self.duplicate_cn = kwargs.pop("duplicate_cn", OpenvpnParser.duplicate_cn) super().__init__(*args, **kwargs) def to_python(self, data): @@ -25,7 +25,7 @@ def to_python(self, data): try: return parse_status(data) except (AttributeError, ParsingError) as e: - msg = 'OpenVPN parsing error: {0}'.format(str(e)) + msg = "OpenVPN parsing error: {0}".format(str(e)) raise ConversionException(msg, data=data) def parse(self, data): @@ -48,19 +48,19 @@ def parse(self, data): special_cases = self._find_special_cases(clients) # add clients in graph as nodes for client in clients: - if client.common_name == 'UNDEF': + if client.common_name == "UNDEF": continue address = client.real_address client_properties = { - 'label': client.common_name, - 'real_address': str(address.host), - 'port': int(address.port), - 'connected_since': client.connected_since.strftime( - '%Y-%m-%dT%H:%M:%SZ' + "label": client.common_name, + "real_address": str(address.host), + "port": int(address.port), + "connected_since": client.connected_since.strftime( + "%Y-%m-%dT%H:%M:%SZ" ), - 'bytes_received': int(client.bytes_received), - 'bytes_sent': int(client.bytes_sent), - 'common_name': client.common_name, + "bytes_received": int(client.bytes_received), + "bytes_sent": int(client.bytes_sent), + "common_name": client.common_name, } local_addresses = [ str(route.virtual_address) @@ -68,12 +68,12 @@ def parse(self, data): if route.real_address == address ] if local_addresses: - client_properties['local_addresses'] = local_addresses + client_properties["local_addresses"] = local_addresses node_id = self.get_node_id(client, special_cases) graph.add_node(node_id, **client_properties) # add links in routing table to graph for link in links: - if link.common_name == 'UNDEF': + if link.common_name == "UNDEF": continue target_id = self.get_target_id(link, special_cases) graph.add_edge(server, str(target_id), weight=1) @@ -90,9 +90,9 @@ def get_node_id(self, client, special_cases): if not self.duplicate_cn: return client.common_name address = client.real_address - node_id = f'{client.common_name},{address.host}' + node_id = f"{client.common_name},{address.host}" if node_id in special_cases: - node_id = f'{node_id}:{address.port}' + node_id = f"{node_id}:{address.port}" return node_id def get_target_id(self, link, special_cases): @@ -106,9 +106,9 @@ def get_target_id(self, link, special_cases): if not self.duplicate_cn: return link.common_name address = link.real_address - target_id = f'{link.common_name},{address.host}' + target_id = f"{link.common_name},{address.host}" if target_id in special_cases: - target_id = f'{target_id}:{address.port}' + target_id = f"{target_id}:{address.port}" return target_id def _find_special_cases(self, clients): @@ -117,7 +117,7 @@ def _find_special_cases(self, clients): id_list = [] special_cases = [] for client in clients: - id_ = f'{client.common_name},{client.real_address.host}' + id_ = f"{client.common_name},{client.real_address.host}" if id_ in id_list: special_cases.append(id_) continue diff --git a/netdiff/parsers/wireguard.py b/netdiff/parsers/wireguard.py index faea135..f45a634 100644 --- a/netdiff/parsers/wireguard.py +++ b/netdiff/parsers/wireguard.py @@ -8,9 +8,9 @@ class WireguardParser(BaseParser): """wireguard parser""" - protocol = 'Wireguard Status Log' - version = '1' - metric = 'static' + protocol = "Wireguard Status Log" + version = "1" + metric = "static" max_time_diff = timedelta(minutes=5) def to_python(self, data): @@ -20,14 +20,14 @@ def to_python(self, data): return self._wg_dump_to_python(e.data) def __parse_value(self, value): - return None if value == '(none)' else value + return None if value == "(none)" else value def _wg_dump_to_python(self, data): - lines = map(lambda line: line.split('\t'), data.strip().split('\n')) + lines = map(lambda line: line.split("\t"), data.strip().split("\n")) try: parsed_lines = self._parse_lines(lines) except ValueError: - raise ParserError('Unrecognized format') + raise ParserError("Unrecognized format") return parsed_lines def _parse_lines(self, lines): @@ -60,18 +60,18 @@ def _parse_lines(self, lines): connected, latest_handshake = self._parse_latest_handshake( latest_handshake ) - parsed_lines[device]['peers'].append( + parsed_lines[device]["peers"].append( { public_key: dict( preshared_key=preshared_key, endpoint=endpoint, latest_handshake=latest_handshake.strftime( - '%Y-%m-%dT%H:%M:%SZ' + "%Y-%m-%dT%H:%M:%SZ" ), transfer_rx=transfer_rx, transfer_tx=transfer_tx, persistent_keepalive=persistent_keepalive, - allowed_ips=allowed_ips.split(',') if allowed_ips else [], + allowed_ips=allowed_ips.split(",") if allowed_ips else [], connected=connected, ), } @@ -95,14 +95,14 @@ def parse(self, data): graph = self._init_graph() data = deepcopy(data) for interface, interface_properties in data.items(): - peers = interface_properties.pop('peers', []) + peers = interface_properties.pop("peers", []) graph.add_node(interface, **interface_properties) for peer in peers: public_key = (*peer,)[0] peer_properties = peer[public_key] - if not peer_properties.get('connected'): + if not peer_properties.get("connected"): continue - allowed_ips = ', '.join(peer_properties.get('allowed_ips', [])) + allowed_ips = ", ".join(peer_properties.get("allowed_ips", [])) graph.add_node(public_key, label=allowed_ips, **peer_properties) graph.add_edge(public_key, interface, weight=1) return graph diff --git a/netdiff/parsers/zerotier.py b/netdiff/parsers/zerotier.py index 64b41c8..517c2b3 100644 --- a/netdiff/parsers/zerotier.py +++ b/netdiff/parsers/zerotier.py @@ -2,9 +2,9 @@ class ZeroTierParser(BaseParser): - version = '1' - metric = 'static' - protocol = 'ZeroTier Controller Peers' + version = "1" + metric = "static" + protocol = "ZeroTier Controller Peers" def to_python(self, data): return super().to_python(data) @@ -16,29 +16,29 @@ def parse(self, data): # that is a member of a ZeroTier virtual network. # Therefore, we can skip peers with roles other than 'LEAF' # or with latency -1 (indicating not reachable) - if peer.get('role') != 'LEAF' or peer.get('latency') == -1: + if peer.get("role") != "LEAF" or peer.get("latency") == -1: continue # Similar to zerotier-cli peers command (PATH) # We only select path that are active, preferred, and not expired - for path in peer.get('paths'): + for path in peer.get("paths"): if ( - not path.get('expired') - and path.get('active') - and path.get('preferred') + not path.get("expired") + and path.get("active") + and path.get("preferred") ): - peer_address = peer.get('address') + peer_address = peer.get("address") peer_properties = dict( label=peer_address, address=peer_address, - ip_address=path.pop('address'), - role=peer.get('role'), - version=peer.get('version'), - tunneled=peer.get('tunneled'), - isBonded=peer.get('isBonded'), + ip_address=path.pop("address"), + role=peer.get("role"), + version=peer.get("version"), + tunneled=peer.get("tunneled"), + isBonded=peer.get("isBonded"), ) - graph.add_node('controller', label='controller') + graph.add_node("controller", label="controller") graph.add_node(peer_address, **peer_properties) graph.add_edge( - 'controller', peer_address, weight=peer.get('latency'), **path + "controller", peer_address, weight=peer.get("latency"), **path ) return graph diff --git a/netdiff/tests.py b/netdiff/tests.py index 9ffc563..d7195e3 100644 --- a/netdiff/tests.py +++ b/netdiff/tests.py @@ -1,6 +1,6 @@ import unittest -__all__ = ['TestCase'] +__all__ = ["TestCase"] class TestCase(unittest.TestCase): @@ -14,8 +14,8 @@ def _test_expected_links(self, graph, expected_links): """ found = 0 # loop over all links (the result got by netdiff) - for link in graph['links']: - tuple_link = (link['source'], link['target']) + for link in graph["links"]: + tuple_link = (link["source"], link["target"]) # all expected links must be in links for expected_link in expected_links: # use sets to ignore ordering diff --git a/netdiff/utils.py b/netdiff/utils.py index 2aafc91..bb7bbd1 100644 --- a/netdiff/utils.py +++ b/netdiff/utils.py @@ -51,7 +51,7 @@ def diff(old, new): ) else: changed = None - return OrderedDict((('added', added), ('removed', removed), ('changed', changed))) + return OrderedDict((("added", added), ("removed", removed), ("changed", changed))) def _make_diff(old, new, both): @@ -104,8 +104,8 @@ def _nodes_difference(graph, both): props = properties.copy() old_node = [ip] # wrap attributes in tuples so they will be recognizable - old_node.append(('label', popdefault(props, 'label', ''))) - old_node.append(('local_addresses', props.pop('local_addresses', []))) + old_node.append(("label", popdefault(props, "label", ""))) + old_node.append(("local_addresses", props.pop("local_addresses", []))) for name, value in props.items(): old_node.append((name, value)) nodes.append(old_node) @@ -140,9 +140,9 @@ def _edges_difference(graph, both): if set((src, dst)) not in both: continue props = properties.copy() - old_edge = [('_src', src), ('_dst', dst)] - old_edge.append(('weight', props.pop('weight'))) - old_edge.append(('cost_text', props.pop('cost_text', ''))) + old_edge = [("_src", src), ("_dst", dst)] + old_edge.append(("weight", props.pop("weight"))) + old_edge.append(("cost_text", props.pop("cost_text", ""))) for name, value in props.items(): old_edge.append((name, value)) edges.append(set(old_edge)) @@ -163,8 +163,8 @@ def _find_changed_edges(old, new, both): for new_edge in new_edges: if new_edge not in old_edges: props = dict(new_edge) - src = props.pop('_src') - dst = props.pop('_dst') + src = props.pop("_src") + dst = props.pop("_dst") changed.append([src, dst, props]) return changed @@ -184,40 +184,40 @@ def _netjson_networkgraph( ): # netjson format validity check if protocol is None: - raise NetJsonError('protocol cannot be None') - if version is None and protocol != 'static': + raise NetJsonError("protocol cannot be None") + if version is None and protocol != "static": raise NetJsonError('version cannot be None except when protocol is "static"') # prepare nodes node_list = [] for ip, properties in nodes: - netjson_node = OrderedDict({'id': ip}) + netjson_node = OrderedDict({"id": ip}) # must copy properties dict to avoid modifying data props = properties.copy() - netjson_node['label'] = popdefault(props, 'label', '') - netjson_node['local_addresses'] = popdefault(props, 'local_addresses', []) - netjson_node['properties'] = props + netjson_node["label"] = popdefault(props, "label", "") + netjson_node["local_addresses"] = popdefault(props, "local_addresses", []) + netjson_node["properties"] = props node_list.append(netjson_node) - node_list.sort(key=lambda d: d['id']) + node_list.sort(key=lambda d: d["id"]) # prepare links link_list = [] for source, target, properties in links: # must copy properties dict to avoid modifying data props = properties.copy() - netjson_link = OrderedDict((('source', source), ('target', target))) - netjson_link['cost'] = props.pop('weight') - netjson_link['cost_text'] = popdefault(props, 'cost_text', '') - netjson_link['properties'] = props + netjson_link = OrderedDict((("source", source), ("target", target))) + netjson_link["cost"] = props.pop("weight") + netjson_link["cost_text"] = popdefault(props, "cost_text", "") + netjson_link["properties"] = props link_list.append(netjson_link) - link_list.sort(key=lambda d: (d['source'], d['target'])) + link_list.sort(key=lambda d: (d["source"], d["target"])) data = OrderedDict( ( - ('type', 'NetworkGraph'), - ('protocol', protocol), - ('version', version), - ('revision', revision), - ('metric', metric), - ('nodes', node_list), - ('links', link_list), + ("type", "NetworkGraph"), + ("protocol", protocol), + ("version", version), + ("revision", revision), + ("metric", metric), + ("nodes", node_list), + ("links", link_list), ) ) if dict: diff --git a/setup.py b/setup.py index 218f7c0..d77473b 100644 --- a/setup.py +++ b/setup.py @@ -4,24 +4,24 @@ from setuptools import find_packages, setup # avoid networkx ImportError -sys.path.insert(0, 'netdiff') +sys.path.insert(0, "netdiff") from info import get_version -sys.path.remove('netdiff') +sys.path.remove("netdiff") -if sys.argv[-1] == 'setup.py': +if sys.argv[-1] == "setup.py": print("To install, run 'python setup.py install'\n") -if sys.argv[-1] == 'publish': +if sys.argv[-1] == "publish": import os os.system('find . | grep -E "(__pycache__|\.pyc|\.pyo$)" | xargs rm -rf') os.system("python setup.py sdist bdist_wheel") os.system("twine upload -s dist/*") os.system("rm -rf dist build") - args = {'version': get_version()} + args = {"version": get_version()} print("You probably want to also tag the version now:") print(" git tag -a %(version)s -m 'version %(version)s'" % args) print(" git push --tags") @@ -33,45 +33,45 @@ def get_install_requires(): parse requirements.txt, ignore links, exclude comments """ requirements = [] - for line in open('requirements.txt').readlines(): + for line in open("requirements.txt").readlines(): # skip to next iteration if comment or empty line if ( - line.startswith('#') - or line == '' - or line.startswith('http') - or line.startswith('git') + line.startswith("#") + or line == "" + or line.startswith("http") + or line.startswith("git") ): continue # add line to requirements - requirements.append(line.replace('\n', '')) + requirements.append(line.replace("\n", "")) return requirements setup( - name='netdiff', + name="netdiff", version=get_version(), description="Python library for parsing network topology data (eg: dynamic " "routing protocols, NetJSON, CNML) and detect changes.", - long_description=open('README.rst').read(), - author='Federico Capoano', - author_email='federico.capoano@gmail.com', - license='MIT', - url='https://github.com/ninuxorg/netdiff', - download_url='https://github.com/ninuxorg/netdiff/releases', - keywords=['networking', 'mesh-network', 'netjson', 'olsr', 'batman', 'bmx'], - platforms=['Platform Independent'], - packages=find_packages(exclude=['tests', 'tests.*', 'docs', 'docs.*']), + long_description=open("README.rst").read(), + author="Federico Capoano", + author_email="federico.capoano@gmail.com", + license="MIT", + url="https://github.com/ninuxorg/netdiff", + download_url="https://github.com/ninuxorg/netdiff/releases", + keywords=["networking", "mesh-network", "netjson", "olsr", "batman", "bmx"], + platforms=["Platform Independent"], + packages=find_packages(exclude=["tests", "tests.*", "docs", "docs.*"]), zip_safe=False, classifiers=[ - 'Development Status :: 5 - Production/Stable ', - 'Environment :: Console', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: MIT License', - 'Operating System :: OS Independent', - 'Programming Language :: Python', - 'Topic :: System :: Networking', - 'Programming Language :: Python :: 3', + "Development Status :: 5 - Production/Stable", + "Environment :: Console", + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Topic :: System :: Networking", + "Programming Language :: Python :: 3", ], install_requires=get_install_requires(), - test_suite='nose2.collector', + test_suite="nose2.collector", ) diff --git a/tests/static/batman-1+1.json b/tests/static/batman-1+1.json index c4977f7..3192382 100644 --- a/tests/static/batman-1+1.json +++ b/tests/static/batman-1+1.json @@ -1,112 +1,109 @@ { - "source_version":"2014.3.0", - "algorithm":4, - "vis":[ + "source_version": "2014.3.0", + "algorithm": 4, + "vis": [ + { + "primary": "a0:f3:c1:96:94:10", + "neighbors": [ { - "primary":"a0:f3:c1:96:94:10", - "neighbors":[ - { - "router":"a0:f3:c1:96:94:10", - "neighbor":"90:f6:52:f2:8c:2d", - "metric":"1.000" - } - ], - "clients":[ - "86:a6:e8:ff:fd:6c", - "64:76:ba:7e:06:44", - "68:72:51:05:79:10", - "86:a6:e8:ff:fd:6c", - "a0:f3:c1:96:94:05" - ] - }, + "router": "a0:f3:c1:96:94:10", + "neighbor": "90:f6:52:f2:8c:2d", + "metric": "1.000" + } + ], + "clients": [ + "86:a6:e8:ff:fd:6c", + "64:76:ba:7e:06:44", + "68:72:51:05:79:10", + "86:a6:e8:ff:fd:6c", + "a0:f3:c1:96:94:05" + ] + }, + { + "primary": "a0:f3:c1:ac:6c:44", + "neighbors": [ + { + "router": "a0:f3:c1:ac:6c:44", + "neighbor": "10:fe:ed:37:3a:39", + "metric": "1.000" + } + ], + "clients": [ + "a0:f3:c1:ac:6c:4c", + "dc:9f:db:f1:d7:a9", + "46:1f:b2:8b:c2:a1", + "46:1f:b2:8b:c2:a1" + ] + }, + { + "primary": "90:f6:52:f2:8c:2c", + "secondary": ["90:f6:52:f2:8c:2b", "90:f6:52:f2:8c:2d"], + "neighbors": [ { - "primary":"a0:f3:c1:ac:6c:44", - "neighbors":[ - { - "router":"a0:f3:c1:ac:6c:44", - "neighbor":"10:fe:ed:37:3a:39", - "metric":"1.000" - } - ], - "clients":[ - "a0:f3:c1:ac:6c:4c", - "dc:9f:db:f1:d7:a9", - "46:1f:b2:8b:c2:a1", - "46:1f:b2:8b:c2:a1" - ] + "router": "90:f6:52:f2:8c:2c", + "neighbor": "00:05:1c:06:35:8e", + "metric": "1.000" }, { - "primary":"90:f6:52:f2:8c:2c", - "secondary":[ - "90:f6:52:f2:8c:2b", - "90:f6:52:f2:8c:2d" - ], - "neighbors":[ - { - "router":"90:f6:52:f2:8c:2c", - "neighbor":"00:05:1c:06:35:8e", - "metric":"1.000" - }, - { - "router":"90:f6:52:f2:8c:2b", - "neighbor":"10:fe:ed:37:3a:39", - "metric":"1.000" - }, - { - "router":"90:f6:52:f2:8c:2d", - "neighbor":"a0:f3:c1:96:94:10", - "metric":"1.000" - } - ], - "clients":[ - "ee:74:50:85:fd:67", - "dc:9f:db:f1:d8:aa", - "68:72:51:05:7c:86", - "90:f6:52:f2:8c:2a", - "ee:74:50:85:fd:67", - "24:a4:3c:6d:fd:81", - "24:a4:3c:6d:fd:82" - ] + "router": "90:f6:52:f2:8c:2b", + "neighbor": "10:fe:ed:37:3a:39", + "metric": "1.000" }, { - "primary":"00:05:1c:06:35:8e", - "neighbors":[ - { - "router":"00:05:1c:06:35:8e", - "neighbor":"90:f6:52:f2:8c:2c", - "metric":"1.000" - } - ], - "clients":[ - "00:ff:aa:00:00:01", - "00:18:7d:0b:b3:31", - "52:fe:31:1d:aa:4e", - "24:a4:3c:47:53:9a", - "dc:9f:db:0b:af:b9", - "52:fe:31:1d:aa:4e", - "dc:9f:db:f1:d8:a7" - ] + "router": "90:f6:52:f2:8c:2d", + "neighbor": "a0:f3:c1:96:94:10", + "metric": "1.000" + } + ], + "clients": [ + "ee:74:50:85:fd:67", + "dc:9f:db:f1:d8:aa", + "68:72:51:05:7c:86", + "90:f6:52:f2:8c:2a", + "ee:74:50:85:fd:67", + "24:a4:3c:6d:fd:81", + "24:a4:3c:6d:fd:82" + ] + }, + { + "primary": "00:05:1c:06:35:8e", + "neighbors": [ + { + "router": "00:05:1c:06:35:8e", + "neighbor": "90:f6:52:f2:8c:2c", + "metric": "1.000" + } + ], + "clients": [ + "00:ff:aa:00:00:01", + "00:18:7d:0b:b3:31", + "52:fe:31:1d:aa:4e", + "24:a4:3c:47:53:9a", + "dc:9f:db:0b:af:b9", + "52:fe:31:1d:aa:4e", + "dc:9f:db:f1:d8:a7" + ] + }, + { + "primary": "10:fe:ed:37:3a:39", + "neighbors": [ + { + "router": "10:fe:ed:37:3a:39", + "neighbor": "90:f6:52:f2:8c:2b", + "metric": "1.000" }, { - "primary":"10:fe:ed:37:3a:39", - "neighbors":[ - { - "router":"10:fe:ed:37:3a:39", - "neighbor":"90:f6:52:f2:8c:2b", - "metric":"1.000" - }, - { - "router":"10:fe:ed:37:3a:39", - "neighbor":"a0:f3:c1:ac:6c:44", - "metric":"1.016" - } - ], - "clients":[ - "10:fe:ed:37:3a:38", - "24:a4:3c:6d:fd:ce", - "a6:86:18:b1:00:7b", - "a6:86:18:b1:00:7b" - ] + "router": "10:fe:ed:37:3a:39", + "neighbor": "a0:f3:c1:ac:6c:44", + "metric": "1.016" } - ] + ], + "clients": [ + "10:fe:ed:37:3a:38", + "24:a4:3c:6d:fd:ce", + "a6:86:18:b1:00:7b", + "a6:86:18:b1:00:7b" + ] + } + ] } diff --git a/tests/static/batman-duplicated.json b/tests/static/batman-duplicated.json index 0c7b58b..2c39c08 100644 --- a/tests/static/batman-duplicated.json +++ b/tests/static/batman-duplicated.json @@ -1,85 +1,82 @@ { - "source_version":"2014.3.0", - "algorithm":4, - "vis":[ + "source_version": "2014.3.0", + "algorithm": 4, + "vis": [ + { + "primary": "a0:f3:c1:96:94:06", + "neighbors": [ { - "primary":"a0:f3:c1:96:94:06", - "neighbors":[ - { - "router":"a0:f3:c1:96:94:06", - "neighbor":"90:f6:52:f2:8c:2d", - "metric":"1.000" - } - ] - }, + "router": "a0:f3:c1:96:94:06", + "neighbor": "90:f6:52:f2:8c:2d", + "metric": "1.000" + } + ] + }, + { + "primary": "a0:f3:c1:96:94:06", + "neighbors": [ { - "primary":"a0:f3:c1:96:94:06", - "neighbors":[ - { - "router":"a0:f3:c1:96:94:06", - "neighbor":"90:f6:52:f2:8c:2d", - "metric":"1.000" - } - ] - }, + "router": "a0:f3:c1:96:94:06", + "neighbor": "90:f6:52:f2:8c:2d", + "metric": "1.000" + } + ] + }, + { + "primary": "a0:f3:c1:ac:6c:44", + "neighbors": [ + { + "router": "a0:f3:c1:ac:6c:44", + "neighbor": "10:fe:ed:37:3a:39", + "metric": "1.000" + } + ] + }, + { + "primary": "90:f6:52:f2:8c:2c", + "secondary": ["90:f6:52:f2:8c:2b", "90:f6:52:f2:8c:2d"], + "neighbors": [ { - "primary":"a0:f3:c1:ac:6c:44", - "neighbors":[ - { - "router":"a0:f3:c1:ac:6c:44", - "neighbor":"10:fe:ed:37:3a:39", - "metric":"1.000" - } - ] + "router": "90:f6:52:f2:8c:2c", + "neighbor": "00:05:1c:06:35:8e", + "metric": "1.000" }, { - "primary":"90:f6:52:f2:8c:2c", - "secondary":[ - "90:f6:52:f2:8c:2b", - "90:f6:52:f2:8c:2d" - ], - "neighbors":[ - { - "router":"90:f6:52:f2:8c:2c", - "neighbor":"00:05:1c:06:35:8e", - "metric":"1.000" - }, - { - "router":"90:f6:52:f2:8c:2b", - "neighbor":"10:fe:ed:37:3a:39", - "metric":"1.000" - }, - { - "router":"90:f6:52:f2:8c:2d", - "neighbor":"a0:f3:c1:96:94:06", - "metric":"1.000" - } - ] + "router": "90:f6:52:f2:8c:2b", + "neighbor": "10:fe:ed:37:3a:39", + "metric": "1.000" }, { - "primary":"00:05:1c:06:35:8e", - "neighbors":[ - { - "router":"00:05:1c:06:35:8e", - "neighbor":"90:f6:52:f2:8c:2c", - "metric":"1.000" - } - ] + "router": "90:f6:52:f2:8c:2d", + "neighbor": "a0:f3:c1:96:94:06", + "metric": "1.000" + } + ] + }, + { + "primary": "00:05:1c:06:35:8e", + "neighbors": [ + { + "router": "00:05:1c:06:35:8e", + "neighbor": "90:f6:52:f2:8c:2c", + "metric": "1.000" + } + ] + }, + { + "primary": "10:fe:ed:37:3a:39", + "neighbors": [ + { + "router": "10:fe:ed:37:3a:39", + "neighbor": "90:f6:52:f2:8c:2b", + "metric": "1.000" }, { - "primary":"10:fe:ed:37:3a:39", - "neighbors":[ - { - "router":"10:fe:ed:37:3a:39", - "neighbor":"90:f6:52:f2:8c:2b", - "metric":"1.000" - }, - { - "router":"10:fe:ed:37:3a:39", - "neighbor":"a0:f3:c1:ac:6c:44", - "metric":"1.016" - } - ] + "router": "10:fe:ed:37:3a:39", + "neighbor": "a0:f3:c1:ac:6c:44", + "metric": "1.016" } - ] + ] + } + ] } diff --git a/tests/static/batman.json b/tests/static/batman.json index c735b73..fce8e76 100644 --- a/tests/static/batman.json +++ b/tests/static/batman.json @@ -1,111 +1,108 @@ { - "source_version":"2014.3.0", - "algorithm":4, - "vis":[ + "source_version": "2014.3.0", + "algorithm": 4, + "vis": [ + { + "primary": "a0:f3:c1:96:94:06", + "neighbors": [ { - "primary":"a0:f3:c1:96:94:06", - "neighbors":[ - { - "router":"a0:f3:c1:96:94:06", - "neighbor":"90:f6:52:f2:8c:2d", - "metric":"1.000" - } - ], - "clients":[ - "86:a6:e8:ff:fd:6c", - "64:76:ba:7e:06:44", - "68:72:51:05:79:10", - "86:a6:e8:ff:fd:6c", - "a0:f3:c1:96:94:05" - ] - }, + "router": "a0:f3:c1:96:94:06", + "neighbor": "90:f6:52:f2:8c:2d", + "metric": "1.000" + } + ], + "clients": [ + "86:a6:e8:ff:fd:6c", + "64:76:ba:7e:06:44", + "68:72:51:05:79:10", + "86:a6:e8:ff:fd:6c", + "a0:f3:c1:96:94:05" + ] + }, + { + "primary": "a0:f3:c1:ac:6c:44", + "neighbors": [ + { + "router": "a0:f3:c1:ac:6c:44", + "neighbor": "10:fe:ed:37:3a:39", + "metric": "1.000" + } + ], + "clients": [ + "a0:f3:c1:ac:6c:4c", + "dc:9f:db:f1:d7:a9", + "46:1f:b2:8b:c2:a1", + "46:1f:b2:8b:c2:a1" + ] + }, + { + "primary": "90:f6:52:f2:8c:2c", + "secondary": ["90:f6:52:f2:8c:2b", "90:f6:52:f2:8c:2d"], + "neighbors": [ { - "primary":"a0:f3:c1:ac:6c:44", - "neighbors":[ - { - "router":"a0:f3:c1:ac:6c:44", - "neighbor":"10:fe:ed:37:3a:39", - "metric":"1.000" - } - ], - "clients":[ - "a0:f3:c1:ac:6c:4c", - "dc:9f:db:f1:d7:a9", - "46:1f:b2:8b:c2:a1", - "46:1f:b2:8b:c2:a1" - ] + "router": "90:f6:52:f2:8c:2c", + "neighbor": "00:05:1c:06:35:8e", + "metric": "1.000" }, { - "primary":"90:f6:52:f2:8c:2c", - "secondary":[ - "90:f6:52:f2:8c:2b", - "90:f6:52:f2:8c:2d" - ], - "neighbors":[ - { - "router":"90:f6:52:f2:8c:2c", - "neighbor":"00:05:1c:06:35:8e", - "metric":"1.000" - }, - { - "router":"90:f6:52:f2:8c:2b", - "neighbor":"10:fe:ed:37:3a:39", - "metric":"1.000" - }, - { - "router":"90:f6:52:f2:8c:2d", - "neighbor":"a0:f3:c1:96:94:06", - "metric":"1.000" - } - ], - "clients":[ - "ee:74:50:85:fd:67", - "dc:9f:db:f1:d8:aa", - "68:72:51:05:7c:86", - "90:f6:52:f2:8c:2a", - "ee:74:50:85:fd:67", - "24:a4:3c:6d:fd:81" - ] + "router": "90:f6:52:f2:8c:2b", + "neighbor": "10:fe:ed:37:3a:39", + "metric": "1.000" }, { - "primary":"00:05:1c:06:35:8e", - "neighbors":[ - { - "router":"00:05:1c:06:35:8e", - "neighbor":"90:f6:52:f2:8c:2c", - "metric":"1.000" - } - ], - "clients":[ - "00:ff:aa:00:00:01", - "00:18:7d:0b:b3:31", - "52:fe:31:1d:aa:4e", - "24:a4:3c:47:53:9a", - "dc:9f:db:0b:af:b9", - "52:fe:31:1d:aa:4e", - "dc:9f:db:f1:d8:a7" - ] + "router": "90:f6:52:f2:8c:2d", + "neighbor": "a0:f3:c1:96:94:06", + "metric": "1.000" + } + ], + "clients": [ + "ee:74:50:85:fd:67", + "dc:9f:db:f1:d8:aa", + "68:72:51:05:7c:86", + "90:f6:52:f2:8c:2a", + "ee:74:50:85:fd:67", + "24:a4:3c:6d:fd:81" + ] + }, + { + "primary": "00:05:1c:06:35:8e", + "neighbors": [ + { + "router": "00:05:1c:06:35:8e", + "neighbor": "90:f6:52:f2:8c:2c", + "metric": "1.000" + } + ], + "clients": [ + "00:ff:aa:00:00:01", + "00:18:7d:0b:b3:31", + "52:fe:31:1d:aa:4e", + "24:a4:3c:47:53:9a", + "dc:9f:db:0b:af:b9", + "52:fe:31:1d:aa:4e", + "dc:9f:db:f1:d8:a7" + ] + }, + { + "primary": "10:fe:ed:37:3a:39", + "neighbors": [ + { + "router": "10:fe:ed:37:3a:39", + "neighbor": "90:f6:52:f2:8c:2b", + "metric": "1.000" }, { - "primary":"10:fe:ed:37:3a:39", - "neighbors":[ - { - "router":"10:fe:ed:37:3a:39", - "neighbor":"90:f6:52:f2:8c:2b", - "metric":"1.000" - }, - { - "router":"10:fe:ed:37:3a:39", - "neighbor":"a0:f3:c1:ac:6c:44", - "metric":"1.016" - } - ], - "clients":[ - "10:fe:ed:37:3a:38", - "24:a4:3c:6d:fd:ce", - "a6:86:18:b1:00:7b", - "a6:86:18:b1:00:7b" - ] + "router": "10:fe:ed:37:3a:39", + "neighbor": "a0:f3:c1:ac:6c:44", + "metric": "1.016" } - ] + ], + "clients": [ + "10:fe:ed:37:3a:38", + "24:a4:3c:6d:fd:ce", + "a6:86:18:b1:00:7b", + "a6:86:18:b1:00:7b" + ] + } + ] } diff --git a/tests/static/bmx6-1+1.json b/tests/static/bmx6-1+1.json index 45d9131..9f41897 100644 --- a/tests/static/bmx6-1+1.json +++ b/tests/static/bmx6-1+1.json @@ -20,54 +20,54 @@ ] }, { - "name": "P9SFBadajoz93-6e99", - "links": [ - { - "name": "P9SFAlmogavers237-56ac", - "rxRate": 95, - "txRate": 1 - } - ] + "name": "P9SFBadajoz93-6e99", + "links": [ + { + "name": "P9SFAlmogavers237-56ac", + "rxRate": 95, + "txRate": 1 + } + ] }, { - "name": "P9SFBilbao102-7df9", - "links": [ - { - "name": "P9SFAlmogavers237-56ac", - "rxRate": 81, - "txRate": 95 - } - ] + "name": "P9SFBilbao102-7df9", + "links": [ + { + "name": "P9SFAlmogavers237-56ac", + "rxRate": 81, + "txRate": 95 + } + ] }, { - "name": "P9SFCastanys31-1663", - "links": [ - { - "name": "P9SFAlmogavers237-56ac", - "rxRate": 100, - "txRate": 97 - }, - { - "name": "P9SFCiutatGranada73-68f5", - "rxRate": 100, - "txRate": 97 - } - ] + "name": "P9SFCastanys31-1663", + "links": [ + { + "name": "P9SFAlmogavers237-56ac", + "rxRate": 100, + "txRate": 97 + }, + { + "name": "P9SFCiutatGranada73-68f5", + "rxRate": 100, + "txRate": 97 + } + ] }, { - "name": "P9SFCiutatGranada73-68f5", - "links": [ - { - "name": "P9SFDrTruetaa183-b715", - "rxRate": 93, - "txRate": 59 - }, - { - "name": "PP9SFCastanys31-1663", - "rxRate": 93, - "txRate": 59 - } - ] + "name": "P9SFCiutatGranada73-68f5", + "links": [ + { + "name": "P9SFDrTruetaa183-b715", + "rxRate": 93, + "txRate": 59 + }, + { + "name": "PP9SFCastanys31-1663", + "rxRate": 93, + "txRate": 59 + } + ] }, { "name": "P9SFDrTruetaa183-b715", diff --git a/tests/static/bmx6.json b/tests/static/bmx6.json index 5cd6932..c4b6bc5 100644 --- a/tests/static/bmx6.json +++ b/tests/static/bmx6.json @@ -20,54 +20,54 @@ ] }, { - "name": "P9SFBadajoz93-6e99", - "links": [ - { - "name": "P9SFAlmogavers237-56ac", - "rxRate": 95, - "txRate": 1 - } - ] + "name": "P9SFBadajoz93-6e99", + "links": [ + { + "name": "P9SFAlmogavers237-56ac", + "rxRate": 95, + "txRate": 1 + } + ] }, { - "name": "P9SFBilbao102-7df9", - "links": [ - { - "name": "P9SFAlmogavers237-56ac", - "rxRate": 81, - "txRate": 95 - } - ] + "name": "P9SFBilbao102-7df9", + "links": [ + { + "name": "P9SFAlmogavers237-56ac", + "rxRate": 81, + "txRate": 95 + } + ] }, { - "name": "P9SFCastanys31-1663", - "links": [ - { - "name": "P9SFAlmogavers237-56ac", - "rxRate": 100, - "txRate": 97 - }, - { - "name": "P9SFCiutatGranada73-68f5", - "rxRate": 100, - "txRate": 97 - } - ] + "name": "P9SFCastanys31-1663", + "links": [ + { + "name": "P9SFAlmogavers237-56ac", + "rxRate": 100, + "txRate": 97 + }, + { + "name": "P9SFCiutatGranada73-68f5", + "rxRate": 100, + "txRate": 97 + } + ] }, { - "name": "P9SFCiutatGranada73-68f5", - "links": [ - { - "name": "P9SFDrTruetaa183-b713", - "rxRate": 93, - "txRate": 59 - }, - { - "name": "PP9SFCastanys31-1663", - "rxRate": 93, - "txRate": 59 - } - ] + "name": "P9SFCiutatGranada73-68f5", + "links": [ + { + "name": "P9SFDrTruetaa183-b713", + "rxRate": 93, + "txRate": 59 + }, + { + "name": "PP9SFCastanys31-1663", + "rxRate": 93, + "txRate": 59 + } + ] }, { "name": "P9SFDrTruetaa183-b713", diff --git a/tests/static/netjson-2-links.json b/tests/static/netjson-2-links.json index e5ebe1d..2e81a53 100644 --- a/tests/static/netjson-2-links.json +++ b/tests/static/netjson-2-links.json @@ -1,56 +1,50 @@ { - "type": "NetworkGraph", - "protocol": "OLSR", - "version": "0.6.6", - "revision": "5031a799fcbe17f61d57e387bc3806de", - "metric": "ETX", - "nodes": [ - { - "id": "10.150.0.3", - "local_addresses": [ - "192.168.1.3" - ], - "label": "nodeA", - "properties": { - "hostname": "router.3nnx" - } - }, - { - "id": "10.150.0.2", - "local_addresses": [ - "192.168.1.2" - ], - "label": "nodeB", - "properties": { - "hostname": "router2.nnx" - } - }, - { - "id": "10.150.0.4", - "local_addresses": [ - "192.168.1.3" - ], - "properties": { - "hostname": "router4.nnx" - } - } - ], - "links": [ - { - "source": "10.150.0.3", - "target": "10.150.0.2", - "cost": 28334, - "properties": { - "custom_property": true - } - }, - { - "source": "10.150.0.3", - "target": "10.150.0.4", - "cost": 1024, - "properties": { - "custom_property": true - } - } - ] + "type": "NetworkGraph", + "protocol": "OLSR", + "version": "0.6.6", + "revision": "5031a799fcbe17f61d57e387bc3806de", + "metric": "ETX", + "nodes": [ + { + "id": "10.150.0.3", + "local_addresses": ["192.168.1.3"], + "label": "nodeA", + "properties": { + "hostname": "router.3nnx" + } + }, + { + "id": "10.150.0.2", + "local_addresses": ["192.168.1.2"], + "label": "nodeB", + "properties": { + "hostname": "router2.nnx" + } + }, + { + "id": "10.150.0.4", + "local_addresses": ["192.168.1.3"], + "properties": { + "hostname": "router4.nnx" + } + } + ], + "links": [ + { + "source": "10.150.0.3", + "target": "10.150.0.2", + "cost": 28334, + "properties": { + "custom_property": true + } + }, + { + "source": "10.150.0.3", + "target": "10.150.0.4", + "cost": 1024, + "properties": { + "custom_property": true + } + } + ] } diff --git a/tests/static/netjson-3-links.json b/tests/static/netjson-3-links.json index fedf13a..eb5c1ee 100644 --- a/tests/static/netjson-3-links.json +++ b/tests/static/netjson-3-links.json @@ -1,42 +1,42 @@ { - "type": "NetworkGraph", - "protocol": "OLSR", - "version": "0.6.6", - "revision": "5031a799fcbe17f61d57e387bc3806de", - "metric": "ETX", - "nodes": [ - { - "id": "10.150.0.3" - }, - { - "id": "10.150.0.2" - }, - { - "id": "10.150.0.5" - }, - { - "id": "10.150.0.4" - } - ], - "links": [ - { - "source": "10.150.0.3", - "target": "10.150.0.2", - "cost": 28334, - "properties": { - "custom_property": false, - "foo": "bar" - } - }, - { - "source": "10.150.0.3", - "target": "10.150.0.4", - "cost": 1048 - }, - { - "source": "10.150.0.5", - "target": "10.150.0.4", - "cost": 1024 - } - ] + "type": "NetworkGraph", + "protocol": "OLSR", + "version": "0.6.6", + "revision": "5031a799fcbe17f61d57e387bc3806de", + "metric": "ETX", + "nodes": [ + { + "id": "10.150.0.3" + }, + { + "id": "10.150.0.2" + }, + { + "id": "10.150.0.5" + }, + { + "id": "10.150.0.4" + } + ], + "links": [ + { + "source": "10.150.0.3", + "target": "10.150.0.2", + "cost": 28334, + "properties": { + "custom_property": false, + "foo": "bar" + } + }, + { + "source": "10.150.0.3", + "target": "10.150.0.4", + "cost": 1048 + }, + { + "source": "10.150.0.5", + "target": "10.150.0.4", + "cost": 1024 + } + ] } diff --git a/tests/static/netjson-nodes-1.json b/tests/static/netjson-nodes-1.json index d96f327..61003e2 100644 --- a/tests/static/netjson-nodes-1.json +++ b/tests/static/netjson-nodes-1.json @@ -1,52 +1,48 @@ { - "type": "NetworkGraph", - "protocol": "OLSR", - "version": "0.6.6", - "revision": "5031a799fcbe17f61d57e387bc3806de", - "metric": "ETX", - "nodes": [ - { - "id": "10.150.0.3", - "local_addresses": [ - "192.168.1.3" - ], - "label": "nodeA", - "properties": { - "hostname": "router.3nnx" - } - }, - { - "id": "10.150.0.2", - "local_addresses": [ - "192.168.1.2" - ], - "label": "nodeB", - "properties": { - "hostname": "router2.nnx" - } - }, - { - "id": "10.150.0.4" - } - ], - "links": [ - { - "source": "10.150.0.3", - "target": "10.150.0.2", - "cost": 28334, - "properties": { - "custom_property": false, - "foo": "bar" - } - }, - { - "source": "10.150.0.3", - "target": "10.150.0.4", - "cost": 1048, - "cost_text": "Slow link", - "properties": { - "custom_property": true - } - } - ] + "type": "NetworkGraph", + "protocol": "OLSR", + "version": "0.6.6", + "revision": "5031a799fcbe17f61d57e387bc3806de", + "metric": "ETX", + "nodes": [ + { + "id": "10.150.0.3", + "local_addresses": ["192.168.1.3"], + "label": "nodeA", + "properties": { + "hostname": "router.3nnx" + } + }, + { + "id": "10.150.0.2", + "local_addresses": ["192.168.1.2"], + "label": "nodeB", + "properties": { + "hostname": "router2.nnx" + } + }, + { + "id": "10.150.0.4" + } + ], + "links": [ + { + "source": "10.150.0.3", + "target": "10.150.0.2", + "cost": 28334, + "properties": { + "custom_property": false, + "foo": "bar" + } + }, + { + "source": "10.150.0.3", + "target": "10.150.0.4", + "cost": 1048, + "cost_text": "Slow link", + "properties": { + "custom_property": true + } + } + ] } diff --git a/tests/static/netjson-nodes-2.json b/tests/static/netjson-nodes-2.json index fa83d15..c615268 100644 --- a/tests/static/netjson-nodes-2.json +++ b/tests/static/netjson-nodes-2.json @@ -1,52 +1,50 @@ { - "type": "NetworkGraph", - "protocol": "OLSR", - "version": "0.6.6", - "revision": "5031a799fcbe17f61d57e387bc3806de", - "metric": "ETX", - "nodes": [ - { - "id": "10.150.0.3", - "label": "nodeA2", - "properties": { - "hostname": "router.2nnx", - "contact": "me@project.com", - "input_octets": 85331213, - "output_octets": 4358710 - } - }, - { - "id": "10.150.0.2" - }, - { - "id": "10.150.0.4", - "local_addresses": [ - "192.168.1.3" - ], - "properties": { - "hostname": "router4.nnx" - } - }, - { - "id": "10.150.0.5", - "label": "node5" - } - ], - "links": [ - { - "source": "10.150.0.3", - "target": "10.150.0.2", - "cost": 28334, - "cost_text": "Fast link", - "properties": { - "custom_property": true, - "foo": "bar" - } - }, - { - "source": "10.150.0.3", - "target": "10.150.0.4", - "cost": 1048 - } - ] + "type": "NetworkGraph", + "protocol": "OLSR", + "version": "0.6.6", + "revision": "5031a799fcbe17f61d57e387bc3806de", + "metric": "ETX", + "nodes": [ + { + "id": "10.150.0.3", + "label": "nodeA2", + "properties": { + "hostname": "router.2nnx", + "contact": "me@project.com", + "input_octets": 85331213, + "output_octets": 4358710 + } + }, + { + "id": "10.150.0.2" + }, + { + "id": "10.150.0.4", + "local_addresses": ["192.168.1.3"], + "properties": { + "hostname": "router4.nnx" + } + }, + { + "id": "10.150.0.5", + "label": "node5" + } + ], + "links": [ + { + "source": "10.150.0.3", + "target": "10.150.0.2", + "cost": 28334, + "cost_text": "Fast link", + "properties": { + "custom_property": true, + "foo": "bar" + } + }, + { + "source": "10.150.0.3", + "target": "10.150.0.4", + "cost": 1048 + } + ] } diff --git a/tests/static/olsr-2-links-cost-changed.json b/tests/static/olsr-2-links-cost-changed.json index 617aad9..7aa80c8 100644 --- a/tests/static/olsr-2-links-cost-changed.json +++ b/tests/static/olsr-2-links-cost-changed.json @@ -1,115 +1,115 @@ { - "topology": [ - { - "lastHopIP": "10.150.0.2", - "destinationIP": "10.150.0.3", - "linkQuality": 0.195, - "neighborLinkQuality": 0.184, - "tcEdgeCost": 1334, - "validityTime": 284572 - }, - { - "lastHopIP": "10.150.0.3", - "destinationIP": "10.150.0.4", - "linkQuality": 1.0, - "neighborLinkQuality": 1.0, - "tcEdgeCost": 1048, - "validityTime": 284572 - } - ], - "mid": [], - "config": { - "olsrPort":698, - "debugLevel":0, - "noFork":false, - "hostEmulation":false, - "ipVersion":2, - "allowNoInterfaces":true, - "typeOfService":192, - "rtProto":3, - "rtTable":222, - "rtTableDefault":223, - "rtTableTunnel":223, - "rtTablePriority":-1, - "rtTableTunnelPriority":-1, - "rtTableDefauiltOlsrPriority":-1, - "rtTableDefaultPriority":-1, - "willingness":3, - "willingnessAuto":false, - "brokenLinkCost":4194304, - "brokenRouteCost":-1, - "fibMetrics":"flat", - "defaultIpv6Multicast":"ff02::6d", - "defaultIpv4Broadcast":"auto", - "defaultInterfaceMode":"mesh", - "defaultHelloEmissionInterval":2.000, - "defaultHelloValidityTime":20.000, - "defaultTcEmissionInterval":5.000, - "defaultTcValidityTime":300.000, - "defaultMidEmissionInterval":5.000, - "defaultMidValidityTime":300.000, - "defaultHnaEmissionInterval":5.000, - "defaultHnaValidityTime":300.000, - "defaultAutoDetectChanges":true, - "defaultLinkQualityMultipliers":[], - "hna":[ - { - "destination":"10.176.0.128", - "genmask":25, - "gateway":"10.0.1.77" - } - ], - "totalIpcConnectionsAllowed":0, - "ipcAllowedAddresses":[], - "pollRate":50, - "nicChangePollInterval":2500, - "clearScreen":true, - "tcRedundancy":2, - "mprCoverage":7, - "linkQualityLevel":2, - "linkQualityAging":0.050, - "linkQualityFisheye":true, - "linkQualityAlgorithm":"(null)", - "minTcValidTime":0, - "setIpForward":true, - "lockFile":"(null)", - "useNiit":false, - "smartGateway":false, - "mainIpAddress":"10.0.1.77", - "unicastSourceIpAddress":"10.0.1.77", - "useSourceIpRoutes":false, - "maxPrefixLength":32, - "ipSize":4, - "deleteInternetGatewaysAtStartup":false, - "willingnessUpdateInterval":20000, - "maxSendMessageJitter":2.000, - "exitValue":0, - "maxTcValidTime":5000, - "niit4to6InterfaceIndex":0, - "niit6to4InterfaceIndex":0, - "hasIpv4Gateway":false, - "hasIpv6Gateway":false, - "ioctlSocket":3, - "routeNetlinkSocket":4, - "routeMonitorSocket":5, - "linkQualityNatThreshold":1.000, - "olsrdVersion":"olsr.org - 0.6.6-git_0000000-hash_5031a799fcbe17f61d57e387bc3806de", - "olsrdBuildDate":"2014-09-16 15:55:12", - "olsrdBuildHost":"tlaloc", - "os":"GNU/Linux", - "startTime":1430048863 + "topology": [ + { + "lastHopIP": "10.150.0.2", + "destinationIP": "10.150.0.3", + "linkQuality": 0.195, + "neighborLinkQuality": 0.184, + "tcEdgeCost": 1334, + "validityTime": 284572 }, - "plugins": [ - { - "plugin":"olsrd_jsoninfo.so.0.0", - "accept":"0.0.0.0", - "port":9090 - }, - { - "plugin":"olsrd_txtinfo.so.0.1", - "accept":"0.0.0.0" - } + { + "lastHopIP": "10.150.0.3", + "destinationIP": "10.150.0.4", + "linkQuality": 1.0, + "neighborLinkQuality": 1.0, + "tcEdgeCost": 1048, + "validityTime": 284572 + } + ], + "mid": [], + "config": { + "olsrPort": 698, + "debugLevel": 0, + "noFork": false, + "hostEmulation": false, + "ipVersion": 2, + "allowNoInterfaces": true, + "typeOfService": 192, + "rtProto": 3, + "rtTable": 222, + "rtTableDefault": 223, + "rtTableTunnel": 223, + "rtTablePriority": -1, + "rtTableTunnelPriority": -1, + "rtTableDefauiltOlsrPriority": -1, + "rtTableDefaultPriority": -1, + "willingness": 3, + "willingnessAuto": false, + "brokenLinkCost": 4194304, + "brokenRouteCost": -1, + "fibMetrics": "flat", + "defaultIpv6Multicast": "ff02::6d", + "defaultIpv4Broadcast": "auto", + "defaultInterfaceMode": "mesh", + "defaultHelloEmissionInterval": 2.0, + "defaultHelloValidityTime": 20.0, + "defaultTcEmissionInterval": 5.0, + "defaultTcValidityTime": 300.0, + "defaultMidEmissionInterval": 5.0, + "defaultMidValidityTime": 300.0, + "defaultHnaEmissionInterval": 5.0, + "defaultHnaValidityTime": 300.0, + "defaultAutoDetectChanges": true, + "defaultLinkQualityMultipliers": [], + "hna": [ + { + "destination": "10.176.0.128", + "genmask": 25, + "gateway": "10.0.1.77" + } ], - "systemTime":1430572557, - "timeSinceStartup":523790030 + "totalIpcConnectionsAllowed": 0, + "ipcAllowedAddresses": [], + "pollRate": 50, + "nicChangePollInterval": 2500, + "clearScreen": true, + "tcRedundancy": 2, + "mprCoverage": 7, + "linkQualityLevel": 2, + "linkQualityAging": 0.05, + "linkQualityFisheye": true, + "linkQualityAlgorithm": "(null)", + "minTcValidTime": 0, + "setIpForward": true, + "lockFile": "(null)", + "useNiit": false, + "smartGateway": false, + "mainIpAddress": "10.0.1.77", + "unicastSourceIpAddress": "10.0.1.77", + "useSourceIpRoutes": false, + "maxPrefixLength": 32, + "ipSize": 4, + "deleteInternetGatewaysAtStartup": false, + "willingnessUpdateInterval": 20000, + "maxSendMessageJitter": 2.0, + "exitValue": 0, + "maxTcValidTime": 5000, + "niit4to6InterfaceIndex": 0, + "niit6to4InterfaceIndex": 0, + "hasIpv4Gateway": false, + "hasIpv6Gateway": false, + "ioctlSocket": 3, + "routeNetlinkSocket": 4, + "routeMonitorSocket": 5, + "linkQualityNatThreshold": 1.0, + "olsrdVersion": "olsr.org - 0.6.6-git_0000000-hash_5031a799fcbe17f61d57e387bc3806de", + "olsrdBuildDate": "2014-09-16 15:55:12", + "olsrdBuildHost": "tlaloc", + "os": "GNU/Linux", + "startTime": 1430048863 + }, + "plugins": [ + { + "plugin": "olsrd_jsoninfo.so.0.0", + "accept": "0.0.0.0", + "port": 9090 + }, + { + "plugin": "olsrd_txtinfo.so.0.1", + "accept": "0.0.0.0" + } + ], + "systemTime": 1430572557, + "timeSinceStartup": 523790030 } diff --git a/tests/static/olsr-2-links-newformat.json b/tests/static/olsr-2-links-newformat.json index d5705a2..2237742 100644 --- a/tests/static/olsr-2-links-newformat.json +++ b/tests/static/olsr-2-links-newformat.json @@ -1,193 +1,193 @@ { - "topology": [ + "topology": [ + { + "lastHopIP": "10.150.0.2", + "destinationIP": "10.150.0.3", + "linkQuality": 0.195, + "neighborLinkQuality": 0.184, + "tcEdgeCost": 28334, + "validityTime": 284572 + }, + { + "lastHopIP": "10.150.0.3", + "destinationIP": "10.150.0.4", + "linkQuality": 1.0, + "neighborLinkQuality": 1.0, + "tcEdgeCost": 1024, + "validityTime": 284572 + } + ], + "mid": [ + { + "main": { + "ipAddress": "10.150.0.2", + "validityTime": 286445 + }, + "aliases": [ { - "lastHopIP": "10.150.0.2", - "destinationIP": "10.150.0.3", - "linkQuality": 0.195, - "neighborLinkQuality": 0.184, - "tcEdgeCost": 28334, - "validityTime": 284572 + "ipAddress": "172.16.192.2", + "validityTime": 286445 }, { - "lastHopIP": "10.150.0.3", - "destinationIP": "10.150.0.4", - "linkQuality": 1.0, - "neighborLinkQuality": 1.0, - "tcEdgeCost": 1024, - "validityTime": 284572 + "ipAddress": "192.168.0.2", + "validityTime": 286445 } - ], - "mid": [ - { - "main": { - "ipAddress": "10.150.0.2", - "validityTime": 286445 - }, - "aliases": [ - { - "ipAddress": "172.16.192.2", - "validityTime": 286445 - }, - { - "ipAddress": "192.168.0.2", - "validityTime": 286445 - } - ] - }, - { - "main": { - "ipAddress": "10.150.0.3", - "validityTime": 286445 - }, - "aliases": [ - { - "ipAddress": "172.16.192.3", - "validityTime": 286445 - } - ] - }, + ] + }, + { + "main": { + "ipAddress": "10.150.0.3", + "validityTime": 286445 + }, + "aliases": [ { - "main": { - "ipAddress": "10.150.0.4", - "validityTime": 286445 - }, - "aliases": [ - { - "ipAddress": "172.16.192.4", - "validityTime": 286445 - } - ] + "ipAddress": "172.16.192.3", + "validityTime": 286445 } - ], - "version": { - "version": "olsr.org - 0.6.6-git_0000000-hash_5031a799fcbe17f61d57e387bc3806de", - "gitDescriptor": "", - "gitSha": "0000000000000000000000000000000000000000", - "releaseVersion": "0.6.6", - "sourceHash": "5031a799fcbe17f61d57e387bc3806de" + ] }, - "config": { - "olsrPort":698, - "debugLevel":0, - "noFork":false, - "pidFile": "", - "hostEmulation":false, - "ipVersion":2, - "allowNoInt": true, - "tosValue": 192, - "rtProto":3, - "rtTable": { - "main": 222, - "default": 223, - "tunnel": 223, - "priority": -1, - "tunnelPriority": -1, - "defaultOlsrPriority": -1, - "defaultPriority": -1 - }, - "willingness": { - "willingness": 3, - "auto": false, - "updateInterval": 20 - }, - "brokenLinkCost":4194304, - "brokenRouteCost":-1, - "fib": { - "metric": "flat", - "metricDefault": "approx" - }, - "hna": [ - { - "destination":"10.176.0.128", - "genmask":25, - "gateway":"10.0.1.77", - "validityTime": 0 - } - ], - "interfaceDefaults": { - "ipv4Broadcast": "255.255.255.255", - "ipv6Multicast": "ff02::6d", - "ipv4Source": "0.0.0.0", - "ipv6Source": "0.0.0.0", - "ipv6SourcePrefixLength": 0, - "mode": "mesh", - "weightValue": 0, - "weightFixed": false, - "hello": { - "emissionInterval": 5, - "validityTime": 100 - }, - "tc": { - "emissionInterval": 3, - "validityTime": 500 - }, - "mid": { - "emissionInterval": 30, - "validityTime": 500 - }, - "hna": { - "emissionInterval": 30, - "validityTime": 500 - }, - "linkQualityMultipliers": [], - "linkQualityMultipliersCount": 0, - "autoDetectChanges": true - }, - "ipcConnectMaxConnections": 0, - "ipcConnectAllowed": [], - "pollRate":50, - "nicChgsPollInt": 2.5, - "clearScreen":true, - "tcRedundancy":2, - "mprCoverage":7, - "linkQuality": { - "level": 2, - "fishEye": true, - "aging": 0.05, - "algorithm": "(null)" - }, - "minTCVTime": 0, - "setIpForward":true, - "lockFile":"(null)", - "useNiit":false, - "smartGateway": { - "enabled": false - }, - "mainIp":"10.0.1.77", - "unicastSourceIpAddress":"10.0.1.77", - "srcIpRoutes":false, - "maxPrefixLength":32, - "ipSize":4, - "delgw":false, - "maxSendMessageJitter":2.000, - "exitValue":0, - "maxTcValidTime":5000, - "niit4to6InterfaceIndex":0, - "niit6to4InterfaceIndex":0, - "hasIpv4Gateway":false, - "hasIpv6Gateway":false, - "ioctlSocket":3, - "routeNetlinkSocket":4, - "routeMonitorSocket":5, - "linkQualityNatThreshold":1.000, - "os":"GNU/Linux", - "startTime":1430048863 - }, - "plugins": [ + { + "main": { + "ipAddress": "10.150.0.4", + "validityTime": 286445 + }, + "aliases": [ { - "plugin": "olsrd_jsoninfo.so.1.1", - "parameters": { - "accept": "0.0.0.0", - "port": "9090" - } - }, - { - "plugin": "olsrd_txtinfo.so.0.1", - "parameters": { - "accept": "0.0.0.0" - } + "ipAddress": "172.16.192.4", + "validityTime": 286445 } + ] + } + ], + "version": { + "version": "olsr.org - 0.6.6-git_0000000-hash_5031a799fcbe17f61d57e387bc3806de", + "gitDescriptor": "", + "gitSha": "0000000000000000000000000000000000000000", + "releaseVersion": "0.6.6", + "sourceHash": "5031a799fcbe17f61d57e387bc3806de" + }, + "config": { + "olsrPort": 698, + "debugLevel": 0, + "noFork": false, + "pidFile": "", + "hostEmulation": false, + "ipVersion": 2, + "allowNoInt": true, + "tosValue": 192, + "rtProto": 3, + "rtTable": { + "main": 222, + "default": 223, + "tunnel": 223, + "priority": -1, + "tunnelPriority": -1, + "defaultOlsrPriority": -1, + "defaultPriority": -1 + }, + "willingness": { + "willingness": 3, + "auto": false, + "updateInterval": 20 + }, + "brokenLinkCost": 4194304, + "brokenRouteCost": -1, + "fib": { + "metric": "flat", + "metricDefault": "approx" + }, + "hna": [ + { + "destination": "10.176.0.128", + "genmask": 25, + "gateway": "10.0.1.77", + "validityTime": 0 + } ], - "systemTime":1430572557, - "timeSinceStartup":523790030 + "interfaceDefaults": { + "ipv4Broadcast": "255.255.255.255", + "ipv6Multicast": "ff02::6d", + "ipv4Source": "0.0.0.0", + "ipv6Source": "0.0.0.0", + "ipv6SourcePrefixLength": 0, + "mode": "mesh", + "weightValue": 0, + "weightFixed": false, + "hello": { + "emissionInterval": 5, + "validityTime": 100 + }, + "tc": { + "emissionInterval": 3, + "validityTime": 500 + }, + "mid": { + "emissionInterval": 30, + "validityTime": 500 + }, + "hna": { + "emissionInterval": 30, + "validityTime": 500 + }, + "linkQualityMultipliers": [], + "linkQualityMultipliersCount": 0, + "autoDetectChanges": true + }, + "ipcConnectMaxConnections": 0, + "ipcConnectAllowed": [], + "pollRate": 50, + "nicChgsPollInt": 2.5, + "clearScreen": true, + "tcRedundancy": 2, + "mprCoverage": 7, + "linkQuality": { + "level": 2, + "fishEye": true, + "aging": 0.05, + "algorithm": "(null)" + }, + "minTCVTime": 0, + "setIpForward": true, + "lockFile": "(null)", + "useNiit": false, + "smartGateway": { + "enabled": false + }, + "mainIp": "10.0.1.77", + "unicastSourceIpAddress": "10.0.1.77", + "srcIpRoutes": false, + "maxPrefixLength": 32, + "ipSize": 4, + "delgw": false, + "maxSendMessageJitter": 2.0, + "exitValue": 0, + "maxTcValidTime": 5000, + "niit4to6InterfaceIndex": 0, + "niit6to4InterfaceIndex": 0, + "hasIpv4Gateway": false, + "hasIpv6Gateway": false, + "ioctlSocket": 3, + "routeNetlinkSocket": 4, + "routeMonitorSocket": 5, + "linkQualityNatThreshold": 1.0, + "os": "GNU/Linux", + "startTime": 1430048863 + }, + "plugins": [ + { + "plugin": "olsrd_jsoninfo.so.1.1", + "parameters": { + "accept": "0.0.0.0", + "port": "9090" + } + }, + { + "plugin": "olsrd_txtinfo.so.0.1", + "parameters": { + "accept": "0.0.0.0" + } + } + ], + "systemTime": 1430572557, + "timeSinceStartup": 523790030 } diff --git a/tests/static/olsr-2-links.json b/tests/static/olsr-2-links.json index 20932b9..0ed7d08 100644 --- a/tests/static/olsr-2-links.json +++ b/tests/static/olsr-2-links.json @@ -1,147 +1,147 @@ { - "topology": [ + "topology": [ + { + "lastHopIP": "10.150.0.2", + "destinationIP": "10.150.0.3", + "linkQuality": 0.195, + "neighborLinkQuality": 0.184, + "tcEdgeCost": 28334, + "validityTime": 284572 + }, + { + "lastHopIP": "10.150.0.3", + "destinationIP": "10.150.0.4", + "linkQuality": 1.0, + "neighborLinkQuality": 1.0, + "tcEdgeCost": 1024, + "validityTime": 284572 + } + ], + "mid": [ + { + "ipAddress": "10.150.0.2", + "aliases": [ { - "lastHopIP": "10.150.0.2", - "destinationIP": "10.150.0.3", - "linkQuality": 0.195, - "neighborLinkQuality": 0.184, - "tcEdgeCost": 28334, - "validityTime": 284572 + "ipAddress": "172.16.192.2", + "validityTime": 286445 }, { - "lastHopIP": "10.150.0.3", - "destinationIP": "10.150.0.4", - "linkQuality": 1.0, - "neighborLinkQuality": 1.0, - "tcEdgeCost": 1024, - "validityTime": 284572 + "ipAddress": "192.168.0.2", + "validityTime": 286445 } - ], - "mid": [ - { - "ipAddress": "10.150.0.2", - "aliases": [ - { - "ipAddress": "172.16.192.2", - "validityTime": 286445 - }, - { - "ipAddress": "192.168.0.2", - "validityTime": 286445 - } - ] - }, - { - "ipAddress": "10.150.0.3", - "aliases": [ - { - "ipAddress": "172.16.192.3", - "validityTime": 286445 - } - ] - }, + ] + }, + { + "ipAddress": "10.150.0.3", + "aliases": [ { - "ipAddress": "10.150.0.4", - "aliases": [ - { - "ipAddress": "172.16.192.4", - "validityTime": 286445 - } - ] + "ipAddress": "172.16.192.3", + "validityTime": 286445 } - ], - "config": { - "olsrPort":698, - "debugLevel":0, - "noFork":false, - "hostEmulation":false, - "ipVersion":2, - "allowNoInterfaces":true, - "typeOfService":192, - "rtProto":3, - "rtTable":222, - "rtTableDefault":223, - "rtTableTunnel":223, - "rtTablePriority":-1, - "rtTableTunnelPriority":-1, - "rtTableDefauiltOlsrPriority":-1, - "rtTableDefaultPriority":-1, - "willingness":3, - "willingnessAuto":false, - "brokenLinkCost":4194304, - "brokenRouteCost":-1, - "fibMetrics":"flat", - "defaultIpv6Multicast":"ff02::6d", - "defaultIpv4Broadcast":"auto", - "defaultInterfaceMode":"mesh", - "defaultHelloEmissionInterval":2.000, - "defaultHelloValidityTime":20.000, - "defaultTcEmissionInterval":5.000, - "defaultTcValidityTime":300.000, - "defaultMidEmissionInterval":5.000, - "defaultMidValidityTime":300.000, - "defaultHnaEmissionInterval":5.000, - "defaultHnaValidityTime":300.000, - "defaultAutoDetectChanges":true, - "defaultLinkQualityMultipliers":[], - "hna":[ - { - "destination":"10.176.0.128", - "genmask":25, - "gateway":"10.0.1.77" - } - ], - "totalIpcConnectionsAllowed":0, - "ipcAllowedAddresses":[], - "pollRate":50, - "nicChangePollInterval":2500, - "clearScreen":true, - "tcRedundancy":2, - "mprCoverage":7, - "linkQualityLevel":2, - "linkQualityAging":0.050, - "linkQualityFisheye":true, - "linkQualityAlgorithm":"(null)", - "minTcValidTime":0, - "setIpForward":true, - "lockFile":"(null)", - "useNiit":false, - "smartGateway":false, - "mainIpAddress":"10.0.1.77", - "unicastSourceIpAddress":"10.0.1.77", - "useSourceIpRoutes":false, - "maxPrefixLength":32, - "ipSize":4, - "deleteInternetGatewaysAtStartup":false, - "willingnessUpdateInterval":20000, - "maxSendMessageJitter":2.000, - "exitValue":0, - "maxTcValidTime":5000, - "niit4to6InterfaceIndex":0, - "niit6to4InterfaceIndex":0, - "hasIpv4Gateway":false, - "hasIpv6Gateway":false, - "ioctlSocket":3, - "routeNetlinkSocket":4, - "routeMonitorSocket":5, - "linkQualityNatThreshold":1.000, - "olsrdVersion":"olsr.org - 0.6.6-git_0000000-hash_5031a799fcbe17f61d57e387bc3806de", - "olsrdBuildDate":"2014-09-16 15:55:12", - "olsrdBuildHost":"tlaloc", - "os":"GNU/Linux", - "startTime":1430048863 + ] }, - "plugins": [ + { + "ipAddress": "10.150.0.4", + "aliases": [ { - "plugin":"olsrd_jsoninfo.so.0.0", - "accept":"0.0.0.0", - "port":9090 - }, - { - "plugin":"olsrd_txtinfo.so.0.1", - "accept":"0.0.0.0" + "ipAddress": "172.16.192.4", + "validityTime": 286445 } + ] + } + ], + "config": { + "olsrPort": 698, + "debugLevel": 0, + "noFork": false, + "hostEmulation": false, + "ipVersion": 2, + "allowNoInterfaces": true, + "typeOfService": 192, + "rtProto": 3, + "rtTable": 222, + "rtTableDefault": 223, + "rtTableTunnel": 223, + "rtTablePriority": -1, + "rtTableTunnelPriority": -1, + "rtTableDefauiltOlsrPriority": -1, + "rtTableDefaultPriority": -1, + "willingness": 3, + "willingnessAuto": false, + "brokenLinkCost": 4194304, + "brokenRouteCost": -1, + "fibMetrics": "flat", + "defaultIpv6Multicast": "ff02::6d", + "defaultIpv4Broadcast": "auto", + "defaultInterfaceMode": "mesh", + "defaultHelloEmissionInterval": 2.0, + "defaultHelloValidityTime": 20.0, + "defaultTcEmissionInterval": 5.0, + "defaultTcValidityTime": 300.0, + "defaultMidEmissionInterval": 5.0, + "defaultMidValidityTime": 300.0, + "defaultHnaEmissionInterval": 5.0, + "defaultHnaValidityTime": 300.0, + "defaultAutoDetectChanges": true, + "defaultLinkQualityMultipliers": [], + "hna": [ + { + "destination": "10.176.0.128", + "genmask": 25, + "gateway": "10.0.1.77" + } ], - "systemTime":1430572557, - "timeSinceStartup":523790030 + "totalIpcConnectionsAllowed": 0, + "ipcAllowedAddresses": [], + "pollRate": 50, + "nicChangePollInterval": 2500, + "clearScreen": true, + "tcRedundancy": 2, + "mprCoverage": 7, + "linkQualityLevel": 2, + "linkQualityAging": 0.05, + "linkQualityFisheye": true, + "linkQualityAlgorithm": "(null)", + "minTcValidTime": 0, + "setIpForward": true, + "lockFile": "(null)", + "useNiit": false, + "smartGateway": false, + "mainIpAddress": "10.0.1.77", + "unicastSourceIpAddress": "10.0.1.77", + "useSourceIpRoutes": false, + "maxPrefixLength": 32, + "ipSize": 4, + "deleteInternetGatewaysAtStartup": false, + "willingnessUpdateInterval": 20000, + "maxSendMessageJitter": 2.0, + "exitValue": 0, + "maxTcValidTime": 5000, + "niit4to6InterfaceIndex": 0, + "niit6to4InterfaceIndex": 0, + "hasIpv4Gateway": false, + "hasIpv6Gateway": false, + "ioctlSocket": 3, + "routeNetlinkSocket": 4, + "routeMonitorSocket": 5, + "linkQualityNatThreshold": 1.0, + "olsrdVersion": "olsr.org - 0.6.6-git_0000000-hash_5031a799fcbe17f61d57e387bc3806de", + "olsrdBuildDate": "2014-09-16 15:55:12", + "olsrdBuildHost": "tlaloc", + "os": "GNU/Linux", + "startTime": 1430048863 + }, + "plugins": [ + { + "plugin": "olsrd_jsoninfo.so.0.0", + "accept": "0.0.0.0", + "port": 9090 + }, + { + "plugin": "olsrd_txtinfo.so.0.1", + "accept": "0.0.0.0" + } + ], + "systemTime": 1430572557, + "timeSinceStartup": 523790030 } diff --git a/tests/static/olsr-3-links.json b/tests/static/olsr-3-links.json index 6414f43..417ab89 100644 --- a/tests/static/olsr-3-links.json +++ b/tests/static/olsr-3-links.json @@ -1,29 +1,29 @@ { - "topology": [ - { - "destinationIP": "10.150.0.2", - "lastHopIP": "10.150.0.3", - "linkQuality": 0.195, - "neighborLinkQuality": 0.184, - "tcEdgeCost": 28334, - "validityTime": 284572 - }, - { - "destinationIP": "10.150.0.3", - "lastHopIP": "10.150.0.4", - "linkQuality": 1, - "neighborLinkQuality": 1, - "tcEdgeCost": 1024, - "validityTime": 284572 - }, - { - "destinationIP": "10.150.0.4", - "lastHopIP": "10.150.0.5", - "linkQuality": 1, - "neighborLinkQuality": 1, - "tcEdgeCost": 1024, - "validityTime": 284572 - } - ], - "mid": [] + "topology": [ + { + "destinationIP": "10.150.0.2", + "lastHopIP": "10.150.0.3", + "linkQuality": 0.195, + "neighborLinkQuality": 0.184, + "tcEdgeCost": 28334, + "validityTime": 284572 + }, + { + "destinationIP": "10.150.0.3", + "lastHopIP": "10.150.0.4", + "linkQuality": 1, + "neighborLinkQuality": 1, + "tcEdgeCost": 1024, + "validityTime": 284572 + }, + { + "destinationIP": "10.150.0.4", + "lastHopIP": "10.150.0.5", + "linkQuality": 1, + "neighborLinkQuality": 1, + "tcEdgeCost": 1024, + "validityTime": 284572 + } + ], + "mid": [] } diff --git a/tests/static/olsr-5-links-cost-changed.json b/tests/static/olsr-5-links-cost-changed.json index ffc56da..0a08f65 100644 --- a/tests/static/olsr-5-links-cost-changed.json +++ b/tests/static/olsr-5-links-cost-changed.json @@ -1,139 +1,139 @@ { - "topology": [ - { - "destinationIP": "10.150.0.2", - "lastHopIP": "10.150.0.3", - "linkQuality": 0.195, - "neighborLinkQuality": 0.184, - "tcEdgeCost": 1024, - "validityTime": 284572 - }, - { - "destinationIP": "10.150.0.3", - "lastHopIP": "10.150.0.4", - "linkQuality": 1.0, - "neighborLinkQuality": 1.0, - "tcEdgeCost": 2048, - "validityTime": 284572 - }, - { - "destinationIP": "10.150.0.6", - "lastHopIP": "10.150.0.3", - "linkQuality": 1.0, - "neighborLinkQuality": 1.0, - "tcEdgeCost": 1024, - "validityTime": 284572 - }, - { - "destinationIP": "10.150.0.7", - "lastHopIP": "10.150.0.3", - "linkQuality": 1.0, - "neighborLinkQuality": 1.0, - "tcEdgeCost": 1540, - "validityTime": 284572 - }, - { - "destinationIP": "10.150.0.6", - "lastHopIP": "10.150.0.7", - "linkQuality": 1.0, - "neighborLinkQuality": 1.0, - "tcEdgeCost": 3600, - "validityTime": 284572 - } - ], - "mid": [], - "config": { - "olsrPort":698, - "debugLevel":0, - "noFork":false, - "hostEmulation":false, - "ipVersion":2, - "allowNoInterfaces":true, - "typeOfService":192, - "rtProto":3, - "rtTable":222, - "rtTableDefault":223, - "rtTableTunnel":223, - "rtTablePriority":-1, - "rtTableTunnelPriority":-1, - "rtTableDefauiltOlsrPriority":-1, - "rtTableDefaultPriority":-1, - "willingness":3, - "willingnessAuto":false, - "brokenLinkCost":4194304, - "brokenRouteCost":-1, - "fibMetrics":"flat", - "defaultIpv6Multicast":"ff02::6d", - "defaultIpv4Broadcast":"auto", - "defaultInterfaceMode":"mesh", - "defaultHelloEmissionInterval":2.000, - "defaultHelloValidityTime":20.000, - "defaultTcEmissionInterval":5.000, - "defaultTcValidityTime":300.000, - "defaultMidEmissionInterval":5.000, - "defaultMidValidityTime":300.000, - "defaultHnaEmissionInterval":5.000, - "defaultHnaValidityTime":300.000, - "defaultAutoDetectChanges":true, - "defaultLinkQualityMultipliers":[], - "hna":[ - { - "destination":"10.176.0.128", - "genmask":25, - "gateway":"10.0.1.77" - } - ], - "totalIpcConnectionsAllowed":0, - "ipcAllowedAddresses":[], - "pollRate":50, - "nicChangePollInterval":2500, - "clearScreen":true, - "tcRedundancy":2, - "mprCoverage":7, - "linkQualityLevel":2, - "linkQualityAging":0.050, - "linkQualityFisheye":true, - "linkQualityAlgorithm":"(null)", - "minTcValidTime":0, - "setIpForward":true, - "lockFile":"(null)", - "useNiit":false, - "smartGateway":false, - "mainIpAddress":"10.0.1.77", - "unicastSourceIpAddress":"10.0.1.77", - "useSourceIpRoutes":false, - "maxPrefixLength":32, - "ipSize":4, - "deleteInternetGatewaysAtStartup":false, - "willingnessUpdateInterval":20000, - "maxSendMessageJitter":2.000, - "exitValue":0, - "maxTcValidTime":5000, - "niit4to6InterfaceIndex":0, - "niit6to4InterfaceIndex":0, - "hasIpv4Gateway":false, - "hasIpv6Gateway":false, - "ioctlSocket":3, - "routeNetlinkSocket":4, - "routeMonitorSocket":5, - "linkQualityNatThreshold":1.000, - "olsrdVersion":"olsr.org - 0.6.6-git_0000000-hash_5031a799fcbe17f61d57e387bc3806de", - "olsrdBuildDate":"2014-09-16 15:55:12", - "olsrdBuildHost":"tlaloc", - "os":"GNU/Linux", - "startTime":1430048863 + "topology": [ + { + "destinationIP": "10.150.0.2", + "lastHopIP": "10.150.0.3", + "linkQuality": 0.195, + "neighborLinkQuality": 0.184, + "tcEdgeCost": 1024, + "validityTime": 284572 + }, + { + "destinationIP": "10.150.0.3", + "lastHopIP": "10.150.0.4", + "linkQuality": 1.0, + "neighborLinkQuality": 1.0, + "tcEdgeCost": 2048, + "validityTime": 284572 + }, + { + "destinationIP": "10.150.0.6", + "lastHopIP": "10.150.0.3", + "linkQuality": 1.0, + "neighborLinkQuality": 1.0, + "tcEdgeCost": 1024, + "validityTime": 284572 }, - "plugins": [ - { - "plugin":"olsrd_jsoninfo.so.0.0", - "accept":"0.0.0.0", - "port":9090 - }, - { - "plugin":"olsrd_txtinfo.so.0.1", - "accept":"0.0.0.0" - } + { + "destinationIP": "10.150.0.7", + "lastHopIP": "10.150.0.3", + "linkQuality": 1.0, + "neighborLinkQuality": 1.0, + "tcEdgeCost": 1540, + "validityTime": 284572 + }, + { + "destinationIP": "10.150.0.6", + "lastHopIP": "10.150.0.7", + "linkQuality": 1.0, + "neighborLinkQuality": 1.0, + "tcEdgeCost": 3600, + "validityTime": 284572 + } + ], + "mid": [], + "config": { + "olsrPort": 698, + "debugLevel": 0, + "noFork": false, + "hostEmulation": false, + "ipVersion": 2, + "allowNoInterfaces": true, + "typeOfService": 192, + "rtProto": 3, + "rtTable": 222, + "rtTableDefault": 223, + "rtTableTunnel": 223, + "rtTablePriority": -1, + "rtTableTunnelPriority": -1, + "rtTableDefauiltOlsrPriority": -1, + "rtTableDefaultPriority": -1, + "willingness": 3, + "willingnessAuto": false, + "brokenLinkCost": 4194304, + "brokenRouteCost": -1, + "fibMetrics": "flat", + "defaultIpv6Multicast": "ff02::6d", + "defaultIpv4Broadcast": "auto", + "defaultInterfaceMode": "mesh", + "defaultHelloEmissionInterval": 2.0, + "defaultHelloValidityTime": 20.0, + "defaultTcEmissionInterval": 5.0, + "defaultTcValidityTime": 300.0, + "defaultMidEmissionInterval": 5.0, + "defaultMidValidityTime": 300.0, + "defaultHnaEmissionInterval": 5.0, + "defaultHnaValidityTime": 300.0, + "defaultAutoDetectChanges": true, + "defaultLinkQualityMultipliers": [], + "hna": [ + { + "destination": "10.176.0.128", + "genmask": 25, + "gateway": "10.0.1.77" + } ], - "systemTime":1430572557, - "timeSinceStartup":523790030 + "totalIpcConnectionsAllowed": 0, + "ipcAllowedAddresses": [], + "pollRate": 50, + "nicChangePollInterval": 2500, + "clearScreen": true, + "tcRedundancy": 2, + "mprCoverage": 7, + "linkQualityLevel": 2, + "linkQualityAging": 0.05, + "linkQualityFisheye": true, + "linkQualityAlgorithm": "(null)", + "minTcValidTime": 0, + "setIpForward": true, + "lockFile": "(null)", + "useNiit": false, + "smartGateway": false, + "mainIpAddress": "10.0.1.77", + "unicastSourceIpAddress": "10.0.1.77", + "useSourceIpRoutes": false, + "maxPrefixLength": 32, + "ipSize": 4, + "deleteInternetGatewaysAtStartup": false, + "willingnessUpdateInterval": 20000, + "maxSendMessageJitter": 2.0, + "exitValue": 0, + "maxTcValidTime": 5000, + "niit4to6InterfaceIndex": 0, + "niit6to4InterfaceIndex": 0, + "hasIpv4Gateway": false, + "hasIpv6Gateway": false, + "ioctlSocket": 3, + "routeNetlinkSocket": 4, + "routeMonitorSocket": 5, + "linkQualityNatThreshold": 1.0, + "olsrdVersion": "olsr.org - 0.6.6-git_0000000-hash_5031a799fcbe17f61d57e387bc3806de", + "olsrdBuildDate": "2014-09-16 15:55:12", + "olsrdBuildHost": "tlaloc", + "os": "GNU/Linux", + "startTime": 1430048863 + }, + "plugins": [ + { + "plugin": "olsrd_jsoninfo.so.0.0", + "accept": "0.0.0.0", + "port": 9090 + }, + { + "plugin": "olsrd_txtinfo.so.0.1", + "accept": "0.0.0.0" + } + ], + "systemTime": 1430572557, + "timeSinceStartup": 523790030 } diff --git a/tests/static/olsr-5-links.json b/tests/static/olsr-5-links.json index 5cfe3eb..8ab6c9e 100644 --- a/tests/static/olsr-5-links.json +++ b/tests/static/olsr-5-links.json @@ -1,139 +1,139 @@ { - "topology": [ - { - "destinationIP": "10.150.0.2", - "lastHopIP": "10.150.0.3", - "linkQuality": 0.195, - "neighborLinkQuality": 0.184, - "tcEdgeCost": 28334, - "validityTime": 284572 - }, - { - "destinationIP": "10.150.0.3", - "lastHopIP": "10.150.0.4", - "linkQuality": 1.0, - "neighborLinkQuality": 1.0, - "tcEdgeCost": 1024, - "validityTime": 284572 - }, - { - "destinationIP": "10.150.0.6", - "lastHopIP": "10.150.0.3", - "linkQuality": 1.0, - "neighborLinkQuality": 1.0, - "tcEdgeCost": 1024, - "validityTime": 284572 - }, - { - "destinationIP": "10.150.0.7", - "lastHopIP": "10.150.0.3", - "linkQuality": 1.0, - "neighborLinkQuality": 1.0, - "tcEdgeCost": 1024, - "validityTime": 284572 - }, - { - "destinationIP": "10.150.0.6", - "lastHopIP": "10.150.0.7", - "linkQuality": 1.0, - "neighborLinkQuality": 1.0, - "tcEdgeCost": 1024, - "validityTime": 284572 - } - ], - "mid": [], - "config": { - "olsrPort":698, - "debugLevel":0, - "noFork":false, - "hostEmulation":false, - "ipVersion":2, - "allowNoInterfaces":true, - "typeOfService":192, - "rtProto":3, - "rtTable":222, - "rtTableDefault":223, - "rtTableTunnel":223, - "rtTablePriority":-1, - "rtTableTunnelPriority":-1, - "rtTableDefauiltOlsrPriority":-1, - "rtTableDefaultPriority":-1, - "willingness":3, - "willingnessAuto":false, - "brokenLinkCost":4194304, - "brokenRouteCost":-1, - "fibMetrics":"flat", - "defaultIpv6Multicast":"ff02::6d", - "defaultIpv4Broadcast":"auto", - "defaultInterfaceMode":"mesh", - "defaultHelloEmissionInterval":2.000, - "defaultHelloValidityTime":20.000, - "defaultTcEmissionInterval":5.000, - "defaultTcValidityTime":300.000, - "defaultMidEmissionInterval":5.000, - "defaultMidValidityTime":300.000, - "defaultHnaEmissionInterval":5.000, - "defaultHnaValidityTime":300.000, - "defaultAutoDetectChanges":true, - "defaultLinkQualityMultipliers":[], - "hna":[ - { - "destination":"10.176.0.128", - "genmask":25, - "gateway":"10.0.1.77" - } - ], - "totalIpcConnectionsAllowed":0, - "ipcAllowedAddresses":[], - "pollRate":50, - "nicChangePollInterval":2500, - "clearScreen":true, - "tcRedundancy":2, - "mprCoverage":7, - "linkQualityLevel":2, - "linkQualityAging":0.050, - "linkQualityFisheye":true, - "linkQualityAlgorithm":"(null)", - "minTcValidTime":0, - "setIpForward":true, - "lockFile":"(null)", - "useNiit":false, - "smartGateway":false, - "mainIpAddress":"10.0.1.77", - "unicastSourceIpAddress":"10.0.1.77", - "useSourceIpRoutes":false, - "maxPrefixLength":32, - "ipSize":4, - "deleteInternetGatewaysAtStartup":false, - "willingnessUpdateInterval":20000, - "maxSendMessageJitter":2.000, - "exitValue":0, - "maxTcValidTime":5000, - "niit4to6InterfaceIndex":0, - "niit6to4InterfaceIndex":0, - "hasIpv4Gateway":false, - "hasIpv6Gateway":false, - "ioctlSocket":3, - "routeNetlinkSocket":4, - "routeMonitorSocket":5, - "linkQualityNatThreshold":1.000, - "olsrdVersion":"olsr.org - 0.6.6-git_0000000-hash_5031a799fcbe17f61d57e387bc3806de", - "olsrdBuildDate":"2014-09-16 15:55:12", - "olsrdBuildHost":"tlaloc", - "os":"GNU/Linux", - "startTime":1430048863 + "topology": [ + { + "destinationIP": "10.150.0.2", + "lastHopIP": "10.150.0.3", + "linkQuality": 0.195, + "neighborLinkQuality": 0.184, + "tcEdgeCost": 28334, + "validityTime": 284572 + }, + { + "destinationIP": "10.150.0.3", + "lastHopIP": "10.150.0.4", + "linkQuality": 1.0, + "neighborLinkQuality": 1.0, + "tcEdgeCost": 1024, + "validityTime": 284572 + }, + { + "destinationIP": "10.150.0.6", + "lastHopIP": "10.150.0.3", + "linkQuality": 1.0, + "neighborLinkQuality": 1.0, + "tcEdgeCost": 1024, + "validityTime": 284572 }, - "plugins": [ - { - "plugin":"olsrd_jsoninfo.so.0.0", - "accept":"0.0.0.0", - "port":9090 - }, - { - "plugin":"olsrd_txtinfo.so.0.1", - "accept":"0.0.0.0" - } + { + "destinationIP": "10.150.0.7", + "lastHopIP": "10.150.0.3", + "linkQuality": 1.0, + "neighborLinkQuality": 1.0, + "tcEdgeCost": 1024, + "validityTime": 284572 + }, + { + "destinationIP": "10.150.0.6", + "lastHopIP": "10.150.0.7", + "linkQuality": 1.0, + "neighborLinkQuality": 1.0, + "tcEdgeCost": 1024, + "validityTime": 284572 + } + ], + "mid": [], + "config": { + "olsrPort": 698, + "debugLevel": 0, + "noFork": false, + "hostEmulation": false, + "ipVersion": 2, + "allowNoInterfaces": true, + "typeOfService": 192, + "rtProto": 3, + "rtTable": 222, + "rtTableDefault": 223, + "rtTableTunnel": 223, + "rtTablePriority": -1, + "rtTableTunnelPriority": -1, + "rtTableDefauiltOlsrPriority": -1, + "rtTableDefaultPriority": -1, + "willingness": 3, + "willingnessAuto": false, + "brokenLinkCost": 4194304, + "brokenRouteCost": -1, + "fibMetrics": "flat", + "defaultIpv6Multicast": "ff02::6d", + "defaultIpv4Broadcast": "auto", + "defaultInterfaceMode": "mesh", + "defaultHelloEmissionInterval": 2.0, + "defaultHelloValidityTime": 20.0, + "defaultTcEmissionInterval": 5.0, + "defaultTcValidityTime": 300.0, + "defaultMidEmissionInterval": 5.0, + "defaultMidValidityTime": 300.0, + "defaultHnaEmissionInterval": 5.0, + "defaultHnaValidityTime": 300.0, + "defaultAutoDetectChanges": true, + "defaultLinkQualityMultipliers": [], + "hna": [ + { + "destination": "10.176.0.128", + "genmask": 25, + "gateway": "10.0.1.77" + } ], - "systemTime":1430572557, - "timeSinceStartup":523790030 + "totalIpcConnectionsAllowed": 0, + "ipcAllowedAddresses": [], + "pollRate": 50, + "nicChangePollInterval": 2500, + "clearScreen": true, + "tcRedundancy": 2, + "mprCoverage": 7, + "linkQualityLevel": 2, + "linkQualityAging": 0.05, + "linkQualityFisheye": true, + "linkQualityAlgorithm": "(null)", + "minTcValidTime": 0, + "setIpForward": true, + "lockFile": "(null)", + "useNiit": false, + "smartGateway": false, + "mainIpAddress": "10.0.1.77", + "unicastSourceIpAddress": "10.0.1.77", + "useSourceIpRoutes": false, + "maxPrefixLength": 32, + "ipSize": 4, + "deleteInternetGatewaysAtStartup": false, + "willingnessUpdateInterval": 20000, + "maxSendMessageJitter": 2.0, + "exitValue": 0, + "maxTcValidTime": 5000, + "niit4to6InterfaceIndex": 0, + "niit6to4InterfaceIndex": 0, + "hasIpv4Gateway": false, + "hasIpv6Gateway": false, + "ioctlSocket": 3, + "routeNetlinkSocket": 4, + "routeMonitorSocket": 5, + "linkQualityNatThreshold": 1.0, + "olsrdVersion": "olsr.org - 0.6.6-git_0000000-hash_5031a799fcbe17f61d57e387bc3806de", + "olsrdBuildDate": "2014-09-16 15:55:12", + "olsrdBuildHost": "tlaloc", + "os": "GNU/Linux", + "startTime": 1430048863 + }, + "plugins": [ + { + "plugin": "olsrd_jsoninfo.so.0.0", + "accept": "0.0.0.0", + "port": 9090 + }, + { + "plugin": "olsrd_txtinfo.so.0.1", + "accept": "0.0.0.0" + } + ], + "systemTime": 1430572557, + "timeSinceStartup": 523790030 } diff --git a/tests/static/zt-peers-updated.json b/tests/static/zt-peers-updated.json index fcb4e10..a5a12c9 100644 --- a/tests/static/zt-peers-updated.json +++ b/tests/static/zt-peers-updated.json @@ -1,180 +1,180 @@ [ - { - "address": "3504e2b2e2", - "isBonded": false, - "latency": 9, - "paths": [ + { + "address": "3504e2b2e2", + "isBonded": false, + "latency": 9, + "paths": [ { - "active": true, - "address": "192.168.56.1/44221", - "expired": false, - "lastReceive": 1691493323678, - "lastSend": 1691493323677, - "localSocket": 94434869108304, - "preferred": true, - "trustedPathId": 0 + "active": true, + "address": "192.168.56.1/44221", + "expired": false, + "lastReceive": 1691493323678, + "lastSend": 1691493323677, + "localSocket": 94434869108304, + "preferred": true, + "trustedPathId": 0 }, { - "active": true, - "address": "fd60:8d57:65e9::1/9993", - "expired": false, - "lastReceive": 1691493323678, - "lastSend": 1691493323677, - "localSocket": 94434869123504, - "preferred": false, - "trustedPathId": 0 + "active": true, + "address": "fd60:8d57:65e9::1/9993", + "expired": false, + "lastReceive": 1691493323678, + "lastSend": 1691493323677, + "localSocket": 94434869123504, + "preferred": false, + "trustedPathId": 0 }, { - "active": true, - "address": "fd60:8d57:65e9::1/9993", - "expired": false, - "lastReceive": 1691493323678, - "lastSend": 1691493323677, - "localSocket": 94434869095936, - "preferred": false, - "trustedPathId": 0 + "active": true, + "address": "fd60:8d57:65e9::1/9993", + "expired": false, + "lastReceive": 1691493323678, + "lastSend": 1691493323677, + "localSocket": 94434869095936, + "preferred": false, + "trustedPathId": 0 } - ], - "role": "LEAF", - "tunneled": false, - "version": "1.10.3", - "versionMajor": 1, - "versionMinor": 10, - "versionRev": 3 - }, - { - "address": "9a9e1c9f19", - "isBonded": false, - "latency": 0, - "paths": [ + ], + "role": "LEAF", + "tunneled": false, + "version": "1.10.3", + "versionMajor": 1, + "versionMinor": 10, + "versionRev": 3 + }, + { + "address": "9a9e1c9f19", + "isBonded": false, + "latency": 0, + "paths": [ { - "active": true, - "address": "192.168.56.6/9993", - "expired": false, - "lastReceive": 1691493318673, - "lastSend": 1691493318672, - "localSocket": 94434869092208, - "preferred": false, - "trustedPathId": 0 + "active": true, + "address": "192.168.56.6/9993", + "expired": false, + "lastReceive": 1691493318673, + "lastSend": 1691493318672, + "localSocket": 94434869092208, + "preferred": false, + "trustedPathId": 0 }, { - "active": true, - "address": "192.168.56.1/9993", - "expired": false, - "lastReceive": 1691493318673, - "lastSend": 1691493318672, - "localSocket": 94434869109504, - "preferred": false, - "trustedPathId": 0 + "active": true, + "address": "192.168.56.1/9993", + "expired": false, + "lastReceive": 1691493318673, + "lastSend": 1691493318672, + "localSocket": 94434869109504, + "preferred": false, + "trustedPathId": 0 }, { - "active": true, - "address": "172.168.56.9/9993", - "expired": false, - "lastReceive": 1691493323678, - "lastSend": 1691493323677, - "localSocket": 94434869108304, - "preferred": true, - "trustedPathId": 0 + "active": true, + "address": "172.168.56.9/9993", + "expired": false, + "lastReceive": 1691493323678, + "lastSend": 1691493323677, + "localSocket": 94434869108304, + "preferred": true, + "trustedPathId": 0 } - ], - "role": "LEAF", - "tunneled": false, - "version": "1.10.3", - "versionMajor": 1, - "versionMinor": 10, - "versionRev": 3 - }, - { - "address": "62f865ae71", - "isBonded": false, - "latency": 297, - "paths": [ + ], + "role": "LEAF", + "tunneled": false, + "version": "1.10.3", + "versionMajor": 1, + "versionMinor": 10, + "versionRev": 3 + }, + { + "address": "62f865ae71", + "isBonded": false, + "latency": 297, + "paths": [ { - "active": true, - "address": "50.7.252.138/9993", - "expired": false, - "lastReceive": 1691493263920, - "lastSend": 1691493323677, - "localSocket": 94434869079296, - "preferred": true, - "trustedPathId": 0 + "active": true, + "address": "50.7.252.138/9993", + "expired": false, + "lastReceive": 1691493263920, + "lastSend": 1691493323677, + "localSocket": 94434869079296, + "preferred": true, + "trustedPathId": 0 } - ], - "role": "PLANET", - "tunneled": false, - "version": "-1.-1.-1", - "versionMajor": -1, - "versionMinor": -1, - "versionRev": -1 - }, - { - "address": "778cde7190", - "isBonded": false, - "latency": 276, - "paths": [ + ], + "role": "PLANET", + "tunneled": false, + "version": "-1.-1.-1", + "versionMajor": -1, + "versionMinor": -1, + "versionRev": -1 + }, + { + "address": "778cde7190", + "isBonded": false, + "latency": 276, + "paths": [ { - "active": true, - "address": "103.195.103.66/9993", - "expired": false, - "lastReceive": 1691493263899, - "lastSend": 1691493323677, - "localSocket": 94434869085344, - "preferred": true, - "trustedPathId": 0 + "active": true, + "address": "103.195.103.66/9993", + "expired": false, + "lastReceive": 1691493263899, + "lastSend": 1691493323677, + "localSocket": 94434869085344, + "preferred": true, + "trustedPathId": 0 } - ], - "role": "PLANET", - "tunneled": false, - "version": "-1.-1.-1", - "versionMajor": -1, - "versionMinor": -1, - "versionRev": -1 - }, - { - "address": "cafe04eba9", - "isBonded": false, - "latency": 163, - "paths": [ + ], + "role": "PLANET", + "tunneled": false, + "version": "-1.-1.-1", + "versionMajor": -1, + "versionMinor": -1, + "versionRev": -1 + }, + { + "address": "cafe04eba9", + "isBonded": false, + "latency": 163, + "paths": [ { - "active": true, - "address": "84.17.53.155/9993", - "expired": false, - "lastReceive": 1691493263786, - "lastSend": 1691493327124, - "localSocket": 94434869086304, - "preferred": true, - "trustedPathId": 0 + "active": true, + "address": "84.17.53.155/9993", + "expired": false, + "lastReceive": 1691493263786, + "lastSend": 1691493327124, + "localSocket": 94434869086304, + "preferred": true, + "trustedPathId": 0 } - ], - "role": "PLANET", - "tunneled": false, - "version": "-1.-1.-1", - "versionMajor": -1, - "versionMinor": -1, - "versionRev": -1 - }, - { - "address": "cafe9efeb9", - "isBonded": false, - "latency": 241, - "paths": [ + ], + "role": "PLANET", + "tunneled": false, + "version": "-1.-1.-1", + "versionMajor": -1, + "versionMinor": -1, + "versionRev": -1 + }, + { + "address": "cafe9efeb9", + "isBonded": false, + "latency": 241, + "paths": [ { - "active": true, - "address": "104.194.8.134/9993", - "expired": false, - "lastReceive": 1691493263864, - "lastSend": 1691493323677, - "localSocket": 94434869086304, - "preferred": true, - "trustedPathId": 0 + "active": true, + "address": "104.194.8.134/9993", + "expired": false, + "lastReceive": 1691493263864, + "lastSend": 1691493323677, + "localSocket": 94434869086304, + "preferred": true, + "trustedPathId": 0 } - ], - "role": "PLANET", - "tunneled": false, - "version": "-1.-1.-1", - "versionMajor": -1, - "versionMinor": -1, - "versionRev": -1 - } - ] + ], + "role": "PLANET", + "tunneled": false, + "version": "-1.-1.-1", + "versionMajor": -1, + "versionMinor": -1, + "versionRev": -1 + } +] diff --git a/tests/static/zt-peers.json b/tests/static/zt-peers.json index e052719..39ac561 100644 --- a/tests/static/zt-peers.json +++ b/tests/static/zt-peers.json @@ -1,202 +1,202 @@ [ - { - "address": "3504e2b2e2", - "isBonded": false, - "latency": 1, - "paths": [ + { + "address": "3504e2b2e2", + "isBonded": false, + "latency": 1, + "paths": [ { - "active": true, - "address": "fd60:8d57:65e9::1/9993", - "expired": false, - "lastReceive": 1691413701307, - "lastSend": 1691413701307, - "localSocket": 94898166342576, - "preferred": true, - "trustedPathId": 0 + "active": true, + "address": "fd60:8d57:65e9::1/9993", + "expired": false, + "lastReceive": 1691413701307, + "lastSend": 1691413701307, + "localSocket": 94898166342576, + "preferred": true, + "trustedPathId": 0 }, { - "active": true, - "address": "192.168.56.1/46076", - "expired": false, - "lastReceive": 1691413695846, - "lastSend": 1691413695844, - "localSocket": 94898166354352, - "preferred": false, - "trustedPathId": 0 + "active": true, + "address": "192.168.56.1/46076", + "expired": false, + "lastReceive": 1691413695846, + "lastSend": 1691413695844, + "localSocket": 94898166354352, + "preferred": false, + "trustedPathId": 0 }, { - "active": true, - "address": "192.168.56.1/46076", - "expired": false, - "lastReceive": 1691413695846, - "lastSend": 1691413695844, - "localSocket": 94898166357312, - "preferred": false, - "trustedPathId": 0 + "active": true, + "address": "192.168.56.1/46076", + "expired": false, + "lastReceive": 1691413695846, + "lastSend": 1691413695844, + "localSocket": 94898166357312, + "preferred": false, + "trustedPathId": 0 } - ], - "role": "LEAF", - "tunneled": false, - "version": "1.10.3", - "versionMajor": 1, - "versionMinor": 10, - "versionRev": 3 - }, - { - "address": "4a9e1c6f14", - "isBonded": false, - "latency": 1, - "paths": [ + ], + "role": "LEAF", + "tunneled": false, + "version": "1.10.3", + "versionMajor": 1, + "versionMinor": 10, + "versionRev": 3 + }, + { + "address": "4a9e1c6f14", + "isBonded": false, + "latency": 1, + "paths": [ { - "active": true, - "address": "192.168.56.2/9993", - "expired": false, - "lastReceive": 1691413695845, - "lastSend": 1691413695844, - "localSocket": 94898166237728, - "preferred": false, - "trustedPathId": 0 + "active": true, + "address": "192.168.56.2/9993", + "expired": false, + "lastReceive": 1691413695845, + "lastSend": 1691413695844, + "localSocket": 94898166237728, + "preferred": false, + "trustedPathId": 0 }, { - "active": true, - "address": "192.168.9.109/5216", - "expired": false, - "lastReceive": 1691413695845, - "lastSend": 1691413700597, - "localSocket": 94898166193600, - "preferred": true, - "trustedPathId": 0 + "active": true, + "address": "192.168.9.109/5216", + "expired": false, + "lastReceive": 1691413695845, + "lastSend": 1691413700597, + "localSocket": 94898166193600, + "preferred": true, + "trustedPathId": 0 } - ], - "role": "LEAF", - "tunneled": false, - "version": "1.10.3", - "versionMajor": 1, - "versionMinor": 10, - "versionRev": 3 - }, - { - "address": "62f865ae71", - "isBonded": false, - "latency": 299, - "paths": [ + ], + "role": "LEAF", + "tunneled": false, + "version": "1.10.3", + "versionMajor": 1, + "versionMinor": 10, + "versionRev": 3 + }, + { + "address": "62f865ae71", + "isBonded": false, + "latency": 299, + "paths": [ { - "active": true, - "address": "50.7.252.138/9993", - "expired": false, - "lastReceive": 1691413480922, - "lastSend": 1691413675822, - "localSocket": 94898166306960, - "preferred": true, - "trustedPathId": 0 + "active": true, + "address": "50.7.252.138/9993", + "expired": false, + "lastReceive": 1691413480922, + "lastSend": 1691413675822, + "localSocket": 94898166306960, + "preferred": true, + "trustedPathId": 0 } - ], - "role": "PLANET", - "tunneled": false, - "version": "-1.-1.-1", - "versionMajor": -1, - "versionMinor": -1, - "versionRev": -1 - }, - { - "address": "778cde7190", - "isBonded": false, - "latency": 239, - "paths": [ + ], + "role": "PLANET", + "tunneled": false, + "version": "-1.-1.-1", + "versionMajor": -1, + "versionMinor": -1, + "versionRev": -1 + }, + { + "address": "778cde7190", + "isBonded": false, + "latency": 239, + "paths": [ { - "active": true, - "address": "103.195.103.66/9993", - "expired": false, - "lastReceive": 1691413255618, - "lastSend": 1691413435572, - "localSocket": 94898166308768, - "preferred": false, - "trustedPathId": 0 + "active": true, + "address": "103.195.103.66/9993", + "expired": false, + "lastReceive": 1691413255618, + "lastSend": 1691413435572, + "localSocket": 94898166308768, + "preferred": false, + "trustedPathId": 0 }, { - "active": true, - "address": "103.195.103.66/9993", - "expired": false, - "lastReceive": 1691413480862, - "lastSend": 1691413675822, - "localSocket": 94898166309120, - "preferred": true, - "trustedPathId": 0 + "active": true, + "address": "103.195.103.66/9993", + "expired": false, + "lastReceive": 1691413480862, + "lastSend": 1691413675822, + "localSocket": 94898166309120, + "preferred": true, + "trustedPathId": 0 } - ], - "role": "PLANET", - "tunneled": false, - "version": "-1.-1.-1", - "versionMajor": -1, - "versionMinor": -1, - "versionRev": -1 - }, - { - "address": "a7f77c3e11", - "isBonded": false, - "latency": -1, - "paths": [], - "role": "LEAF", - "tunneled": false, - "version": "1.10.6", - "versionMajor": 1, - "versionMinor": 10, - "versionRev": 6 - }, - { - "address": "cafe04eba9", - "isBonded": false, - "latency": 166, - "paths": [ + ], + "role": "PLANET", + "tunneled": false, + "version": "-1.-1.-1", + "versionMajor": -1, + "versionMinor": -1, + "versionRev": -1 + }, + { + "address": "a7f77c3e11", + "isBonded": false, + "latency": -1, + "paths": [], + "role": "LEAF", + "tunneled": false, + "version": "1.10.6", + "versionMajor": 1, + "versionMinor": 10, + "versionRev": 6 + }, + { + "address": "cafe04eba9", + "isBonded": false, + "latency": 166, + "paths": [ { - "active": true, - "address": "84.17.53.155/9993", - "expired": false, - "lastReceive": 1691413455702, - "lastSend": 1691413475617, - "localSocket": 94898166309120, - "preferred": false, - "trustedPathId": 0 + "active": true, + "address": "84.17.53.155/9993", + "expired": false, + "lastReceive": 1691413455702, + "lastSend": 1691413475617, + "localSocket": 94898166309120, + "preferred": false, + "trustedPathId": 0 }, { - "active": true, - "address": "84.17.53.155/9993", - "expired": false, - "lastReceive": 1691413695952, - "lastSend": 1691413700848, - "localSocket": 94898166306960, - "preferred": true, - "trustedPathId": 0 + "active": true, + "address": "84.17.53.155/9993", + "expired": false, + "lastReceive": 1691413695952, + "lastSend": 1691413700848, + "localSocket": 94898166306960, + "preferred": true, + "trustedPathId": 0 } - ], - "role": "PLANET", - "tunneled": false, - "version": "-1.-1.-1", - "versionMajor": -1, - "versionMinor": -1, - "versionRev": -1 - }, - { - "address": "cafe9efeb9", - "isBonded": false, - "latency": 239, - "paths": [ + ], + "role": "PLANET", + "tunneled": false, + "version": "-1.-1.-1", + "versionMajor": -1, + "versionMinor": -1, + "versionRev": -1 + }, + { + "address": "cafe9efeb9", + "isBonded": false, + "latency": 239, + "paths": [ { - "active": true, - "address": "104.194.8.134/9993", - "expired": false, - "lastReceive": 1691413480862, - "lastSend": 1691413675822, - "localSocket": 94898166308768, - "preferred": true, - "trustedPathId": 0 + "active": true, + "address": "104.194.8.134/9993", + "expired": false, + "lastReceive": 1691413480862, + "lastSend": 1691413675822, + "localSocket": 94898166308768, + "preferred": true, + "trustedPathId": 0 } - ], - "role": "PLANET", - "tunneled": false, - "version": "-1.-1.-1", - "versionMajor": -1, - "versionMinor": -1, - "versionRev": -1 - } + ], + "role": "PLANET", + "tunneled": false, + "version": "-1.-1.-1", + "versionMajor": -1, + "versionMinor": -1, + "versionRev": -1 + } ] diff --git a/tests/test_base.py b/tests/test_base.py index 1da01e3..e0fe6b9 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -30,58 +30,58 @@ def test_no_data_supplied(self): def test_parse_file(self): dir = os.path.dirname(os.path.realpath(__file__)) - path = '{0}/static/olsr-2-links.json'.format(dir) + path = "{0}/static/olsr-2-links.json".format(dir) p = BaseParser(file=path) self.assertIsInstance(p.original_data, dict) with self.assertRaises(TopologyRetrievalError): - BaseParser(file='../wrong.json') + BaseParser(file="../wrong.json") @responses.activate def test_parse_http(self): responses.add( responses.GET, - 'http://localhost:9090', - body=self._load_contents('tests/static/olsr-2-links.json'), + "http://localhost:9090", + body=self._load_contents("tests/static/olsr-2-links.json"), ) - p = BaseParser(url='http://localhost:9090') + p = BaseParser(url="http://localhost:9090") self.assertIsInstance(p.original_data, dict) @responses.activate def test_topology_retrieval_error_http_404(self): - responses.add(responses.GET, 'http://404.com', body='not found', status=404) + responses.add(responses.GET, "http://404.com", body="not found", status=404) with self.assertRaises(TopologyRetrievalError): - BaseParser(url='http://404.com') + BaseParser(url="http://404.com") @responses.activate def test_topology_retrieval_error_http(self): def request_callback(request): - raise ConnectionError('test exception') + raise ConnectionError("test exception") responses.add_callback( - responses.GET, 'http://connectionerror.com', callback=request_callback + responses.GET, "http://connectionerror.com", callback=request_callback ) with self.assertRaises(TopologyRetrievalError): - BaseParser(url='http://connectionerror.com') + BaseParser(url="http://connectionerror.com") - @mock.patch('Exscript.protocols.telnetlib.Telnet') + @mock.patch("Exscript.protocols.telnetlib.Telnet") def test_telnet_retrieval_error(self, MockClass): - MockClass.side_effect = ValueError('testing exception') + MockClass.side_effect = ValueError("testing exception") with self.assertRaises(TopologyRetrievalError): - BaseParser(url='telnet://wrong.com') + BaseParser(url="telnet://wrong.com") - @mock.patch('Exscript.protocols.telnetlib.Telnet') + @mock.patch("Exscript.protocols.telnetlib.Telnet") def test_telnet_retrieval(self, MockClass): with self.assertRaises(ConversionException): - BaseParser(url='telnet://127.0.0.1') + BaseParser(url="telnet://127.0.0.1") def test_topology_retrieval_error_file(self): with self.assertRaises(TopologyRetrievalError): - BaseParser(file='./tests/static/wrong.json') + BaseParser(file="./tests/static/wrong.json") def test_parse_json_string(self): - p = BaseParser(data='{}') + p = BaseParser(data="{}") self.assertIsInstance(p.original_data, dict) - p = BaseParser(data=u'{}') + p = BaseParser(data="{}") self.assertIsInstance(p.original_data, dict) def test_parse_dict(self): @@ -90,7 +90,7 @@ def test_parse_dict(self): def test_parse_conversion_exception(self): with self.assertRaises(ConversionException): - BaseParser(data='wrong [] ; .') + BaseParser(data="wrong [] ; .") def test_parse_error(self): with self.assertRaises(ConversionException): @@ -101,10 +101,10 @@ class MyParser(BaseParser): pass with self.assertRaises(NotImplementedError): - MyParser(data='{}') + MyParser(data="{}") def test_json_not_implemented(self): - p = BaseParser(data='{}') + p = BaseParser(data="{}") with self.assertRaises(NotImplementedError): p.json() @@ -112,4 +112,4 @@ def test_netjson_networkgraph_func(self): with self.assertRaises(NetJsonError): _netjson_networkgraph(None, None, None, None, [], []) with self.assertRaises(NetJsonError): - _netjson_networkgraph('bgp', None, None, None, [], []) + _netjson_networkgraph("bgp", None, None, None, [], []) diff --git a/tests/test_batman.py b/tests/test_batman.py index 1765219..6d00034 100644 --- a/tests/test_batman.py +++ b/tests/test_batman.py @@ -7,9 +7,9 @@ from netdiff.tests import TestCase CURRENT_DIR = os.path.dirname(os.path.realpath(__file__)) -iulinet = open('{0}/static/batman.json'.format(CURRENT_DIR)).read() -iulinet2 = open('{0}/static/batman-1+1.json'.format(CURRENT_DIR)).read() -duplicated = open('{0}/static/batman-duplicated.json'.format(CURRENT_DIR)).read() +iulinet = open("{0}/static/batman.json".format(CURRENT_DIR)).read() +iulinet2 = open("{0}/static/batman-1+1.json".format(CURRENT_DIR)).read() +duplicated = open("{0}/static/batman-duplicated.json".format(CURRENT_DIR)).read() class TestBatmanParser(TestCase): @@ -19,11 +19,11 @@ def test_parse(self): p = BatmanParser(iulinet) self.assertIsInstance(p.graph, networkx.Graph) properties = list(p.graph.edges(data=True))[0][2] - self.assertIsInstance(properties['weight'], float) + self.assertIsInstance(properties["weight"], float) # test additional properties in nodes of networkx graph properties = list(p.graph.nodes(data=True))[0][1] - self.assertIsInstance(properties['local_addresses'], list) - self.assertIsInstance(properties['clients'], list) + self.assertIsInstance(properties["local_addresses"], list) + self.assertIsInstance(properties["clients"], list) def test_parse_exception(self): with self.assertRaises(ParserError): @@ -37,27 +37,27 @@ def test_json_dict(self): p = BatmanParser(iulinet) data = p.json(dict=True) self.assertIsInstance(data, dict) - self.assertEqual(data['type'], 'NetworkGraph') - self.assertEqual(data['protocol'], 'batman-adv') - self.assertEqual(data['version'], '2014.3.0') - self.assertEqual(data['metric'], 'TQ') - self.assertIsInstance(data['nodes'], list) - self.assertIsInstance(data['links'], list) - self.assertEqual(len(data['nodes']), 5) - self.assertEqual(len(data['links']), 4) - self.assertIsInstance(data['links'][0]['cost'], float) + self.assertEqual(data["type"], "NetworkGraph") + self.assertEqual(data["protocol"], "batman-adv") + self.assertEqual(data["version"], "2014.3.0") + self.assertEqual(data["metric"], "TQ") + self.assertIsInstance(data["nodes"], list) + self.assertIsInstance(data["links"], list) + self.assertEqual(len(data["nodes"]), 5) + self.assertEqual(len(data["links"]), 4) + self.assertIsInstance(data["links"][0]["cost"], float) # ensure additional node properties are present found = False - for node in data['nodes']: - if node['id'] == '90:f6:52:f2:8c:2c': - self.assertIsInstance(node['local_addresses'], list) - self.assertIsInstance(node['properties']['clients'], list) + for node in data["nodes"]: + if node["id"] == "90:f6:52:f2:8c:2c": + self.assertIsInstance(node["local_addresses"], list) + self.assertIsInstance(node["properties"]["clients"], list) found = True break self.assertTrue(found) found = False - for node in data['nodes']: - if node['id'] == 'a0:f3:c1:96:94:06': + for node in data["nodes"]: + if node["id"] == "a0:f3:c1:96:94:06": found = True break self.assertTrue(found) @@ -66,33 +66,33 @@ def test_json_string(self): p = BatmanParser(iulinet) data = p.json() self.assertIsInstance(data, str) - self.assertIn('NetworkGraph', data) - self.assertIn('protocol', data) - self.assertIn('version', data) - self.assertIn('metric', data) - self.assertIn('batman-adv', data) - self.assertIn('2014.3.0', data) - self.assertIn('TQ', data) - self.assertIn('links', data) - self.assertIn('nodes', data) + self.assertIn("NetworkGraph", data) + self.assertIn("protocol", data) + self.assertIn("version", data) + self.assertIn("metric", data) + self.assertIn("batman-adv", data) + self.assertIn("2014.3.0", data) + self.assertIn("TQ", data) + self.assertIn("links", data) + self.assertIn("nodes", data) def test_added_removed_1_node(self): old = BatmanParser(iulinet) new = BatmanParser(iulinet2) result = diff(old, new) self.assertIsInstance(result, dict) - self.assertTrue(type(result['added']['links']) is list) - self.assertTrue(type(result['removed']['links']) is list) + self.assertTrue(type(result["added"]["links"]) is list) + self.assertTrue(type(result["removed"]["links"]) is list) # ensure there are no differences - self.assertEqual(len(result['added']['links']), 1) - self.assertEqual(len(result['removed']['links']), 1) + self.assertEqual(len(result["added"]["links"]), 1) + self.assertEqual(len(result["removed"]["links"]), 1) self._test_expected_links( - graph=result['added'], - expected_links=[('a0:f3:c1:96:94:10', '90:f6:52:f2:8c:2c')], + graph=result["added"], + expected_links=[("a0:f3:c1:96:94:10", "90:f6:52:f2:8c:2c")], ) self._test_expected_links( - graph=result['removed'], - expected_links=[('a0:f3:c1:96:94:06', '90:f6:52:f2:8c:2c')], + graph=result["removed"], + expected_links=[("a0:f3:c1:96:94:06", "90:f6:52:f2:8c:2c")], ) def test_no_changes(self): @@ -100,8 +100,8 @@ def test_no_changes(self): new = BatmanParser(iulinet) result = diff(old, new) self.assertIsInstance(result, dict) - self.assertIsNone(result['added']) - self.assertIsNone(result['removed']) + self.assertIsNone(result["added"]) + self.assertIsNone(result["removed"]) def test_duplicated(self): nodup = BatmanParser(iulinet) @@ -112,5 +112,5 @@ def test_duplicated(self): def test_get_primary_address_ValueError(self): p = BatmanParser(iulinet) - r = p._get_primary_address('bb:aa:cc:dd:ee:ff', [['aa:bb:cc:dd:ee:ff']]) - self.assertEqual(r, 'bb:aa:cc:dd:ee:ff') + r = p._get_primary_address("bb:aa:cc:dd:ee:ff", [["aa:bb:cc:dd:ee:ff"]]) + self.assertEqual(r, "bb:aa:cc:dd:ee:ff") diff --git a/tests/test_batman_txtinfo.py b/tests/test_batman_txtinfo.py index dc0712e..0182f42 100644 --- a/tests/test_batman_txtinfo.py +++ b/tests/test_batman_txtinfo.py @@ -7,8 +7,8 @@ from netdiff.tests import TestCase CURRENT_DIR = os.path.dirname(os.path.realpath(__file__)) -iulinet = open('{0}/static/batman.txt'.format(CURRENT_DIR)).read() -iulinet2 = open('{0}/static/batman-1+1.txt'.format(CURRENT_DIR)).read() +iulinet = open("{0}/static/batman.txt".format(CURRENT_DIR)).read() +iulinet2 = open("{0}/static/batman-1+1.txt".format(CURRENT_DIR)).read() class TestBatmanTxtinfoParser(TestCase): @@ -18,84 +18,84 @@ def test_parse(self): self.assertEqual(len(p.graph.nodes()), 5) self.assertEqual(len(p.graph.edges()), 4) properties = list(p.graph.edges(data=True))[0][2] - self.assertIsInstance(properties['weight'], float) + self.assertIsInstance(properties["weight"], float) def test_parse_exception(self): with self.assertRaises(ParserError): - BatmanParser('WRONG') + BatmanParser("WRONG") def test_json_dict(self): p = BatmanParser(iulinet) data = p.json(dict=True) self.assertIsInstance(data, dict) - self.assertEqual(data['type'], 'NetworkGraph') - self.assertEqual(data['protocol'], 'batman-adv') - self.assertEqual(data['version'], '2015.0') - self.assertEqual(data['metric'], 'TQ') - self.assertIsInstance(data['nodes'], list) - self.assertIsInstance(data['links'], list) - self.assertEqual(len(data['nodes']), 5) - self.assertEqual(len(data['links']), 4) - self.assertIsInstance(data['links'][0]['cost'], float) + self.assertEqual(data["type"], "NetworkGraph") + self.assertEqual(data["protocol"], "batman-adv") + self.assertEqual(data["version"], "2015.0") + self.assertEqual(data["metric"], "TQ") + self.assertIsInstance(data["nodes"], list) + self.assertIsInstance(data["links"], list) + self.assertEqual(len(data["nodes"]), 5) + self.assertEqual(len(data["links"]), 4) + self.assertIsInstance(data["links"][0]["cost"], float) def test_json_string(self): p = BatmanParser(iulinet) data = p.json() self.assertIsInstance(data, str) - self.assertIn('NetworkGraph', data) - self.assertIn('protocol', data) - self.assertIn('version', data) - self.assertIn('metric', data) - self.assertIn('batman-adv', data) - self.assertIn('2015.0', data) - self.assertIn('TQ', data) - self.assertIn('links', data) - self.assertIn('nodes', data) + self.assertIn("NetworkGraph", data) + self.assertIn("protocol", data) + self.assertIn("version", data) + self.assertIn("metric", data) + self.assertIn("batman-adv", data) + self.assertIn("2015.0", data) + self.assertIn("TQ", data) + self.assertIn("links", data) + self.assertIn("nodes", data) def test_added_removed_1_node(self): old = BatmanParser(iulinet) new = BatmanParser(iulinet2) result = diff(old, new) self.assertIsInstance(result, dict) - self.assertTrue(type(result['added']['links']) is list) - self.assertTrue(type(result['removed']['links']) is list) + self.assertTrue(type(result["added"]["links"]) is list) + self.assertTrue(type(result["removed"]["links"]) is list) # ensure there are no differences - self.assertEqual(len(result['added']['links']), 1) - self.assertEqual(len(result['removed']['links']), 1) + self.assertEqual(len(result["added"]["links"]), 1) + self.assertEqual(len(result["removed"]["links"]), 1) self._test_expected_links( - graph=result['added'], - expected_links=[('a0:f3:c1:96:94:10', '90:f6:52:f2:8c:2c')], + graph=result["added"], + expected_links=[("a0:f3:c1:96:94:10", "90:f6:52:f2:8c:2c")], ) self._test_expected_links( - graph=result['removed'], - expected_links=[('a0:f3:c1:96:94:06', '90:f6:52:f2:8c:2c')], + graph=result["removed"], + expected_links=[("a0:f3:c1:96:94:06", "90:f6:52:f2:8c:2c")], ) - self.assertIsInstance(result['changed'], dict) + self.assertIsInstance(result["changed"], dict) def test_changed_links(self): old = BatmanParser(iulinet) new = BatmanParser(iulinet2) result = diff(old, new) - self.assertEqual(result['changed']['nodes'], []) - self.assertEqual(len(result['changed']['links']), 2) - link = result['changed']['links'][0] - self.assertEqual(link['source'], '10:fe:ed:37:3a:39') - self.assertEqual(link['target'], 'a0:f3:c1:ac:6c:44') - self.assertEqual(link['cost'], 1.0) - self.assertEqual(link['cost_text'], '') - self.assertEqual(link['properties'], {}) - link = result['changed']['links'][1] - self.assertEqual(link['source'], '90:f6:52:f2:8c:2c') - self.assertEqual(link['target'], '10:fe:ed:37:3a:39') - self.assertEqual(link['cost'], 1.0) - self.assertEqual(link['cost_text'], '') - self.assertEqual(link['properties'], {}) + self.assertEqual(result["changed"]["nodes"], []) + self.assertEqual(len(result["changed"]["links"]), 2) + link = result["changed"]["links"][0] + self.assertEqual(link["source"], "10:fe:ed:37:3a:39") + self.assertEqual(link["target"], "a0:f3:c1:ac:6c:44") + self.assertEqual(link["cost"], 1.0) + self.assertEqual(link["cost_text"], "") + self.assertEqual(link["properties"], {}) + link = result["changed"]["links"][1] + self.assertEqual(link["source"], "90:f6:52:f2:8c:2c") + self.assertEqual(link["target"], "10:fe:ed:37:3a:39") + self.assertEqual(link["cost"], 1.0) + self.assertEqual(link["cost_text"], "") + self.assertEqual(link["properties"], {}) def test_no_changes(self): old = BatmanParser(iulinet) new = BatmanParser(iulinet) result = diff(old, new) self.assertIsInstance(result, dict) - self.assertIsNone(result['added']) - self.assertIsNone(result['removed']) - self.assertIsNone(result['changed']) + self.assertIsNone(result["added"]) + self.assertIsNone(result["removed"]) + self.assertIsNone(result["changed"]) diff --git a/tests/test_bmx6.py b/tests/test_bmx6.py index adf5bf5..903c2c2 100644 --- a/tests/test_bmx6.py +++ b/tests/test_bmx6.py @@ -7,8 +7,8 @@ from netdiff.tests import TestCase CURRENT_DIR = os.path.dirname(os.path.realpath(__file__)) -topo = open('{0}/static/bmx6.json'.format(CURRENT_DIR)).read() -topo2 = open('{0}/static/bmx6-1+1.json'.format(CURRENT_DIR)).read() +topo = open("{0}/static/bmx6.json".format(CURRENT_DIR)).read() +topo2 = open("{0}/static/bmx6-1+1.json".format(CURRENT_DIR)).read() class TestBmx6Parser(TestCase): @@ -17,9 +17,9 @@ def test_parse(self): self.assertIsInstance(p.graph, networkx.Graph) # test additional properties in networkx graph properties = list(p.graph.edges(data=True))[0][2] - self.assertIsInstance(properties['weight'], float) - self.assertIsInstance(properties['tx_rate'], int) - self.assertIsInstance(properties['rx_rate'], int) + self.assertIsInstance(properties["weight"], float) + self.assertIsInstance(properties["tx_rate"], int) + self.assertIsInstance(properties["rx_rate"], int) def test_parse_exception(self): with self.assertRaises(ParserError): @@ -29,52 +29,52 @@ def test_json_dict(self): p = Bmx6Parser(topo) data = p.json(dict=True) self.assertIsInstance(data, dict) - self.assertEqual(data['type'], 'NetworkGraph') - self.assertEqual(data['protocol'], 'BMX6_b6m') - self.assertEqual(data['version'], '0') - self.assertEqual(data['metric'], 'none') - self.assertIsInstance(data['nodes'], list) - self.assertIsInstance(data['links'], list) - self.assertEqual(len(data['nodes']), 7) - self.assertEqual(len(data['links']), 6) - self.assertIsInstance(data['links'][0]['cost'], float) - self.assertGreater(data['links'][0]['cost'], 1) + self.assertEqual(data["type"], "NetworkGraph") + self.assertEqual(data["protocol"], "BMX6_b6m") + self.assertEqual(data["version"], "0") + self.assertEqual(data["metric"], "none") + self.assertIsInstance(data["nodes"], list) + self.assertIsInstance(data["links"], list) + self.assertEqual(len(data["nodes"]), 7) + self.assertEqual(len(data["links"]), 6) + self.assertIsInstance(data["links"][0]["cost"], float) + self.assertGreater(data["links"][0]["cost"], 1) # test additional properties - properties = data['links'][0]['properties'] - self.assertIsInstance(properties['tx_rate'], int) - self.assertIsInstance(properties['rx_rate'], int) + properties = data["links"][0]["properties"] + self.assertIsInstance(properties["tx_rate"], int) + self.assertIsInstance(properties["rx_rate"], int) def test_json_string(self): p = Bmx6Parser(topo) data = p.json() self.assertIsInstance(data, str) - self.assertIn('NetworkGraph', data) - self.assertIn('protocol', data) - self.assertIn('version', data) - self.assertIn('metric', data) - self.assertIn('BMX6_b6m', data) - self.assertIn('0', data) - self.assertIn('none', data) - self.assertIn('links', data) - self.assertIn('nodes', data) + self.assertIn("NetworkGraph", data) + self.assertIn("protocol", data) + self.assertIn("version", data) + self.assertIn("metric", data) + self.assertIn("BMX6_b6m", data) + self.assertIn("0", data) + self.assertIn("none", data) + self.assertIn("links", data) + self.assertIn("nodes", data) def test_added_removed_1_node(self): old = Bmx6Parser(topo) new = Bmx6Parser(topo2) result = diff(old, new) self.assertIsInstance(result, dict) - self.assertTrue(type(result['added']['links']) is list) - self.assertTrue(type(result['removed']['links']) is list) + self.assertTrue(type(result["added"]["links"]) is list) + self.assertTrue(type(result["removed"]["links"]) is list) # ensure there are no differences - self.assertEqual(len(result['added']['links']), 1) - self.assertEqual(len(result['removed']['links']), 1) + self.assertEqual(len(result["added"]["links"]), 1) + self.assertEqual(len(result["removed"]["links"]), 1) self._test_expected_links( - graph=result['added'], - expected_links=[('P9SFCiutatGranada73-68f5', 'P9SFDrTruetaa183-b715')], + graph=result["added"], + expected_links=[("P9SFCiutatGranada73-68f5", "P9SFDrTruetaa183-b715")], ) self._test_expected_links( - graph=result['removed'], - expected_links=[('P9SFCiutatGranada73-68f5', 'P9SFDrTruetaa183-b713')], + graph=result["removed"], + expected_links=[("P9SFCiutatGranada73-68f5", "P9SFDrTruetaa183-b713")], ) def test_no_changes(self): @@ -82,5 +82,5 @@ def test_no_changes(self): new = Bmx6Parser(topo) result = diff(old, new) self.assertIsInstance(result, dict) - self.assertIsNone(result['added']) - self.assertIsNone(result['removed']) + self.assertIsNone(result["added"]) + self.assertIsNone(result["removed"]) diff --git a/tests/test_cnml.py b/tests/test_cnml.py index f9c2d97..516180c 100644 --- a/tests/test_cnml.py +++ b/tests/test_cnml.py @@ -8,9 +8,9 @@ from netdiff.tests import TestCase CURRENT_DIR = os.path.dirname(os.path.realpath(__file__)) -cnml1 = '{0}/static/26494_detail_1.cnml'.format(CURRENT_DIR) -cnml2 = '{0}/static/26494_detail_2.cnml'.format(CURRENT_DIR) -cnml3 = '{0}/static/26494_detail_3.cnml'.format(CURRENT_DIR) +cnml1 = "{0}/static/26494_detail_1.cnml".format(CURRENT_DIR) +cnml2 = "{0}/static/26494_detail_2.cnml".format(CURRENT_DIR) +cnml3 = "{0}/static/26494_detail_3.cnml".format(CURRENT_DIR) class TestCnmlParser(TestCase): @@ -26,82 +26,82 @@ def test_json_dict(self): p = CnmlParser(cnml1) data = p.json(dict=True) self.assertIsInstance(data, dict) - self.assertEqual(data['type'], 'NetworkGraph') - self.assertEqual(data['protocol'], 'static') - self.assertEqual(data['version'], None) - self.assertEqual(data['revision'], None) - self.assertEqual(data['metric'], None) - self.assertIsInstance(data['nodes'], list) - self.assertIsInstance(data['links'], list) - self.assertEqual(len(data['nodes']), 5) - self.assertEqual(len(data['links']), 3) + self.assertEqual(data["type"], "NetworkGraph") + self.assertEqual(data["protocol"], "static") + self.assertEqual(data["version"], None) + self.assertEqual(data["revision"], None) + self.assertEqual(data["metric"], None) + self.assertIsInstance(data["nodes"], list) + self.assertIsInstance(data["links"], list) + self.assertEqual(len(data["nodes"]), 5) + self.assertEqual(len(data["links"]), 3) def test_json_string(self): p = CnmlParser(cnml1) data = p.json() self.assertIsInstance(data, str) - self.assertIn('NetworkGraph', data) - self.assertIn('protocol', data) - self.assertIn('version', data) - self.assertIn('revision', data) - self.assertIn('metric', data) - self.assertIn('null', data) - self.assertIn('links', data) - self.assertIn('nodes', data) + self.assertIn("NetworkGraph", data) + self.assertIn("protocol", data) + self.assertIn("version", data) + self.assertIn("revision", data) + self.assertIn("metric", data) + self.assertIn("null", data) + self.assertIn("links", data) + self.assertIn("nodes", data) def test_no_changes(self): old = CnmlParser(cnml1) new = CnmlParser(cnml1) result = diff(old, new) self.assertIsInstance(result, dict) - self.assertIsNone(result['added']) - self.assertIsNone(result['removed']) + self.assertIsNone(result["added"]) + self.assertIsNone(result["removed"]) def test_added_1_link(self): old = CnmlParser(cnml1) new = CnmlParser(cnml2) result = diff(old, new) - self.assertIsNone(result['removed']) + self.assertIsNone(result["removed"]) # ensure there are differences - self.assertEqual(len(result['added']['links']), 1) + self.assertEqual(len(result["added"]["links"]), 1) # ensure 1 link added - self.assertIn('10.228.172.97', result['added']['links'][0].values()) - self.assertIn('10.228.172.101', result['added']['links'][0].values()) + self.assertIn("10.228.172.97", result["added"]["links"][0].values()) + self.assertIn("10.228.172.101", result["added"]["links"][0].values()) def test_removed_1_link(self): old = CnmlParser(cnml2) new = CnmlParser(cnml1) result = diff(old, new) self.assertIsInstance(result, dict) - self.assertIsNone(result['added']) - self.assertTrue(type(result['removed']['links']) is list) + self.assertIsNone(result["added"]) + self.assertTrue(type(result["removed"]["links"]) is list) # ensure there are differences - self.assertEqual(len(result['removed']['links']), 1) + self.assertEqual(len(result["removed"]["links"]), 1) # ensure 1 link removed - self.assertIn('10.228.172.97', result['removed']['links'][0].values()) - self.assertIn('10.228.172.101', result['removed']['links'][0].values()) + self.assertIn("10.228.172.97", result["removed"]["links"][0].values()) + self.assertIn("10.228.172.101", result["removed"]["links"][0].values()) def test_simple_diff(self): old = CnmlParser(cnml1) new = CnmlParser(cnml3) result = diff(old, new) # ensure there are differences - self.assertEqual(len(result['added']['links']), 2) - self.assertEqual(len(result['removed']['links']), 2) + self.assertEqual(len(result["added"]["links"]), 2) + self.assertEqual(len(result["removed"]["links"]), 2) # ensure 2 links added self._test_expected_links( - graph=result['added'], + graph=result["added"], expected_links=[ - ('10.228.172.97', '10.228.172.101'), - ('10.228.172.194', '10.228.172.193'), + ("10.228.172.97", "10.228.172.101"), + ("10.228.172.194", "10.228.172.193"), ], ) # ensure 2 links removed self._test_expected_links( - graph=result['removed'], + graph=result["removed"], expected_links=[ - ('10.228.172.33', '10.228.172.34'), - ('10.228.172.33', '10.228.172.36'), + ("10.228.172.33", "10.228.172.34"), + ("10.228.172.33", "10.228.172.36"), ], ) diff --git a/tests/test_netjson.py b/tests/test_netjson.py index 9a6884c..8a76365 100644 --- a/tests/test_netjson.py +++ b/tests/test_netjson.py @@ -7,40 +7,40 @@ from netdiff.tests import TestCase CURRENT_DIR = os.path.dirname(os.path.realpath(__file__)) -links2 = open('{0}/static/netjson-2-links.json'.format(CURRENT_DIR)).read() -links3 = open('{0}/static/netjson-3-links.json'.format(CURRENT_DIR)).read() -nodes1 = open('{0}/static/netjson-nodes-1.json'.format(CURRENT_DIR)).read() -nodes2 = open('{0}/static/netjson-nodes-2.json'.format(CURRENT_DIR)).read() +links2 = open("{0}/static/netjson-2-links.json".format(CURRENT_DIR)).read() +links3 = open("{0}/static/netjson-3-links.json".format(CURRENT_DIR)).read() +nodes1 = open("{0}/static/netjson-nodes-1.json".format(CURRENT_DIR)).read() +nodes2 = open("{0}/static/netjson-nodes-2.json".format(CURRENT_DIR)).read() class TestNetJsonParser(TestCase): def test_parse(self): p = NetJsonParser(links2) self.assertIsInstance(p.graph, networkx.Graph) - self.assertEqual(p.version, '0.6.6') - self.assertEqual(p.revision, '5031a799fcbe17f61d57e387bc3806de') - self.assertEqual(p.metric, 'ETX') + self.assertEqual(p.version, "0.6.6") + self.assertEqual(p.revision, "5031a799fcbe17f61d57e387bc3806de") + self.assertEqual(p.metric, "ETX") # test additional properties in links of network graph properties = list(p.graph.edges(data=True))[0][2] - self.assertIsInstance(properties['custom_property'], bool) + self.assertIsInstance(properties["custom_property"], bool) # test additional properties in nodes of networkx graph properties = list(p.graph.nodes(data=True))[0][1] - self.assertIsInstance(properties['local_addresses'], list) - self.assertIsInstance(properties['hostname'], str) + self.assertIsInstance(properties["local_addresses"], list) + self.assertIsInstance(properties["hostname"], str) def test_parse_directed(self): p = NetJsonParser(links2, directed=True) self.assertIsInstance(p.graph, networkx.DiGraph) - self.assertEqual(p.version, '0.6.6') - self.assertEqual(p.revision, '5031a799fcbe17f61d57e387bc3806de') - self.assertEqual(p.metric, 'ETX') + self.assertEqual(p.version, "0.6.6") + self.assertEqual(p.revision, "5031a799fcbe17f61d57e387bc3806de") + self.assertEqual(p.metric, "ETX") # test additional properties in links of network graph properties = list(p.graph.edges(data=True))[0][2] - self.assertIsInstance(properties['custom_property'], bool) + self.assertIsInstance(properties["custom_property"], bool) # test additional properties in nodes of networkx graph properties = list(p.graph.nodes(data=True))[0][1] - self.assertIsInstance(properties['local_addresses'], list) - self.assertIsInstance(properties['hostname'], str) + self.assertIsInstance(properties["local_addresses"], list) + self.assertIsInstance(properties["hostname"], str) def test_parse_string_graph(self): data = """{ @@ -67,10 +67,10 @@ def test_parse_string_graph(self): }""" p = NetJsonParser(data) self.assertEqual(len(p.graph.nodes()), 2) - self.assertIn('10.150.0.3', p.graph.nodes()) - self.assertIn('10.150.0.2', p.graph.nodes()) + self.assertIn("10.150.0.3", p.graph.nodes()) + self.assertIn("10.150.0.2", p.graph.nodes()) self.assertEqual(len(p.graph.edges()), 1) - self.assertEqual(list(p.graph.edges(data=True))[0][2]['weight'], 1.0) + self.assertEqual(list(p.graph.edges(data=True))[0][2]["weight"], 1.0) def test_parse_one_way_directed_string_graph(self): """ @@ -100,8 +100,8 @@ def test_parse_one_way_directed_string_graph(self): }""" p = NetJsonParser(data, directed=True) self.assertEqual(len(p.graph.nodes()), 2) - self.assertIn('10.150.0.3', p.graph.nodes()) - self.assertIn('10.150.0.2', p.graph.nodes()) + self.assertIn("10.150.0.3", p.graph.nodes()) + self.assertIn("10.150.0.2", p.graph.nodes()) self.assertEqual(len(p.graph.edges()), 1) self.assertEqual( len(p.graph.adj["10.150.0.3"]), 1, msg="10.150.0.3 should have an edge" @@ -110,7 +110,7 @@ def test_parse_one_way_directed_string_graph(self): len(p.graph.adj["10.150.0.2"]), 0, msg="10.150.0.2 should have no edges" ) self.assertEqual( - p.graph.edges[("10.150.0.3", "10.150.0.2")]['weight'], + p.graph.edges[("10.150.0.3", "10.150.0.2")]["weight"], 1.0, msg="Expected directed edge does not exist!", ) @@ -149,16 +149,16 @@ def test_parse_forward_backward_directed_string_graph3(self): }""" p = NetJsonParser(data, directed=True) self.assertEqual(len(p.graph.nodes()), 2) - self.assertIn('10.150.0.3', p.graph.nodes()) - self.assertIn('10.150.0.2', p.graph.nodes()) + self.assertIn("10.150.0.3", p.graph.nodes()) + self.assertIn("10.150.0.2", p.graph.nodes()) self.assertEqual(len(p.graph.edges()), 2) self.assertEqual( - p.graph.edges[("10.150.0.3", "10.150.0.2")]['weight'], + p.graph.edges[("10.150.0.3", "10.150.0.2")]["weight"], 1.0, msg="Forward edge weight was incorrectly overwritten!", ) self.assertEqual( - p.graph.edges[("10.150.0.2", "10.150.0.3")]['weight'], + p.graph.edges[("10.150.0.2", "10.150.0.3")]["weight"], 99.0, msg="Backward edge weight was not correctly assigned!", ) @@ -210,152 +210,152 @@ def test_json_dict(self): p = NetJsonParser(links2) data = p.json(dict=True) self.assertIsInstance(data, dict) - self.assertEqual(data['type'], 'NetworkGraph') - self.assertEqual(data['protocol'], 'OLSR') - self.assertEqual(data['version'], '0.6.6') - self.assertEqual(data['revision'], '5031a799fcbe17f61d57e387bc3806de') - self.assertEqual(data['metric'], 'ETX') - self.assertIsInstance(data['nodes'], list) - self.assertIsInstance(data['links'], list) - self.assertEqual(len(data['nodes']), 3) - self.assertEqual(len(data['links']), 2) + self.assertEqual(data["type"], "NetworkGraph") + self.assertEqual(data["protocol"], "OLSR") + self.assertEqual(data["version"], "0.6.6") + self.assertEqual(data["revision"], "5031a799fcbe17f61d57e387bc3806de") + self.assertEqual(data["metric"], "ETX") + self.assertIsInstance(data["nodes"], list) + self.assertIsInstance(data["links"], list) + self.assertEqual(len(data["nodes"]), 3) + self.assertEqual(len(data["links"]), 2) # ensure additional node properties are present - self.assertIn('properties', data['nodes'][0]) - self.assertIn('hostname', data['nodes'][0]['properties']) + self.assertIn("properties", data["nodes"][0]) + self.assertIn("hostname", data["nodes"][0]["properties"]) # ensure local_addresses is present - self.assertIn('local_addresses', data['nodes'][0]) + self.assertIn("local_addresses", data["nodes"][0]) # ensure additional link properties are present - self.assertIn('properties', data['links'][0]) - self.assertIn('custom_property', data['links'][0]['properties']) + self.assertIn("properties", data["links"][0]) + self.assertIn("custom_property", data["links"][0]["properties"]) # check presence of labels, we need to find 2 labels = [] - for node in data['nodes']: - if 'label' in node: - labels.append(node['label']) + for node in data["nodes"]: + if "label" in node: + labels.append(node["label"]) self.assertEqual(len(labels), 3) - self.assertIn('nodeA', labels) - self.assertIn('nodeB', labels) - self.assertIn('', labels) + self.assertIn("nodeA", labels) + self.assertIn("nodeB", labels) + self.assertIn("", labels) def test_json_string(self): p = NetJsonParser(links2) data = p.json() self.assertIsInstance(data, str) - self.assertIn('NetworkGraph', data) - self.assertIn('protocol', data) - self.assertIn('version', data) - self.assertIn('revision', data) - self.assertIn('metric', data) - self.assertIn('OLSR', data) - self.assertIn('0.6.6', data) - self.assertIn('5031a799fcbe17f61d57e387bc3806de', data) - self.assertIn('ETX', data) - self.assertIn('links', data) - self.assertIn('nodes', data) + self.assertIn("NetworkGraph", data) + self.assertIn("protocol", data) + self.assertIn("version", data) + self.assertIn("revision", data) + self.assertIn("metric", data) + self.assertIn("OLSR", data) + self.assertIn("0.6.6", data) + self.assertIn("5031a799fcbe17f61d57e387bc3806de", data) + self.assertIn("ETX", data) + self.assertIn("links", data) + self.assertIn("nodes", data) def test_no_changes(self): old = NetJsonParser(links2) new = NetJsonParser(links2) result = diff(old, new) self.assertIsInstance(result, dict) - self.assertIsNone(result['added']) - self.assertIsNone(result['removed']) + self.assertIsNone(result["added"]) + self.assertIsNone(result["removed"]) def test_added_1_link(self): old = NetJsonParser(links2) new = NetJsonParser(links3) result = diff(old, new) - self.assertIsNone(result['removed']) + self.assertIsNone(result["removed"]) # ensure there are no differences - self.assertEqual(len(result['added']['links']), 1) - self.assertEqual(len(result['added']['nodes']), 1) + self.assertEqual(len(result["added"]["links"]), 1) + self.assertEqual(len(result["added"]["nodes"]), 1) # ensure correct link added - self.assertIn('10.150.0.5', result['added']['links'][0].values()) - self.assertIn('10.150.0.4', result['added']['links'][0].values()) + self.assertIn("10.150.0.5", result["added"]["links"][0].values()) + self.assertIn("10.150.0.4", result["added"]["links"][0].values()) # ensure correct node added - self.assertIn('10.150.0.5', result['added']['nodes'][0].values()) + self.assertIn("10.150.0.5", result["added"]["nodes"][0].values()) # ensure changed value is correct - link = result['changed']['links'][1] - self.assertEqual(link['source'], '10.150.0.3') - self.assertEqual(link['target'], '10.150.0.4') - self.assertEqual(link['cost'], 1048) + link = result["changed"]["links"][1] + self.assertEqual(link["source"], "10.150.0.3") + self.assertEqual(link["target"], "10.150.0.4") + self.assertEqual(link["cost"], 1048) def test_removed_1_link(self): old = NetJsonParser(links3) new = NetJsonParser(links2) result = diff(old, new) - self.assertIsNone(result['added']) + self.assertIsNone(result["added"]) self.assertIsInstance(result, dict) - self.assertTrue(type(result['removed']['links']) is list) - self.assertTrue(type(result['removed']['nodes']) is list) + self.assertTrue(type(result["removed"]["links"]) is list) + self.assertTrue(type(result["removed"]["nodes"]) is list) # ensure differences - self.assertEqual(len(result['removed']['links']), 1) - self.assertEqual(len(result['removed']['nodes']), 1) + self.assertEqual(len(result["removed"]["links"]), 1) + self.assertEqual(len(result["removed"]["nodes"]), 1) # ensure 1 link removed - self.assertIn('10.150.0.5', result['removed']['links'][0].values()) - self.assertIn('10.150.0.4', result['removed']['links'][0].values()) + self.assertIn("10.150.0.5", result["removed"]["links"][0].values()) + self.assertIn("10.150.0.4", result["removed"]["links"][0].values()) # ensure correct node added - self.assertIn('10.150.0.5', result['removed']['nodes'][0].values()) + self.assertIn("10.150.0.5", result["removed"]["nodes"][0].values()) def test_added_1_node(self): old = NetJsonParser(nodes1) new = NetJsonParser(nodes2) result = diff(old, new) - self.assertIsNone(result['removed']) + self.assertIsNone(result["removed"]) self.assertIsInstance(result, dict) # ensure node addedly added with properties - self.assertEqual(len(result['added']['nodes']), 1) - node = result['added']['nodes'][0] - self.assertEqual(node['id'], '10.150.0.5') - self.assertEqual(node['label'], 'node5') - self.assertEqual(node['local_addresses'], []) - self.assertEqual(node['properties'], {}) - self.assertIn('10.150.0.5', result['added']['nodes'][0].values()) + self.assertEqual(len(result["added"]["nodes"]), 1) + node = result["added"]["nodes"][0] + self.assertEqual(node["id"], "10.150.0.5") + self.assertEqual(node["label"], "node5") + self.assertEqual(node["local_addresses"], []) + self.assertEqual(node["properties"], {}) + self.assertIn("10.150.0.5", result["added"]["nodes"][0].values()) def test_changed_3_nodes(self): old = NetJsonParser(nodes1) new = NetJsonParser(nodes2) result = diff(old, new) # nodes whose properties have changed - self.assertEqual(len(result['changed']['nodes']), 3) - node = result['changed']['nodes'][0] - self.assertEqual(node['id'], '10.150.0.2') - self.assertEqual(node['label'], '') - self.assertEqual(node['local_addresses'], []) - self.assertEqual(node['properties'], {}) - node = result['changed']['nodes'][1] - self.assertEqual(node['id'], '10.150.0.3') - self.assertEqual(node['label'], 'nodeA2') - self.assertEqual(node['local_addresses'], []) + self.assertEqual(len(result["changed"]["nodes"]), 3) + node = result["changed"]["nodes"][0] + self.assertEqual(node["id"], "10.150.0.2") + self.assertEqual(node["label"], "") + self.assertEqual(node["local_addresses"], []) + self.assertEqual(node["properties"], {}) + node = result["changed"]["nodes"][1] + self.assertEqual(node["id"], "10.150.0.3") + self.assertEqual(node["label"], "nodeA2") + self.assertEqual(node["local_addresses"], []) self.assertEqual( - node['properties'], + node["properties"], { - 'hostname': 'router.2nnx', - 'contact': 'me@project.com', - 'input_octets': 85331213, - 'output_octets': 4358710, + "hostname": "router.2nnx", + "contact": "me@project.com", + "input_octets": 85331213, + "output_octets": 4358710, }, ) - node = result['changed']['nodes'][2] - self.assertEqual(node['id'], '10.150.0.4') - self.assertEqual(node['label'], '') - self.assertEqual(node['local_addresses'], ['192.168.1.3']) - self.assertEqual(node['properties'], {'hostname': 'router4.nnx'}) + node = result["changed"]["nodes"][2] + self.assertEqual(node["id"], "10.150.0.4") + self.assertEqual(node["label"], "") + self.assertEqual(node["local_addresses"], ["192.168.1.3"]) + self.assertEqual(node["properties"], {"hostname": "router4.nnx"}) def test_changed_2_links(self): old = NetJsonParser(nodes1) new = NetJsonParser(nodes2) result = diff(old, new) - self.assertEqual(len(result['changed']['links']), 2) - link = result['changed']['links'][0] - self.assertEqual(link['source'], '10.150.0.3') - self.assertEqual(link['target'], '10.150.0.2') - self.assertEqual(link['cost'], 28334) - self.assertEqual(link['cost_text'], 'Fast link') - self.assertEqual(link['properties'], {"custom_property": True, "foo": "bar"}) - link = result['changed']['links'][1] - self.assertEqual(link['source'], '10.150.0.3') - self.assertEqual(link['target'], '10.150.0.4') - self.assertEqual(link['cost'], 1048) - self.assertEqual(link['cost_text'], '') - self.assertEqual(link['properties'], {}) + self.assertEqual(len(result["changed"]["links"]), 2) + link = result["changed"]["links"][0] + self.assertEqual(link["source"], "10.150.0.3") + self.assertEqual(link["target"], "10.150.0.2") + self.assertEqual(link["cost"], 28334) + self.assertEqual(link["cost_text"], "Fast link") + self.assertEqual(link["properties"], {"custom_property": True, "foo": "bar"}) + link = result["changed"]["links"][1] + self.assertEqual(link["source"], "10.150.0.3") + self.assertEqual(link["target"], "10.150.0.4") + self.assertEqual(link["cost"], 1048) + self.assertEqual(link["cost_text"], "") + self.assertEqual(link["properties"], {}) diff --git a/tests/test_olsr.py b/tests/test_olsr.py index 1a5cb4e..9e4545d 100644 --- a/tests/test_olsr.py +++ b/tests/test_olsr.py @@ -8,23 +8,23 @@ from netdiff.tests import TestCase CURRENT_DIR = os.path.dirname(os.path.realpath(__file__)) -links2 = open('{0}/static/olsr-2-links.json'.format(CURRENT_DIR)).read() +links2 = open("{0}/static/olsr-2-links.json".format(CURRENT_DIR)).read() links2_newformat = open( - '{0}/static/olsr-2-links-newformat.json'.format(CURRENT_DIR) + "{0}/static/olsr-2-links-newformat.json".format(CURRENT_DIR) ).read() links2_cost = open( - '{0}/static/olsr-2-links-cost-changed.json'.format(CURRENT_DIR) + "{0}/static/olsr-2-links-cost-changed.json".format(CURRENT_DIR) ).read() -links3 = open('{0}/static/olsr-3-links.json'.format(CURRENT_DIR)).read() -links5 = open('{0}/static/olsr-5-links.json'.format(CURRENT_DIR)).read() +links3 = open("{0}/static/olsr-3-links.json".format(CURRENT_DIR)).read() +links5 = open("{0}/static/olsr-5-links.json".format(CURRENT_DIR)).read() links5_cost = open( - '{0}/static/olsr-5-links-cost-changed.json'.format(CURRENT_DIR) + "{0}/static/olsr-5-links-cost-changed.json".format(CURRENT_DIR) ).read() def parameterized_test_name_func(testcase_func, param_num, param): - format = 'newformat' if 'version' in param[0][0] else 'oldformat' - return f'{testcase_func.__name__}_{param_num}_{format}' + format = "newformat" if "version" in param[0][0] else "oldformat" + return f"{testcase_func.__name__}_{param_num}_{format}" class TestOlsrParser(TestCase): @@ -36,20 +36,20 @@ def test_parse(self, links2): self.assertIsInstance(p.graph, networkx.Graph) # test additional properties in networkx graph properties = list(p.graph.edges(data=True))[0][2] - self.assertIsInstance(properties['weight'], float) - self.assertIsInstance(properties['link_quality'], float) - self.assertIsInstance(properties['neighbor_link_quality'], float) + self.assertIsInstance(properties["weight"], float) + self.assertIsInstance(properties["link_quality"], float) + self.assertIsInstance(properties["neighbor_link_quality"], float) # test additional node properties properties = list(p.graph.nodes(data=True))[0][1] - self.assertIsInstance(properties['local_addresses'], list) + self.assertIsInstance(properties["local_addresses"], list) def test_init(self): - p = OlsrParser(links3, version='0.6.3', metric='ETC') - self.assertEqual(p.version, '0.6.3') - self.assertEqual(p.metric, 'ETC') + p = OlsrParser(links3, version="0.6.3", metric="ETC") + self.assertEqual(p.version, "0.6.3") + self.assertEqual(p.metric, "ETC") self.assertEqual(p.revision, None) - p = OlsrParser(links3, version='0.6.3', revision='a', metric='ETC') - self.assertEqual(p.revision, 'a') + p = OlsrParser(links3, version="0.6.3", revision="a", metric="ETC") + self.assertEqual(p.revision, "a") def test_parse_exception(self): with self.assertRaises(ParserError): @@ -70,28 +70,28 @@ def test_json_dict(self, links2): p = OlsrParser(links2) data = p.json(dict=True) self.assertIsInstance(data, dict) - self.assertEqual(data['type'], 'NetworkGraph') - self.assertEqual(data['protocol'], 'OLSR') - self.assertEqual(data['version'], '0.6.6') - self.assertEqual(data['revision'], '5031a799fcbe17f61d57e387bc3806de') - self.assertEqual(data['metric'], 'ETX') - self.assertIsInstance(data['nodes'], list) - self.assertIsInstance(data['links'], list) - self.assertEqual(len(data['nodes']), 3) - self.assertEqual(len(data['links']), 2) - self.assertIsInstance(data['links'][0]['cost'], float) + self.assertEqual(data["type"], "NetworkGraph") + self.assertEqual(data["protocol"], "OLSR") + self.assertEqual(data["version"], "0.6.6") + self.assertEqual(data["revision"], "5031a799fcbe17f61d57e387bc3806de") + self.assertEqual(data["metric"], "ETX") + self.assertIsInstance(data["nodes"], list) + self.assertIsInstance(data["links"], list) + self.assertEqual(len(data["nodes"]), 3) + self.assertEqual(len(data["links"]), 2) + self.assertIsInstance(data["links"][0]["cost"], float) # test additional link properties - properties = data['links'][0]['properties'] - self.assertIsInstance(properties['link_quality'], float) - self.assertIsInstance(properties['neighbor_link_quality'], float) + properties = data["links"][0]["properties"] + self.assertIsInstance(properties["link_quality"], float) + self.assertIsInstance(properties["neighbor_link_quality"], float) # test local_addresses - self.assertIsInstance(data['nodes'][0]['local_addresses'], list) + self.assertIsInstance(data["nodes"][0]["local_addresses"], list) found = False - for node in data['nodes']: - if node['id'] == '10.150.0.2': - self.assertEqual(len(node['local_addresses']), 2) - self.assertEqual(node['local_addresses'][0], '172.16.192.2') - self.assertEqual(node['local_addresses'][1], '192.168.0.2') + for node in data["nodes"]: + if node["id"] == "10.150.0.2": + self.assertEqual(len(node["local_addresses"]), 2) + self.assertEqual(node["local_addresses"][0], "172.16.192.2") + self.assertEqual(node["local_addresses"][1], "192.168.0.2") found = True self.assertTrue(found) @@ -102,17 +102,17 @@ def test_json_string(self, links2): p = OlsrParser(links2) data = p.json() self.assertIsInstance(data, str) - self.assertIn('NetworkGraph', data) - self.assertIn('protocol', data) - self.assertIn('version', data) - self.assertIn('revision', data) - self.assertIn('metric', data) - self.assertIn('OLSR', data) - self.assertIn('0.6.6', data) - self.assertIn('5031a799fcbe17f61d57e387bc3806de', data) - self.assertIn('ETX', data) - self.assertIn('links', data) - self.assertIn('nodes', data) + self.assertIn("NetworkGraph", data) + self.assertIn("protocol", data) + self.assertIn("version", data) + self.assertIn("revision", data) + self.assertIn("metric", data) + self.assertIn("OLSR", data) + self.assertIn("0.6.6", data) + self.assertIn("5031a799fcbe17f61d57e387bc3806de", data) + self.assertIn("ETX", data) + self.assertIn("links", data) + self.assertIn("nodes", data) @parameterized.expand( [(links2), (links2_newformat)], name_func=parameterized_test_name_func @@ -122,9 +122,9 @@ def test_no_changes(self, links2): new = OlsrParser(links2) result = diff(old, new) self.assertIsInstance(result, dict) - self.assertIsNone(result['added']) - self.assertIsNone(result['removed']) - self.assertIsNone(result['changed']) + self.assertIsNone(result["added"]) + self.assertIsNone(result["removed"]) + self.assertIsNone(result["changed"]) @parameterized.expand( [(links2), (links2_newformat)], name_func=parameterized_test_name_func @@ -133,24 +133,24 @@ def test_added_1_link(self, links2): old = OlsrParser(links2) new = OlsrParser(links3) result = diff(old, new) - self.assertIsNone(result['removed']) - self.assertEqual(len(result['changed']['links']), 1) - link = result['changed']['links'][0] - self.assertEqual(link['source'], '10.150.0.3') - self.assertEqual(link['target'], '10.150.0.2') - self.assertEqual(link['cost'], 27.669921875) - self.assertEqual(link['cost_text'], '') + self.assertIsNone(result["removed"]) + self.assertEqual(len(result["changed"]["links"]), 1) + link = result["changed"]["links"][0] + self.assertEqual(link["source"], "10.150.0.3") + self.assertEqual(link["target"], "10.150.0.2") + self.assertEqual(link["cost"], 27.669921875) + self.assertEqual(link["cost_text"], "") self.assertEqual( - link['properties'], {'link_quality': 0.195, 'neighbor_link_quality': 0.184} + link["properties"], {"link_quality": 0.195, "neighbor_link_quality": 0.184} ) # ensure there are differences - self.assertEqual(len(result['added']['links']), 1) - self.assertEqual(len(result['added']['nodes']), 1) + self.assertEqual(len(result["added"]["links"]), 1) + self.assertEqual(len(result["added"]["nodes"]), 1) # ensure correct link added - self.assertIn('10.150.0.5', result['added']['links'][0].values()) - self.assertIn('10.150.0.4', result['added']['links'][0].values()) + self.assertIn("10.150.0.5", result["added"]["links"][0].values()) + self.assertIn("10.150.0.4", result["added"]["links"][0].values()) # ensure correct node added - self.assertIn('10.150.0.5', result['added']['nodes'][0].values()) + self.assertIn("10.150.0.5", result["added"]["nodes"][0].values()) @parameterized.expand( [(links2), (links2_newformat)], name_func=parameterized_test_name_func @@ -159,15 +159,15 @@ def test_added_1_link_sub(self, links2): old = OlsrParser(links2) new = OlsrParser(links3) result = new - old - self.assertIsNone(result['removed']) + self.assertIsNone(result["removed"]) # ensure there are differences - self.assertEqual(len(result['added']['links']), 1) - self.assertEqual(len(result['added']['nodes']), 1) + self.assertEqual(len(result["added"]["links"]), 1) + self.assertEqual(len(result["added"]["nodes"]), 1) # ensure correct link added - self.assertIn('10.150.0.5', result['added']['links'][0].values()) - self.assertIn('10.150.0.4', result['added']['links'][0].values()) + self.assertIn("10.150.0.5", result["added"]["links"][0].values()) + self.assertIn("10.150.0.4", result["added"]["links"][0].values()) # ensure correct node added - self.assertIn('10.150.0.5', result['added']['nodes'][0].values()) + self.assertIn("10.150.0.5", result["added"]["nodes"][0].values()) @parameterized.expand( [(links2), (links2_newformat)], name_func=parameterized_test_name_func @@ -176,26 +176,26 @@ def test_removed_1_link(self, links2): old = OlsrParser(links3) new = OlsrParser(links2) result = diff(old, new) - self.assertIsNone(result['added']) - self.assertEqual(len(result['changed']['links']), 1) - link = result['changed']['links'][0] - self.assertEqual(link['source'], '10.150.0.2') - self.assertEqual(link['target'], '10.150.0.3') - self.assertEqual(link['cost'], 27.669921875) - self.assertEqual(link['cost_text'], '') + self.assertIsNone(result["added"]) + self.assertEqual(len(result["changed"]["links"]), 1) + link = result["changed"]["links"][0] + self.assertEqual(link["source"], "10.150.0.2") + self.assertEqual(link["target"], "10.150.0.3") + self.assertEqual(link["cost"], 27.669921875) + self.assertEqual(link["cost_text"], "") self.assertEqual( - link['properties'], {'link_quality': 0.195, 'neighbor_link_quality': 0.184} + link["properties"], {"link_quality": 0.195, "neighbor_link_quality": 0.184} ) self.assertIsInstance(result, dict) - self.assertTrue(type(result['removed']['links']) is list) + self.assertTrue(type(result["removed"]["links"]) is list) # ensure there are differences - self.assertEqual(len(result['removed']['links']), 1) - self.assertEqual(len(result['removed']['nodes']), 1) + self.assertEqual(len(result["removed"]["links"]), 1) + self.assertEqual(len(result["removed"]["nodes"]), 1) # ensure correct link removed - self.assertIn('10.150.0.5', result['removed']['links'][0].values()) - self.assertIn('10.150.0.4', result['removed']['links'][0].values()) + self.assertIn("10.150.0.5", result["removed"]["links"][0].values()) + self.assertIn("10.150.0.4", result["removed"]["links"][0].values()) # ensure correct node removed - self.assertIn('10.150.0.5', result['removed']['nodes'][0].values()) + self.assertIn("10.150.0.5", result["removed"]["nodes"][0].values()) @parameterized.expand( [(links2), (links2_newformat)], name_func=parameterized_test_name_func @@ -204,14 +204,14 @@ def test_changed_links(self, links2): old = OlsrParser(links2) new = OlsrParser(links3) result = diff(old, new) - self.assertEqual(len(result['changed']['links']), 1) - link = result['changed']['links'][0] - self.assertEqual(link['source'], '10.150.0.3') - self.assertEqual(link['target'], '10.150.0.2') - self.assertEqual(link['cost'], 27.669921875) - self.assertEqual(link['cost_text'], '') + self.assertEqual(len(result["changed"]["links"]), 1) + link = result["changed"]["links"][0] + self.assertEqual(link["source"], "10.150.0.3") + self.assertEqual(link["target"], "10.150.0.2") + self.assertEqual(link["cost"], 27.669921875) + self.assertEqual(link["cost_text"], "") self.assertEqual( - link['properties'], {'link_quality': 0.195, 'neighbor_link_quality': 0.184} + link["properties"], {"link_quality": 0.195, "neighbor_link_quality": 0.184} ) @parameterized.expand( @@ -221,50 +221,50 @@ def test_changed_nodes(self, links2): old = OlsrParser(links2) new = OlsrParser(links2_cost) result = diff(old, new) - self.assertIsInstance(result['changed'], dict) - self.assertEqual(len(result['changed']['nodes']), 3) - node = result['changed']['nodes'][0] - self.assertEqual(node['id'], '10.150.0.2') - self.assertEqual(node['label'], '') - self.assertEqual(node['local_addresses'], []) - self.assertEqual(node['properties'], {}) - node = result['changed']['nodes'][1] - self.assertEqual(node['id'], '10.150.0.3') - self.assertEqual(node['label'], '') - self.assertEqual(node['local_addresses'], []) - self.assertEqual(node['properties'], {}) - node = result['changed']['nodes'][2] - self.assertEqual(node['id'], '10.150.0.4') - self.assertEqual(node['label'], '') - self.assertEqual(node['local_addresses'], []) - self.assertEqual(node['properties'], {}) + self.assertIsInstance(result["changed"], dict) + self.assertEqual(len(result["changed"]["nodes"]), 3) + node = result["changed"]["nodes"][0] + self.assertEqual(node["id"], "10.150.0.2") + self.assertEqual(node["label"], "") + self.assertEqual(node["local_addresses"], []) + self.assertEqual(node["properties"], {}) + node = result["changed"]["nodes"][1] + self.assertEqual(node["id"], "10.150.0.3") + self.assertEqual(node["label"], "") + self.assertEqual(node["local_addresses"], []) + self.assertEqual(node["properties"], {}) + node = result["changed"]["nodes"][2] + self.assertEqual(node["id"], "10.150.0.4") + self.assertEqual(node["label"], "") + self.assertEqual(node["local_addresses"], []) + self.assertEqual(node["properties"], {}) def test_simple_diff(self): old = OlsrParser(links3) new = OlsrParser(links5) result = diff(old, new) - self.assertIsNone(result['changed']) + self.assertIsNone(result["changed"]) # ensure there are differences - self.assertEqual(len(result['added']['links']), 3) - self.assertEqual(len(result['removed']['links']), 1) - self.assertEqual(len(result['added']['nodes']), 2) - self.assertEqual(len(result['removed']['nodes']), 1) + self.assertEqual(len(result["added"]["links"]), 3) + self.assertEqual(len(result["removed"]["links"]), 1) + self.assertEqual(len(result["added"]["nodes"]), 2) + self.assertEqual(len(result["removed"]["nodes"]), 1) # ensure 3 links added self._test_expected_links( - graph=result['added'], + graph=result["added"], expected_links=[ - ('10.150.0.3', '10.150.0.7'), - ('10.150.0.3', '10.150.0.6'), - ('10.150.0.7', '10.150.0.6'), + ("10.150.0.3", "10.150.0.7"), + ("10.150.0.3", "10.150.0.6"), + ("10.150.0.7", "10.150.0.6"), ], ) self._test_expected_links( - graph=result['removed'], expected_links=[('10.150.0.5', '10.150.0.4')] + graph=result["removed"], expected_links=[("10.150.0.5", "10.150.0.4")] ) - added_nodes = [node['id'] for node in result['added']['nodes']] - self.assertIn('10.150.0.6', added_nodes) - self.assertIn('10.150.0.7', added_nodes) - self.assertIn('10.150.0.5', result['removed']['nodes'][0].values()) + added_nodes = [node["id"] for node in result["added"]["nodes"]] + self.assertIn("10.150.0.6", added_nodes) + self.assertIn("10.150.0.7", added_nodes) + self.assertIn("10.150.0.5", result["removed"]["nodes"][0].values()) @parameterized.expand( [(links2), (links2_newformat)], name_func=parameterized_test_name_func @@ -272,8 +272,8 @@ def test_simple_diff(self): def test_cost(self, links2): parser = OlsrParser(links2) graph = parser.json(dict=True) - a = graph['links'][0]['cost'] - b = graph['links'][1]['cost'] + a = graph["links"][0]["cost"] + b = graph["links"][1]["cost"] self.assertIn(27.669921875, [a, b]) self.assertIn(1.0, [a, b]) @@ -281,22 +281,22 @@ def test_diff_format(self): old = OlsrParser(links3) new = OlsrParser(links5) result = diff(old, new) - data = result['added'] - self.assertEqual(data['type'], 'NetworkGraph') - self.assertEqual(data['protocol'], 'OLSR') - self.assertEqual(data['version'], '0.6.6') - self.assertEqual(data['revision'], '5031a799fcbe17f61d57e387bc3806de') - self.assertEqual(data['metric'], 'ETX') - self.assertIsInstance(data['nodes'], list) - self.assertIsInstance(data['links'], list) - data = result['removed'] - self.assertEqual(data['type'], 'NetworkGraph') - self.assertEqual(data['protocol'], 'OLSR') - self.assertEqual(data['version'], '0.6.6') - self.assertEqual(data['revision'], '5031a799fcbe17f61d57e387bc3806de') - self.assertEqual(data['metric'], 'ETX') - self.assertIsInstance(data['nodes'], list) - self.assertIsInstance(data['links'], list) + data = result["added"] + self.assertEqual(data["type"], "NetworkGraph") + self.assertEqual(data["protocol"], "OLSR") + self.assertEqual(data["version"], "0.6.6") + self.assertEqual(data["revision"], "5031a799fcbe17f61d57e387bc3806de") + self.assertEqual(data["metric"], "ETX") + self.assertIsInstance(data["nodes"], list) + self.assertIsInstance(data["links"], list) + data = result["removed"] + self.assertEqual(data["type"], "NetworkGraph") + self.assertEqual(data["protocol"], "OLSR") + self.assertEqual(data["version"], "0.6.6") + self.assertEqual(data["revision"], "5031a799fcbe17f61d57e387bc3806de") + self.assertEqual(data["metric"], "ETX") + self.assertIsInstance(data["nodes"], list) + self.assertIsInstance(data["links"], list) @parameterized.expand( [(links2), (links2_newformat)], name_func=parameterized_test_name_func @@ -305,27 +305,27 @@ def test_cost_changes_1(self, links2): old = OlsrParser(links2) new = OlsrParser(links2_cost) result = diff(old, new) - self.assertIsNone(result['added']) - self.assertIsNone(result['removed']) - self.assertIsInstance(result['changed'], dict) - links = result['changed']['links'] + self.assertIsNone(result["added"]) + self.assertIsNone(result["removed"]) + self.assertIsInstance(result["changed"], dict) + links = result["changed"]["links"] self.assertTrue(type(links) is list) self.assertEqual(len(links), 2) # ensure results are correct - self.assertTrue(1.302734375 in (links[0]['cost'], links[1]['cost'])) - self.assertTrue(1.0234375 in (links[0]['cost'], links[1]['cost'])) + self.assertTrue(1.302734375 in (links[0]["cost"], links[1]["cost"])) + self.assertTrue(1.0234375 in (links[0]["cost"], links[1]["cost"])) def test_cost_changes_2(self): old = OlsrParser(links5) new = OlsrParser(links5_cost) result = diff(old, new) - self.assertIsNone(result['added']) - self.assertIsNone(result['removed']) - self.assertIsInstance(result['changed'], dict) - self.assertEqual(len(result['changed']['nodes']), 0) - links = result['changed']['links'] + self.assertIsNone(result["added"]) + self.assertIsNone(result["removed"]) + self.assertIsInstance(result["changed"], dict) + self.assertEqual(len(result["changed"]["nodes"]), 0) + links = result["changed"]["links"] self.assertEqual(len(links), 4) - costs = [link['cost'] for link in links] + costs = [link["cost"] for link in links] self.assertIn(1.0, costs) self.assertIn(2.0, costs) self.assertIn(1.50390625, costs) @@ -340,7 +340,7 @@ def test_link_with_infinite_cost(self): "destinationIP": "10.150.0.3", "linkQuality": 0.195, "neighborLinkQuality": 0.184, - "tcEdgeCost": float('inf'), + "tcEdgeCost": float("inf"), "validityTime": 284572, } ], diff --git a/tests/test_olsr_txtinfo.py b/tests/test_olsr_txtinfo.py index 8adb69b..1d51566 100644 --- a/tests/test_olsr_txtinfo.py +++ b/tests/test_olsr_txtinfo.py @@ -7,12 +7,12 @@ from netdiff.tests import TestCase CURRENT_DIR = os.path.dirname(os.path.realpath(__file__)) -links2 = open('{0}/static/olsr-2-links.txt'.format(CURRENT_DIR)).read() +links2 = open("{0}/static/olsr-2-links.txt".format(CURRENT_DIR)).read() links2_cost = open( - '{0}/static/olsr-2-links-cost-changed.txt'.format(CURRENT_DIR) + "{0}/static/olsr-2-links-cost-changed.txt".format(CURRENT_DIR) ).read() -links3 = open('{0}/static/olsr-3-links.txt'.format(CURRENT_DIR)).read() -links5 = open('{0}/static/olsr-5-links.txt'.format(CURRENT_DIR)).read() +links3 = open("{0}/static/olsr-3-links.txt".format(CURRENT_DIR)).read() +links5 = open("{0}/static/olsr-5-links.txt".format(CURRENT_DIR)).read() class TestOlsrTxtinfoParser(TestCase): @@ -21,49 +21,49 @@ def test_parse(self): self.assertIsInstance(p.graph, networkx.Graph) # test additional properties in networkx graph properties = list(p.graph.edges(data=True))[0][2] - self.assertIsInstance(properties['weight'], float) - self.assertIsInstance(properties['link_quality'], float) - self.assertIsInstance(properties['neighbor_link_quality'], float) + self.assertIsInstance(properties["weight"], float) + self.assertIsInstance(properties["link_quality"], float) + self.assertIsInstance(properties["neighbor_link_quality"], float) # test additional node properties properties = list(p.graph.nodes(data=True))[0][1] - self.assertIsInstance(properties['local_addresses'], list) + self.assertIsInstance(properties["local_addresses"], list) def test_parse_exception_topology(self): with self.assertRaises(ParserError): - OlsrParser('clearly wrong') + OlsrParser("clearly wrong") with self.assertRaises(ParserError): - OlsrParser('Table: Topology\n......') + OlsrParser("Table: Topology\n......") def test_parse_exception_mid(self): with self.assertRaises(ParserError): - OlsrParser('Table: Topology\n\n\nMISSING MID') + OlsrParser("Table: Topology\n\n\nMISSING MID") def test_json_dict(self): p = OlsrParser(links2) data = p.json(dict=True) self.assertIsInstance(data, dict) - self.assertEqual(data['type'], 'NetworkGraph') - self.assertEqual(data['protocol'], 'OLSR') - self.assertEqual(data['version'], '0.8') - self.assertEqual(data['revision'], None) - self.assertEqual(data['metric'], 'ETX') - self.assertIsInstance(data['nodes'], list) - self.assertIsInstance(data['links'], list) - self.assertEqual(len(data['nodes']), 3) - self.assertEqual(len(data['links']), 2) - self.assertIsInstance(data['links'][0]['cost'], float) + self.assertEqual(data["type"], "NetworkGraph") + self.assertEqual(data["protocol"], "OLSR") + self.assertEqual(data["version"], "0.8") + self.assertEqual(data["revision"], None) + self.assertEqual(data["metric"], "ETX") + self.assertIsInstance(data["nodes"], list) + self.assertIsInstance(data["links"], list) + self.assertEqual(len(data["nodes"]), 3) + self.assertEqual(len(data["links"]), 2) + self.assertIsInstance(data["links"][0]["cost"], float) # test additional properties - properties = data['links'][0]['properties'] - self.assertIsInstance(properties['link_quality'], float) - self.assertIsInstance(properties['neighbor_link_quality'], float) + properties = data["links"][0]["properties"] + self.assertIsInstance(properties["link_quality"], float) + self.assertIsInstance(properties["neighbor_link_quality"], float) # test local_addresses - self.assertIsInstance(data['nodes'][0]['local_addresses'], list) + self.assertIsInstance(data["nodes"][0]["local_addresses"], list) found = False - for node in data['nodes']: - if node['id'] == '10.150.0.2': - self.assertEqual(len(node['local_addresses']), 2) - self.assertEqual(node['local_addresses'][0], '172.16.192.2') - self.assertEqual(node['local_addresses'][1], '192.168.0.2') + for node in data["nodes"]: + if node["id"] == "10.150.0.2": + self.assertEqual(len(node["local_addresses"]), 2) + self.assertEqual(node["local_addresses"][0], "172.16.192.2") + self.assertEqual(node["local_addresses"][1], "192.168.0.2") found = True self.assertTrue(found) @@ -71,180 +71,180 @@ def test_json_string(self): p = OlsrParser(links2) data = p.json() self.assertIsInstance(data, str) - self.assertIn('NetworkGraph', data) - self.assertIn('protocol', data) - self.assertIn('version', data) - self.assertIn('revision', data) - self.assertIn('metric', data) - self.assertIn('OLSR', data) - self.assertIn('0.8', data) - self.assertIn('null', data) - self.assertIn('ETX', data) - self.assertIn('links', data) - self.assertIn('nodes', data) + self.assertIn("NetworkGraph", data) + self.assertIn("protocol", data) + self.assertIn("version", data) + self.assertIn("revision", data) + self.assertIn("metric", data) + self.assertIn("OLSR", data) + self.assertIn("0.8", data) + self.assertIn("null", data) + self.assertIn("ETX", data) + self.assertIn("links", data) + self.assertIn("nodes", data) def test_no_changes(self): old = OlsrParser(links2) new = OlsrParser(links2) result = diff(old, new) self.assertIsInstance(result, dict) - self.assertIsNone(result['added']) - self.assertIsNone(result['removed']) - self.assertIsNone(result['changed']) + self.assertIsNone(result["added"]) + self.assertIsNone(result["removed"]) + self.assertIsNone(result["changed"]) def test_added_1_link(self): old = OlsrParser(links2) new = OlsrParser(links3) result = diff(old, new) - self.assertEqual(result['changed']['links'], []) + self.assertEqual(result["changed"]["links"], []) # ensure there are differences - self.assertEqual(len(result['added']['links']), 1) - self.assertEqual(len(result['added']['nodes']), 1) + self.assertEqual(len(result["added"]["links"]), 1) + self.assertEqual(len(result["added"]["nodes"]), 1) # ensure correct link added - self.assertIn('10.150.0.5', result['added']['links'][0].values()) - self.assertIn('10.150.0.4', result['added']['links'][0].values()) + self.assertIn("10.150.0.5", result["added"]["links"][0].values()) + self.assertIn("10.150.0.4", result["added"]["links"][0].values()) # ensure correct node added - self.assertIn('10.150.0.5', result['added']['nodes'][0].values()) + self.assertIn("10.150.0.5", result["added"]["nodes"][0].values()) def test_added_1_link_sub(self): old = OlsrParser(links2) new = OlsrParser(links3) result = new - old - self.assertIsNone(result['removed']) - self.assertEqual(result['changed']['links'], []) + self.assertIsNone(result["removed"]) + self.assertEqual(result["changed"]["links"], []) # ensure there are differences - self.assertEqual(len(result['added']['links']), 1) - self.assertEqual(len(result['added']['nodes']), 1) + self.assertEqual(len(result["added"]["links"]), 1) + self.assertEqual(len(result["added"]["nodes"]), 1) # ensure correct link added - self.assertIn('10.150.0.5', result['added']['links'][0].values()) - self.assertIn('10.150.0.4', result['added']['links'][0].values()) + self.assertIn("10.150.0.5", result["added"]["links"][0].values()) + self.assertIn("10.150.0.4", result["added"]["links"][0].values()) # ensure correct node added - self.assertIn('10.150.0.5', result['added']['nodes'][0].values()) + self.assertIn("10.150.0.5", result["added"]["nodes"][0].values()) def test_removed_1_link(self): old = OlsrParser(links3) new = OlsrParser(links2) result = diff(old, new) - self.assertIsNone(result['added']) - self.assertEqual(result['changed']['links'], []) + self.assertIsNone(result["added"]) + self.assertEqual(result["changed"]["links"], []) self.assertIsInstance(result, dict) - self.assertTrue(type(result['removed']['links']) is list) + self.assertTrue(type(result["removed"]["links"]) is list) # ensure there are differences - self.assertEqual(len(result['removed']['links']), 1) - self.assertEqual(len(result['removed']['nodes']), 1) + self.assertEqual(len(result["removed"]["links"]), 1) + self.assertEqual(len(result["removed"]["nodes"]), 1) # ensure correct link removed - self.assertIn('10.150.0.5', result['removed']['links'][0].values()) - self.assertIn('10.150.0.4', result['removed']['links'][0].values()) + self.assertIn("10.150.0.5", result["removed"]["links"][0].values()) + self.assertIn("10.150.0.4", result["removed"]["links"][0].values()) # ensure correct node removed - self.assertIn('10.150.0.5', result['removed']['nodes'][0].values()) + self.assertIn("10.150.0.5", result["removed"]["nodes"][0].values()) def test_changed_3_nodes(self): old = OlsrParser(links2) new = OlsrParser(links2_cost) result = diff(old, new) - self.assertIsInstance(result['changed'], dict) - self.assertEqual(len(result['changed']['nodes']), 3) - node = result['changed']['nodes'][0] - self.assertEqual(node['id'], '10.150.0.2') - self.assertEqual(node['label'], '') - self.assertEqual(node['local_addresses'], []) - self.assertEqual(node['properties'], {}) - node = result['changed']['nodes'][1] - self.assertEqual(node['id'], '10.150.0.3') - self.assertEqual(node['label'], '') - self.assertEqual(node['local_addresses'], []) - self.assertEqual(node['properties'], {}) - node = result['changed']['nodes'][2] - self.assertEqual(node['id'], '10.150.0.4') - self.assertEqual(node['label'], '') - self.assertEqual(node['local_addresses'], []) - self.assertEqual(node['properties'], {}) + self.assertIsInstance(result["changed"], dict) + self.assertEqual(len(result["changed"]["nodes"]), 3) + node = result["changed"]["nodes"][0] + self.assertEqual(node["id"], "10.150.0.2") + self.assertEqual(node["label"], "") + self.assertEqual(node["local_addresses"], []) + self.assertEqual(node["properties"], {}) + node = result["changed"]["nodes"][1] + self.assertEqual(node["id"], "10.150.0.3") + self.assertEqual(node["label"], "") + self.assertEqual(node["local_addresses"], []) + self.assertEqual(node["properties"], {}) + node = result["changed"]["nodes"][2] + self.assertEqual(node["id"], "10.150.0.4") + self.assertEqual(node["label"], "") + self.assertEqual(node["local_addresses"], []) + self.assertEqual(node["properties"], {}) def test_simple_diff(self): old = OlsrParser(links3) new = OlsrParser(links5) result = diff(old, new) - self.assertEqual(result['changed']['nodes'], []) - self.assertEqual(len(result['changed']['links']), 1) - link = result['changed']['links'][0] - self.assertEqual(link['source'], '10.150.0.3') - self.assertEqual(link['target'], '10.150.0.2') - self.assertEqual(link['cost'], 27.669) - self.assertEqual(link['cost_text'], '') + self.assertEqual(result["changed"]["nodes"], []) + self.assertEqual(len(result["changed"]["links"]), 1) + link = result["changed"]["links"][0] + self.assertEqual(link["source"], "10.150.0.3") + self.assertEqual(link["target"], "10.150.0.2") + self.assertEqual(link["cost"], 27.669) + self.assertEqual(link["cost_text"], "") self.assertEqual( - link['properties'], {'neighbor_link_quality': 0.184, 'link_quality': 0.195} + link["properties"], {"neighbor_link_quality": 0.184, "link_quality": 0.195} ) # ensure there are differences - self.assertEqual(len(result['added']['links']), 3) - self.assertEqual(len(result['removed']['links']), 1) - self.assertEqual(len(result['added']['nodes']), 2) - self.assertEqual(len(result['removed']['nodes']), 1) + self.assertEqual(len(result["added"]["links"]), 3) + self.assertEqual(len(result["removed"]["links"]), 1) + self.assertEqual(len(result["added"]["nodes"]), 2) + self.assertEqual(len(result["removed"]["nodes"]), 1) # ensure 3 links added self._test_expected_links( - graph=result['added'], + graph=result["added"], expected_links=[ - ('10.150.0.3', '10.150.0.7'), - ('10.150.0.3', '10.150.0.6'), - ('10.150.0.7', '10.150.0.6'), + ("10.150.0.3", "10.150.0.7"), + ("10.150.0.3", "10.150.0.6"), + ("10.150.0.7", "10.150.0.6"), ], ) self._test_expected_links( - graph=result['removed'], expected_links=[('10.150.0.5', '10.150.0.4')] + graph=result["removed"], expected_links=[("10.150.0.5", "10.150.0.4")] ) - added_nodes = [node['id'] for node in result['added']['nodes']] - self.assertIn('10.150.0.6', added_nodes) - self.assertIn('10.150.0.7', added_nodes) - self.assertIn('10.150.0.5', result['removed']['nodes'][0].values()) + added_nodes = [node["id"] for node in result["added"]["nodes"]] + self.assertIn("10.150.0.6", added_nodes) + self.assertIn("10.150.0.7", added_nodes) + self.assertIn("10.150.0.5", result["removed"]["nodes"][0].values()) def test_cost(self): parser = OlsrParser(links2) graph = parser.json(dict=True) - self.assertEqual(27.669, graph['links'][0]['cost']) - self.assertEqual(1.0, graph['links'][1]['cost']) + self.assertEqual(27.669, graph["links"][0]["cost"]) + self.assertEqual(1.0, graph["links"][1]["cost"]) def test_diff_format(self): old = OlsrParser(links3) new = OlsrParser(links5) result = diff(old, new) - data = result['added'] - self.assertEqual(data['type'], 'NetworkGraph') - self.assertEqual(data['protocol'], 'OLSR') - self.assertEqual(data['version'], '0.8') - self.assertEqual(data['revision'], None) - self.assertEqual(data['metric'], 'ETX') - self.assertIsInstance(data['nodes'], list) - self.assertIsInstance(data['links'], list) - data = result['removed'] - self.assertEqual(data['type'], 'NetworkGraph') - self.assertEqual(data['protocol'], 'OLSR') - self.assertEqual(data['version'], '0.8') - self.assertEqual(data['revision'], None) - self.assertEqual(data['metric'], 'ETX') - self.assertIsInstance(data['nodes'], list) - self.assertIsInstance(data['links'], list) - data = result['changed'] - self.assertEqual(data['type'], 'NetworkGraph') - self.assertEqual(data['protocol'], 'OLSR') - self.assertEqual(data['version'], '0.8') - self.assertEqual(data['revision'], None) - self.assertEqual(data['metric'], 'ETX') - self.assertIsInstance(data['nodes'], list) - self.assertIsInstance(data['links'], list) + data = result["added"] + self.assertEqual(data["type"], "NetworkGraph") + self.assertEqual(data["protocol"], "OLSR") + self.assertEqual(data["version"], "0.8") + self.assertEqual(data["revision"], None) + self.assertEqual(data["metric"], "ETX") + self.assertIsInstance(data["nodes"], list) + self.assertIsInstance(data["links"], list) + data = result["removed"] + self.assertEqual(data["type"], "NetworkGraph") + self.assertEqual(data["protocol"], "OLSR") + self.assertEqual(data["version"], "0.8") + self.assertEqual(data["revision"], None) + self.assertEqual(data["metric"], "ETX") + self.assertIsInstance(data["nodes"], list) + self.assertIsInstance(data["links"], list) + data = result["changed"] + self.assertEqual(data["type"], "NetworkGraph") + self.assertEqual(data["protocol"], "OLSR") + self.assertEqual(data["version"], "0.8") + self.assertEqual(data["revision"], None) + self.assertEqual(data["metric"], "ETX") + self.assertIsInstance(data["nodes"], list) + self.assertIsInstance(data["links"], list) def test_cost_changes_1(self): old = OlsrParser(links2) new = OlsrParser(links2_cost) result = diff(old, new) - self.assertIsNone(result['added']) - self.assertIsNone(result['removed']) - self.assertIsInstance(result['changed'], dict) - self.assertEqual(len(result['changed']['nodes']), 3) - self.assertIsInstance(result['changed']['links'], list) - self.assertEqual(len(result['changed']['links']), 2) - links = result['changed']['links'] + self.assertIsNone(result["added"]) + self.assertIsNone(result["removed"]) + self.assertIsInstance(result["changed"], dict) + self.assertEqual(len(result["changed"]["nodes"]), 3) + self.assertIsInstance(result["changed"]["links"], list) + self.assertEqual(len(result["changed"]["links"]), 2) + links = result["changed"]["links"] # ensure results are correct - self.assertTrue(links[0]['cost'], 1.302) - self.assertTrue(links[1]['cost'], 1.023) + self.assertTrue(links[0]["cost"], 1.302) + self.assertTrue(links[1]["cost"], 1.023) def test_link_with_infinite_cost(self): data = """Table: Topology diff --git a/tests/test_openvpn.py b/tests/test_openvpn.py index 5ea83fb..4253527 100644 --- a/tests/test_openvpn.py +++ b/tests/test_openvpn.py @@ -7,139 +7,139 @@ from netdiff.tests import TestCase CURRENT_DIR = os.path.dirname(os.path.realpath(__file__)) -links2 = open('{0}/static/openvpn-2-links.txt'.format(CURRENT_DIR)).read() -links2undef = open('{0}/static/openvpn-2-links-undef.txt'.format(CURRENT_DIR)).read() -links5_tap = open('{0}/static/openvpn-5-links-tap.txt'.format(CURRENT_DIR)).read() -bug = open('{0}/static/openvpn-bug.txt'.format(CURRENT_DIR)).read() -special_case = open('{0}/static/openvpn-special-case.txt'.format(CURRENT_DIR)).read() +links2 = open("{0}/static/openvpn-2-links.txt".format(CURRENT_DIR)).read() +links2undef = open("{0}/static/openvpn-2-links-undef.txt".format(CURRENT_DIR)).read() +links5_tap = open("{0}/static/openvpn-5-links-tap.txt".format(CURRENT_DIR)).read() +bug = open("{0}/static/openvpn-bug.txt".format(CURRENT_DIR)).read() +special_case = open("{0}/static/openvpn-special-case.txt".format(CURRENT_DIR)).read() class TestOpenvpnParser(TestCase): def test_parse(self): p = OpenvpnParser(links2) self.assertIsInstance(p.graph, networkx.Graph) - self.assertEqual(p.version, '1') - self.assertEqual(p.metric, 'static') + self.assertEqual(p.version, "1") + self.assertEqual(p.metric, "static") def test_parse_undef(self): p = OpenvpnParser(links2undef) data = p.json(dict=True) self.assertIsInstance(p.graph, networkx.Graph) # we expect 1 node (only the openvpn server) - self.assertEqual(len(data['nodes']), 1) - self.assertEqual(len(data['links']), 0) + self.assertEqual(len(data["nodes"]), 1) + self.assertEqual(len(data["links"]), 0) def test_json_dict(self): p = OpenvpnParser(links2) data = p.json(dict=True) self.assertIsInstance(data, dict) - self.assertEqual(data['type'], 'NetworkGraph') - self.assertEqual(data['protocol'], 'OpenVPN Status Log') - self.assertEqual(data['version'], '1') - self.assertEqual(data['revision'], None) - self.assertEqual(data['metric'], 'static') - self.assertIsInstance(data['nodes'], list) - self.assertIsInstance(data['links'], list) - self.assertEqual(len(data['nodes']), 3) - self.assertEqual(len(data['links']), 2) + self.assertEqual(data["type"], "NetworkGraph") + self.assertEqual(data["protocol"], "OpenVPN Status Log") + self.assertEqual(data["version"], "1") + self.assertEqual(data["revision"], None) + self.assertEqual(data["metric"], "static") + self.assertIsInstance(data["nodes"], list) + self.assertIsInstance(data["links"], list) + self.assertEqual(len(data["nodes"]), 3) + self.assertEqual(len(data["links"]), 2) # check presence of labels labels = [] - for node in data['nodes']: - if 'label' in node: - labels.append(node['label']) + for node in data["nodes"]: + if "label" in node: + labels.append(node["label"]) self.assertEqual(len(labels), 3) - self.assertIn('nodeA', labels) - self.assertIn('nodeB', labels) - self.assertIn('', labels) + self.assertIn("nodeA", labels) + self.assertIn("nodeB", labels) + self.assertIn("", labels) def test_json_dict_tap(self): p = OpenvpnParser(links5_tap) data = p.json(dict=True) self.assertIsInstance(data, dict) - self.assertEqual(data['type'], 'NetworkGraph') - self.assertEqual(data['protocol'], 'OpenVPN Status Log') - self.assertEqual(data['version'], '1') - self.assertEqual(data['revision'], None) - self.assertEqual(data['metric'], 'static') - self.assertIsInstance(data['nodes'], list) - self.assertIsInstance(data['links'], list) - self.assertEqual(len(data['nodes']), 6) - self.assertEqual(len(data['links']), 5) + self.assertEqual(data["type"], "NetworkGraph") + self.assertEqual(data["protocol"], "OpenVPN Status Log") + self.assertEqual(data["version"], "1") + self.assertEqual(data["revision"], None) + self.assertEqual(data["metric"], "static") + self.assertIsInstance(data["nodes"], list) + self.assertIsInstance(data["links"], list) + self.assertEqual(len(data["nodes"]), 6) + self.assertEqual(len(data["links"]), 5) labels = [] - for node in data['nodes']: - if 'label' in node: - labels.append(node['label']) + for node in data["nodes"]: + if "label" in node: + labels.append(node["label"]) self.assertEqual(len(labels), 6) - self.assertIn('nodeA', labels) - self.assertIn('nodeB', labels) - self.assertIn('nodeC', labels) - self.assertIn('nodeD', labels) - self.assertIn('nodeE', labels) - self.assertIn('', labels) + self.assertIn("nodeA", labels) + self.assertIn("nodeB", labels) + self.assertIn("nodeC", labels) + self.assertIn("nodeD", labels) + self.assertIn("nodeE", labels) + self.assertIn("", labels) def test_bogus_data(self): try: - OpenvpnParser(data='{%$^*([[zsde4323@#}') + OpenvpnParser(data="{%$^*([[zsde4323@#}") except ConversionException: pass else: - self.fail('ConversionException not raised') + self.fail("ConversionException not raised") def test_empty_dict(self): OpenvpnParser(data={}) def test_empty_string(self): - OpenvpnParser(data='') + OpenvpnParser(data="") def test_label_diff_added(self): old = OpenvpnParser({}) new = OpenvpnParser(links5_tap) result = diff(old, new) labels = [] - for node in result['added']['nodes']: - if 'label' in node: - labels.append(node['label']) + for node in result["added"]["nodes"]: + if "label" in node: + labels.append(node["label"]) self.assertEqual(len(labels), 5) - self.assertIn('nodeA', labels) - self.assertIn('nodeB', labels) - self.assertIn('nodeC', labels) - self.assertIn('nodeD', labels) - self.assertIn('nodeE', labels) + self.assertIn("nodeA", labels) + self.assertIn("nodeB", labels) + self.assertIn("nodeC", labels) + self.assertIn("nodeD", labels) + self.assertIn("nodeE", labels) def test_parse_bug(self): p = OpenvpnParser(bug, duplicate_cn=True) data = p.json(dict=True) self.assertIsInstance(p.graph, networkx.Graph) - with self.subTest('Count nodes and links'): - self.assertEqual(len(data['nodes']), 7) - self.assertEqual(len(data['links']), 6) + with self.subTest("Count nodes and links"): + self.assertEqual(len(data["nodes"]), 7) + self.assertEqual(len(data["links"]), 6) labels = [] - for node in data['nodes']: - labels.append(node['label']) + for node in data["nodes"]: + labels.append(node["label"]) expected = { - '60c5a8fffe77607a', - '60c5a8fffe77606b', - '60C5A8FFFE74CB6D', - '60c5a8fffe77607a', - '58a0cbeffe0176d4', - '58a0cbeffe0156b0', - '', + "60c5a8fffe77607a", + "60c5a8fffe77606b", + "60C5A8FFFE74CB6D", + "60c5a8fffe77607a", + "58a0cbeffe0176d4", + "58a0cbeffe0156b0", + "", } - with self.subTest('Check contents of nodes'): + with self.subTest("Check contents of nodes"): self.assertEqual(expected, set(labels)) targets = [] - for link in data['links']: - targets.append(link['target']) + for link in data["links"]: + targets.append(link["target"]) expected = { - '60c5a8fffe77607a,185.211.160.5', - '60c5a8fffe77606b,185.211.160.87', - '60C5A8FFFE74CB6D,194.183.10.51', - '60c5a8fffe77607a,194.183.10.51', - '58a0cbeffe0176d4,195.94.160.52', - '58a0cbeffe0156b0,217.72.97.67', + "60c5a8fffe77607a,185.211.160.5", + "60c5a8fffe77606b,185.211.160.87", + "60C5A8FFFE74CB6D,194.183.10.51", + "60c5a8fffe77607a,194.183.10.51", + "58a0cbeffe0176d4,195.94.160.52", + "58a0cbeffe0156b0,217.72.97.67", } self.assertEqual(expected, set(targets)) @@ -148,35 +148,35 @@ def test_parse_bug_duplicate_cn(self): data = p.json(dict=True) self.assertIsInstance(p.graph, networkx.Graph) - with self.subTest('Count nodes and links'): - self.assertEqual(len(data['nodes']), 7) - self.assertEqual(len(data['links']), 6) + with self.subTest("Count nodes and links"): + self.assertEqual(len(data["nodes"]), 7) + self.assertEqual(len(data["links"]), 6) labels = [] - for node in data['nodes']: - labels.append(node['label']) + for node in data["nodes"]: + labels.append(node["label"]) expected = { - '60c5a8fffe77607a', - '60c5a8fffe77606b', - '60C5A8FFFE74CB6D', - '60c5a8fffe77607a', - '58a0cbeffe0176d4', - '58a0cbeffe0156b0', - '', + "60c5a8fffe77607a", + "60c5a8fffe77606b", + "60C5A8FFFE74CB6D", + "60c5a8fffe77607a", + "58a0cbeffe0176d4", + "58a0cbeffe0156b0", + "", } - with self.subTest('Check contents of nodes'): + with self.subTest("Check contents of nodes"): self.assertEqual(expected, set(labels)) targets = [] - for link in data['links']: - targets.append(link['target']) + for link in data["links"]: + targets.append(link["target"]) expected = { - '60c5a8fffe77607a,185.211.160.5', - '60c5a8fffe77606b,185.211.160.87', - '60C5A8FFFE74CB6D,194.183.10.51', - '60c5a8fffe77607a,194.183.10.51', - '58a0cbeffe0176d4,195.94.160.52', - '58a0cbeffe0156b0,217.72.97.67', + "60c5a8fffe77607a,185.211.160.5", + "60c5a8fffe77606b,185.211.160.87", + "60C5A8FFFE74CB6D,194.183.10.51", + "60c5a8fffe77607a,194.183.10.51", + "58a0cbeffe0176d4,195.94.160.52", + "58a0cbeffe0156b0,217.72.97.67", } self.assertEqual(expected, set(targets)) @@ -190,31 +190,31 @@ def test_parse_special_case_duplicate_cn(self): p = OpenvpnParser(special_case, duplicate_cn=True) data = p.json(dict=True) self.assertIsInstance(p.graph, networkx.Graph) - with self.subTest('Count nodes and links'): - self.assertEqual(len(data['nodes']), 5) - self.assertEqual(len(data['links']), 4) + with self.subTest("Count nodes and links"): + self.assertEqual(len(data["nodes"]), 5) + self.assertEqual(len(data["links"]), 4) id_list = [] - for node in data['nodes']: - id_list.append(node['id']) + for node in data["nodes"]: + id_list.append(node["id"]) expected = { - '60c5a8fffe77607a,194.183.10.51:49794', - '60c5a8fffe77607a,194.183.10.51:60003', - '60c5a8fffe77607a,217.72.97.66', - '58a0cbeffe0156b0,217.72.97.67', - 'openvpn-server', + "60c5a8fffe77607a,194.183.10.51:49794", + "60c5a8fffe77607a,194.183.10.51:60003", + "60c5a8fffe77607a,217.72.97.66", + "58a0cbeffe0156b0,217.72.97.67", + "openvpn-server", } - with self.subTest('Check contents of nodes'): + with self.subTest("Check contents of nodes"): self.assertEqual(expected, set(id_list)) targets = [] - for link in data['links']: - targets.append(link['target']) + for link in data["links"]: + targets.append(link["target"]) expected = { - '60c5a8fffe77607a,194.183.10.51:49794', - '60c5a8fffe77607a,194.183.10.51:60003', - '60c5a8fffe77607a,217.72.97.66', - '58a0cbeffe0156b0,217.72.97.67', + "60c5a8fffe77607a,194.183.10.51:49794", + "60c5a8fffe77607a,194.183.10.51:60003", + "60c5a8fffe77607a,217.72.97.66", + "58a0cbeffe0156b0,217.72.97.67", } self.assertEqual(expected, set(targets)) @@ -223,12 +223,12 @@ def test_common_name_as_id(self): new = OpenvpnParser(links5_tap) result = diff(old, new) id_list = [] - for node in result['added']['nodes']: - id_list.append(node['id']) - self.assertEqual(node['id'], node['properties']['common_name']) + for node in result["added"]["nodes"]: + id_list.append(node["id"]) + self.assertEqual(node["id"], node["properties"]["common_name"]) self.assertEqual(len(id_list), 5) - self.assertIn('nodeA', id_list) - self.assertIn('nodeB', id_list) - self.assertIn('nodeC', id_list) - self.assertIn('nodeD', id_list) - self.assertIn('nodeE', id_list) + self.assertIn("nodeA", id_list) + self.assertIn("nodeB", id_list) + self.assertIn("nodeC", id_list) + self.assertIn("nodeD", id_list) + self.assertIn("nodeE", id_list) diff --git a/tests/test_utils.py b/tests/test_utils.py index 4a3ea14..2e3fe8b 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -4,7 +4,7 @@ from netdiff.tests import TestCase CURRENT_DIR = os.path.dirname(os.path.realpath(__file__)) -links2 = open('{0}/static/netjson-2-links.json'.format(CURRENT_DIR)).read() +links2 = open("{0}/static/netjson-2-links.json".format(CURRENT_DIR)).read() class TestUtils(TestCase): @@ -44,12 +44,12 @@ def test_same_nodes_but_added_links(self): ) new = NetJsonParser(links2) result = diff(old, new) - self.assertIsNone(result['removed']) - self.assertEqual(len(result['changed']['nodes']), 2) - self.assertEqual(len(result['changed']['links']), 0) - self.assertIsNotNone(result['added']) - self.assertEqual(len(result['added']['links']), 2) - self.assertEqual(len(result['added']['nodes']), 0) + self.assertIsNone(result["removed"]) + self.assertEqual(len(result["changed"]["nodes"]), 2) + self.assertEqual(len(result["changed"]["links"]), 0) + self.assertIsNotNone(result["added"]) + self.assertEqual(len(result["added"]["links"]), 2) + self.assertEqual(len(result["added"]["nodes"]), 0) def test_same_nodes_but_removed_links(self): """ @@ -79,8 +79,8 @@ def test_same_nodes_but_removed_links(self): } ) result = diff(old, new) - self.assertIsNone(result['changed']) - self.assertIsNone(result['added']) - self.assertIsNotNone(result['removed']) - self.assertEqual(len(result['removed']['nodes']), 0) - self.assertEqual(len(result['removed']['links']), 1) + self.assertIsNone(result["changed"]) + self.assertIsNone(result["added"]) + self.assertIsNotNone(result["removed"]) + self.assertEqual(len(result["removed"]["nodes"]), 0) + self.assertEqual(len(result["removed"]["links"]), 1) diff --git a/tests/test_wireguard.py b/tests/test_wireguard.py index 1eb23fd..7f45215 100644 --- a/tests/test_wireguard.py +++ b/tests/test_wireguard.py @@ -7,16 +7,16 @@ from netdiff.tests import TestCase CURRENT_DIR = os.path.dirname(os.path.realpath(__file__)) -wg_dump = open('{0}/static/wg-dump.txt'.format(CURRENT_DIR)).read() -wg_dump_updated = open('{0}/static/wg-dump-2.txt'.format(CURRENT_DIR)).read() +wg_dump = open("{0}/static/wg-dump.txt".format(CURRENT_DIR)).read() +wg_dump_updated = open("{0}/static/wg-dump-2.txt".format(CURRENT_DIR)).read() wg_dump_no_allowed_ip = open( - '{0}/static/wg-dump-allowed-ip-absent.txt'.format(CURRENT_DIR) + "{0}/static/wg-dump-allowed-ip-absent.txt".format(CURRENT_DIR) ).read() class TestWireguardParser(TestCase): def setUp(self): - self.freezer = freeze_time('2022-06-06 17:03:38') + self.freezer = freeze_time("2022-06-06 17:03:38") self.freezer.start() return super().setUp() @@ -27,28 +27,28 @@ def tearDown(self): def test_parse(self): p = WireguardParser(wg_dump) original_data = p.original_data - self.assertEqual(list(original_data.keys()), ['wg0', 'wg1']) + self.assertEqual(list(original_data.keys()), ["wg0", "wg1"]) self.assertEqual( - list(original_data['wg0'].keys()), - ['public_key', 'listen_port', 'fwmark', 'peers'], + list(original_data["wg0"].keys()), + ["public_key", "listen_port", "fwmark", "peers"], ) self.assertEqual( - list(original_data['wg0']['peers'][0].values()), + list(original_data["wg0"]["peers"][0].values()), [ { - 'preshared_key': None, - 'endpoint': '192.168.200.210:41100', - 'latest_handshake': '2022-06-06T17:03:38Z', - 'transfer_rx': '37384', - 'transfer_tx': '35848', - 'persistent_keepalive': 'off', - 'allowed_ips': ['10.254.0.2/32'], - 'connected': True, + "preshared_key": None, + "endpoint": "192.168.200.210:41100", + "latest_handshake": "2022-06-06T17:03:38Z", + "transfer_rx": "37384", + "transfer_tx": "35848", + "persistent_keepalive": "off", + "allowed_ips": ["10.254.0.2/32"], + "connected": True, } ], ) - self.assertEqual(len(original_data['wg0']['peers']), 8) - self.assertEqual(len(original_data['wg1']['peers']), 2) + self.assertEqual(len(original_data["wg0"]["peers"]), 8) + self.assertEqual(len(original_data["wg1"]["peers"]), 2) graph = p.graph self.assertIsNotNone(graph) self.assertEqual(len(graph.nodes), 7) @@ -56,32 +56,32 @@ def test_parse(self): def test_parse_exception(self): with self.assertRaises(ParserError): - WireguardParser('WRONG') + WireguardParser("WRONG") def test_parse_allowed_ips_absent(self): p = WireguardParser(wg_dump_no_allowed_ip) original_data = p.original_data - self.assertEqual(list(original_data.keys()), ['wg0']) + self.assertEqual(list(original_data.keys()), ["wg0"]) self.assertEqual( - list(original_data['wg0'].keys()), - ['public_key', 'listen_port', 'fwmark', 'peers'], + list(original_data["wg0"].keys()), + ["public_key", "listen_port", "fwmark", "peers"], ) self.assertEqual( - list(original_data['wg0']['peers'][0].values()), + list(original_data["wg0"]["peers"][0].values()), [ { - 'preshared_key': None, - 'endpoint': '192.168.200.210:41100', - 'latest_handshake': '2022-06-06T17:03:38Z', - 'transfer_rx': '37384', - 'transfer_tx': '35848', - 'persistent_keepalive': 'off', - 'allowed_ips': [], - 'connected': True, + "preshared_key": None, + "endpoint": "192.168.200.210:41100", + "latest_handshake": "2022-06-06T17:03:38Z", + "transfer_rx": "37384", + "transfer_tx": "35848", + "persistent_keepalive": "off", + "allowed_ips": [], + "connected": True, } ], ) - self.assertEqual(len(original_data['wg0']['peers']), 1) + self.assertEqual(len(original_data["wg0"]["peers"]), 1) graph = p.graph self.assertIsNotNone(graph) self.assertEqual(len(graph.nodes), 2) @@ -94,22 +94,22 @@ def test_wireguard_link_update(self): old = WireguardParser(wg_dump) new = WireguardParser(wg_dump_updated) result = diff(old, new) - with self.subTest('test links addition'): - added = result.get('added') - links = added.get('links') + with self.subTest("test links addition"): + added = result.get("added") + links = added.get("links") self.assertEqual(len(links), 1) - self.assertEqual(links[0].get('source'), 'wg0') - with self.subTest('test links deletion'): - removed = result.get('removed') - links = removed.get('links') + self.assertEqual(links[0].get("source"), "wg0") + with self.subTest("test links deletion"): + removed = result.get("removed") + links = removed.get("links") self.assertEqual(len(links), 1) - self.assertEqual(links[0].get('source'), 'wg1') - with self.subTest('test links modification'): - changed = result.get('changed') - nodes = changed.get('nodes') - links = changed.get('links') + self.assertEqual(links[0].get("source"), "wg1") + with self.subTest("test links modification"): + changed = result.get("changed") + nodes = changed.get("nodes") + links = changed.get("links") self.assertEqual(len(nodes), 1) self.assertEqual(len(links), 0) self.assertEqual( - nodes[0].get('id'), 'w6xev2DEpaxqgGIOVh8Ggmmr8BYsTEnSpy/3EQ9DfQw=' + nodes[0].get("id"), "w6xev2DEpaxqgGIOVh8Ggmmr8BYsTEnSpy/3EQ9DfQw=" ) diff --git a/tests/test_zerotier.py b/tests/test_zerotier.py index ca01f48..6a5fb73 100644 --- a/tests/test_zerotier.py +++ b/tests/test_zerotier.py @@ -7,29 +7,29 @@ from netdiff.tests import TestCase CURRENT_DIR = os.path.dirname(os.path.realpath(__file__)) -zt_peers = open(f'{CURRENT_DIR}/static/zt-peers.json').read() -zt_peers_updated = open(f'{CURRENT_DIR}/static/zt-peers-updated.json').read() +zt_peers = open(f"{CURRENT_DIR}/static/zt-peers.json").read() +zt_peers_updated = open(f"{CURRENT_DIR}/static/zt-peers-updated.json").read() class TestZeroTierParser(TestCase): _TEST_PATH_KEYS = [ - 'weight', - 'active', - 'expired', - 'lastReceive', - 'lastSend', - 'localSocket', - 'preferred', - 'trustedPathId', + "weight", + "active", + "expired", + "lastReceive", + "lastSend", + "localSocket", + "preferred", + "trustedPathId", ] _TEST_PEER_KEYS = [ - 'label', - 'address', - 'ip_address', - 'role', - 'version', - 'tunneled', - 'isBonded', + "label", + "address", + "ip_address", + "role", + "version", + "tunneled", + "isBonded", ] def test_parse(self): @@ -50,13 +50,13 @@ def test_parse(self): controller_properties = controller[1] node1_properties = node1[1] node2_properties = node2[1] - self.assertEqual(edge1[0], 'controller') - self.assertEqual(edge1[1], '3504e2b2e2') + self.assertEqual(edge1[0], "controller") + self.assertEqual(edge1[1], "3504e2b2e2") self.assertEqual(list(edge1_properties.keys()), self._TEST_PATH_KEYS) - self.assertEqual(edge2[0], 'controller') - self.assertEqual(edge2[1], '4a9e1c6f14') + self.assertEqual(edge2[0], "controller") + self.assertEqual(edge2[1], "4a9e1c6f14") self.assertEqual(list(edge2_properties.keys()), self._TEST_PATH_KEYS) - self.assertEqual(controller_properties, {'label': 'controller'}) + self.assertEqual(controller_properties, {"label": "controller"}) self.assertEqual(list(node1_properties.keys()), self._TEST_PEER_KEYS) self.assertEqual(list(node2_properties.keys()), self._TEST_PEER_KEYS) @@ -64,32 +64,32 @@ def test_json_dict(self): p = ZeroTierParser(zt_peers) data = p.json(dict=True) self.assertIsInstance(data, dict) - self.assertEqual(data['type'], 'NetworkGraph') - self.assertEqual(data['protocol'], 'ZeroTier Controller Peers') - self.assertEqual(data['version'], '1') - self.assertEqual(data['revision'], None) - self.assertEqual(data['metric'], 'static') - self.assertIsInstance(data['nodes'], list) - self.assertIsInstance(data['links'], list) - self.assertEqual(len(data['nodes']), 3) - self.assertEqual(len(data['links']), 2) + self.assertEqual(data["type"], "NetworkGraph") + self.assertEqual(data["protocol"], "ZeroTier Controller Peers") + self.assertEqual(data["version"], "1") + self.assertEqual(data["revision"], None) + self.assertEqual(data["metric"], "static") + self.assertIsInstance(data["nodes"], list) + self.assertIsInstance(data["links"], list) + self.assertEqual(len(data["nodes"]), 3) + self.assertEqual(len(data["links"]), 2) # check presence of labels labels = [] - for node in data['nodes']: - if 'label' in node: - labels.append(node['label']) + for node in data["nodes"]: + if "label" in node: + labels.append(node["label"]) self.assertEqual(len(labels), 3) - self.assertIn('controller', labels) - self.assertIn('3504e2b2e2', labels) - self.assertIn('4a9e1c6f14', labels) + self.assertIn("controller", labels) + self.assertIn("3504e2b2e2", labels) + self.assertIn("4a9e1c6f14", labels) def test_bogus_data(self): try: - ZeroTierParser(data='{%$^*([[zsde4323@#}') + ZeroTierParser(data="{%$^*([[zsde4323@#}") except ConversionException: pass else: - self.fail('ConversionException not raised') + self.fail("ConversionException not raised") def test_empty_dict(self): ZeroTierParser(data={}) @@ -99,39 +99,39 @@ def test_no_changes(self): new = ZeroTierParser(zt_peers) result = diff(old, new) self.assertIsInstance(result, dict) - self.assertIsNone(result['added']) - self.assertIsNone(result['removed']) - self.assertIsNone(result['changed']) + self.assertIsNone(result["added"]) + self.assertIsNone(result["removed"]) + self.assertIsNone(result["changed"]) def test_zerotier_link_update(self): old = ZeroTierParser(zt_peers) new = ZeroTierParser(zt_peers_updated) result = diff(old, new) - with self.subTest('test links addition'): - added = result.get('added') - links = added.get('links') + with self.subTest("test links addition"): + added = result.get("added") + links = added.get("links") self.assertEqual(len(links), 1) - self.assertEqual(links[0].get('source'), 'controller') - self.assertEqual(links[0].get('target'), '9a9e1c9f19') + self.assertEqual(links[0].get("source"), "controller") + self.assertEqual(links[0].get("target"), "9a9e1c9f19") - with self.subTest('test links deletion'): - removed = result.get('removed') - links = removed.get('links') + with self.subTest("test links deletion"): + removed = result.get("removed") + links = removed.get("links") self.assertEqual(len(links), 1) - self.assertEqual(links[0].get('source'), 'controller') - self.assertEqual(links[0].get('target'), '4a9e1c6f14') + self.assertEqual(links[0].get("source"), "controller") + self.assertEqual(links[0].get("target"), "4a9e1c6f14") - with self.subTest('test links modification'): - changed = result.get('changed') - nodes = changed.get('nodes') - links = changed.get('links') + with self.subTest("test links modification"): + changed = result.get("changed") + nodes = changed.get("nodes") + links = changed.get("links") # If the IP address of the active link changes, # then the ip_address property of the # node will also be modified accordingly self.assertEqual(len(nodes), 1) self.assertEqual(len(links), 1) - self.assertEqual(links[0].get('cost'), 9) + self.assertEqual(links[0].get("cost"), 9) self.assertEqual( - nodes[0].get('properties').get('ip_address'), '192.168.56.1/44221' + nodes[0].get("properties").get("ip_address"), "192.168.56.1/44221" )