def diff(old, new):
protocol = new.protocol<EOL>version = new.version<EOL>revision = new.revision<EOL>metric = new.metric<EOL>in_both = _find_unchanged(old.graph, new.graph)<EOL>added_nodes, added_edges = _make_diff(old.graph, new.graph, in_both)<EOL>removed_nodes, removed_edges = _make_diff(new.graph, old.graph, in_both)<EOL>changed_edges = _find_changed(old.graph, new.graph, in_both)<EOL>if added_nodes.nodes() or added_edges.edges():<EOL><INDENT>added = _netjson_networkgraph(protocol, version, revision, metric,<EOL>added_nodes.nodes(data=True),<EOL>added_edges.edges(data=True),<EOL>dict=True)<EOL><DEDENT>else:<EOL><INDENT>added = None<EOL><DEDENT>if removed_nodes.nodes() or removed_edges.edges():<EOL><INDENT>removed = _netjson_networkgraph(protocol, version, revision, metric,<EOL>removed_nodes.nodes(data=True),<EOL>removed_edges.edges(data=True),<EOL>dict=True)<EOL><DEDENT>else:<EOL><INDENT>removed = None<EOL><DEDENT>if changed_edges:<EOL><INDENT>changed = _netjson_networkgraph(protocol, version, revision, metric,<EOL>[],<EOL>changed_edges,<EOL>dict=True)<EOL><DEDENT>else:<EOL><INDENT>changed = None<EOL><DEDENT>return OrderedDict((<EOL>('<STR_LIT>', added),<EOL>('<STR_LIT>', removed),<EOL>('<STR_LIT>', changed)<EOL>))<EOL>
Returns differences of two network topologies old and new
in NetJSON NetworkGraph compatible format