def json(self):
nodes = []<EOL>links = []<EOL>for link in self.link_set.all():<EOL><INDENT>if self.is_layer2:<EOL><INDENT>source = link.interface_a.mac<EOL>destination = link.interface_b.mac<EOL><DEDENT>else:<EOL><INDENT>source = str(link.interface_a.ip_set.first().address)<EOL>destination = str(link.interface_b.ip_set.first().address)<EOL><DEDENT>nodes.append({<EOL>'<STR_LIT:id>': source<EOL>})<EOL>nodes.append({<EOL>'<STR_LIT:id>': destination<EOL>})<EOL>links.append(OrderedDict((<EOL>('<STR_LIT:source>', source),<EOL>('<STR_LIT:target>', destination),<EOL>('<STR_LIT>', link.metric_value)<EOL>)))<EOL><DEDENT>return OrderedDict((<EOL>('<STR_LIT:type>', '<STR_LIT>'),<EOL>('<STR_LIT>', self.parser.protocol),<EOL>('<STR_LIT:version>', self.parser.version),<EOL>('<STR_LIT>', self.parser.metric),<EOL>('<STR_LIT>', nodes),<EOL>('<STR_LIT>', links)<EOL>))<EOL>
returns a dict that represents a NetJSON NetworkGraph object