URL
https://opencores.org/ocsvn/nocmodel/nocmodel/trunk
Subversion Repositories nocmodel
Compare Revisions
- This comparison shows the changes necessary to convert path
/nocmodel/trunk
- from Rev 1 to Rev 2
- ↔ Reverse comparison
Rev 1 → Rev 2
/nocmodel/noc_base.py
0,0 → 1,888
#!/usr/bin/env python |
# -*- coding: utf-8 -*- |
|
# |
# NoC Base Objects |
# |
# Author: Oscar Diaz |
# Version: 0.1 |
# Date: 03-03-2011 |
|
# |
# This code is free software; you can redistribute it and/or |
# modify it under the terms of the GNU Lesser General Public |
# License as published by the Free Software Foundation; either |
# version 2.1 of the License, or (at your option) any later version. |
# |
# This code is distributed in the hope that it will be useful, |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
# Lesser General Public License for more details. |
# |
# You should have received a copy of the GNU Lesser General Public |
# License along with this library; if not, write to the |
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
# Boston, MA 02111-1307 USA |
# |
|
# |
# Changelog: |
# |
# 03-03-2011 : (OD) initial release |
# |
|
""" |
================ |
NoCmodel Base Objects |
================ |
|
This module declares classes used on a Network-on-chip representation: |
|
* NoC container class |
* Router base class |
* Channel base class |
* IPCore base class |
* Protocol base class |
* Packet class |
""" |
|
import networkx as nx |
|
class noc(nx.Graph): |
""" |
Base class for NoC modeling. |
Based on a Graph object that hold the NoC structure |
|
Arguments |
* kwargs: optional parameters to put as object attributes |
""" |
def __init__(self, **kwargs): |
""" |
NoCmodel constructor |
""" |
nx.Graph.__init__(self, **kwargs) |
|
# objects management functions |
def add_router(self, name="", with_ipcore=False, **kwargs): |
""" |
Create a base router object and add it to NoC model. |
|
Arguments |
* name: optional name for this router. By default has the form of |
"R_<index>" |
* with_ipcore: If True, add an ipcore to the created router. |
* kwargs: optional parameters to put as object attributes |
|
Return: reference to the created router object |
""" |
#nodeidx = self._get_next_nodeidx() |
routernode = router(index=None, name=name, graph_ref=self, **kwargs) |
retval = self.add_router_from_object(routernode) |
if name == "": |
retval.name = "R_%d" % retval.index |
if with_ipcore: |
# kwargs are reserved for router creation, not for ipcore. |
self.add_ipcore(retval) |
return retval |
|
def add_router_from_object(self, router_ref): |
""" |
Add an existing router object to NoC model. |
|
Use this function to add an object based on a derived class of |
base router defined in this module. |
|
Arguments |
* router_ref: reference to the router object |
|
Return: the same reference passed in router_ref |
|
Notes: |
* This function will change router_ref.index and router_ref.graph_ref |
attributes when inserted in the NoC model. |
""" |
if not isinstance(router_ref, router): |
raise ValueError("Argument 'router_ref' is not a router object.") |
|
router_ref.index = self._get_next_nodeidx() |
router_ref.graph_ref = self |
# don't forget that index is used for address |
router_ref.address = router_ref.index |
self.add_node(router_ref.index, router_ref=router_ref) |
return router_ref |
|
def add_channel(self, router1, router2, name="", **kwargs): |
""" |
Create a base channel object to link two objects and add it |
to NoC model. |
|
Arguments: |
* router1: reference to a router, router index or ipcore |
* router2: -idem- |
* name: optional argument for channel name |
* kwargs: optional parameters to put as object attributes |
|
Notes: |
* If router1 or router2 is an ipcore reference, this method creates |
the special channel object and update ipcore references. Additionally, |
if both arguments are ipcores, throw an error exception |
""" |
if isinstance(router1, ipcore) and isinstance(router2, ipcore): |
raise ValueError("Both object references cannot be ipcore objects.") |
|
rhash = [None, None] |
rrefs = [None, None] |
for targetid, routertarget in enumerate((router1, router2)): |
if isinstance(routertarget, router): |
if routertarget.index in self.node: |
rhash[targetid] = routertarget.index |
rrefs[targetid] = self.node[routertarget.index]["router_ref"] |
elif isinstance(routertarget, ipcore): |
# special channel |
rhash[targetid] = None |
rrefs[targetid] = routertarget |
elif isinstance(routertarget, int): |
if routertarget in self.node: |
rhash[targetid] = routertarget |
rrefs[targetid] = self.node[routertarget]["router_ref"] |
|
if rrefs[0] is None: |
raise ValueError("Object not found for argument 'router1'") |
if rrefs[1] is None: |
raise ValueError("Object not found for argument 'router2'") |
|
if None in rhash: |
ipcore_idx = rhash.index(None) |
# ipcore channel |
if name == "": |
# channel default name format |
name = "CH_IP_%s" % rrefs[ipcore_idx].name |
channelnode = channel(index=None, name=name, graph_ref=self, **kwargs) |
else: |
# inter-routers channel |
if name == "": |
# channel default name format |
name = "CH_%s:%s" % (rrefs[0].name, rrefs[1].name) |
channelnode = channel(index=self._get_next_edgeidx(), name=name, graph_ref=self, **kwargs) |
self.add_edge(rhash[0], rhash[1], channel_ref = channelnode) |
channelnode.endpoints = rrefs |
return channelnode |
|
def add_from_channel(self, channel_ref, router1=None, router2=None): |
""" |
Add a channel object to NoC model. |
|
Use this function to add an object based on a derived class of |
base channel defined in this module. |
|
Arguments |
* channel_ref: reference to the channel object |
* router1: optional reference to a router, router index or ipcore |
* router2: -idem- |
|
Return: the same reference passed in channel_ref |
|
Notes: |
* If router1 or router2 are not used as arguments, will assume that |
channel object has defined its attribute "endpoints" with the |
objects to connect. If the objects don't exist in the NoC model, |
throw an error exception. |
|
* If router1 or router2 is an ipcore reference, this method creates |
the special channel object and update ipcore references. Additionally, |
if both arguments are ipcores, throw an error exception. |
|
* This function will change channel_ref.index and channel_ref.graph_ref |
attributes when inserted in the NoC model. Also it may change |
channel_ref.endpoints with router1 and router2 references. |
""" |
if not isinstance(channel_ref, channel): |
raise ValueError("Argument 'channel_ref' is not a channel object.") |
|
if isinstance(router1, ipcore) and isinstance(router2, ipcore): |
raise ValueError("Both object references cannot be ipcore objects.") |
|
rhash = [None, None] |
rrefs = [None, None] |
for targetid, routertarget in enumerate((router1, router2)): |
if isinstance(routertarget, router): |
if routertarget.index in self.node: |
rhash[targetid] = routertarget.index |
rrefs[targetid] = self.node[routertarget.index]["router_ref"] |
elif isinstance(routertarget, ipcore): |
# special channel |
rhash[targetid] = None |
rrefs[targetid] = routertarget |
elif isinstance(routertarget, int): |
if routertarget in self.node: |
rhash[targetid] = routertarget |
rrefs[targetid] = self.node[routertarget]["router_ref"] |
|
if (router1 is None) and (router2 is None): |
# extract from endpoints attribute |
if not hasattr(channel_ref, "endpoints"): |
raise ValueError("Channel object has not attribute 'endpoints'") |
for i in range(2): |
if not isinstance(channel_ref.endpoints[i], [router, ipcore]): |
raise ValueError("Channel object: attribute 'endpoints'[%d] is not a router or an ipcore" % i) |
if isinstance(channel_ref.endpoints[i], router): |
if channel_ref.endpoints[i].index in self.node: |
rhash[i] = channel_ref.endpoints[i].index |
rrefs[i] = channel_ref.endpoints[i] |
if isinstance(channel_ref.endpoints[i], ipcore): |
rhash[i] = None |
rrefs[i] = channel_ref.endpoints[i] |
|
if rrefs[0] is None: |
raise ValueError("Object not found for argument 'router1'") |
if rrefs[1] is None: |
raise ValueError("Object not found for argument 'router2'") |
|
if None in rhash: |
ipcore_idx = rhash.index(None) |
channel_ref.index = None |
# ipcore channel: adjust the references |
rrefs[ipcore_idx].channel_ref = channel_ref |
# the other reference must be a router object |
rrefs[ipcore_idx - 1].ipcore_ref = rrefs[ipcore_idx] |
else: |
# inter-routers channel |
channel_ref.index = self._get_next_edgeidx() |
self.add_edge(rhash[0], rhash[1], channel_ref=channel_ref) |
# update common references |
channel_ref.graph_ref = self |
channel_ref.endpoints = rrefs |
return channel_ref |
|
|
def add_ipcore(self, router_ref, name="", **kwargs): |
""" |
Create an ipcore object and connect it to the router reference argument |
|
Arguments |
* router_ref: reference to an existing router |
* name: optional name for this router. By default has the form of |
"IP_<router_index>" |
* kwargs: optional parameters to put as object attributes |
|
Return: reference to the created ipcore object |
|
Notes: |
* This function automatically adds a special channel object |
(router-to-ipcore) and adjust its relations in all involved objects. |
""" |
if router_ref not in self.router_list(): |
raise ValueError("Argument 'router_ref' must be an existing router.") |
if name == "": |
# channel default name format |
name = "IP_%d" % router_ref.index |
# fix channel name, based on ipcore name |
chname = "CH_%s" % name |
newip = ipcore(name=name, router_ref=router_ref, graph_ref=self, **kwargs) |
channelnode = channel(index=None, name=chname, graph_ref=self, endpoints=[router_ref, newip]) |
# fix references |
newip.channel_ref = channelnode |
router_ref.ipcore_ref = newip |
return newip |
|
def add_from_ipcore(self, ipcore_ref, router_ref, channel_ref=None): |
""" |
Add a ipcore object to NoC model. |
|
Arguments |
* ipcore_ref: reference to ipcore object |
* router_ref: reference to an existing router to connect |
* channel_ref: optional channel object that connect the router and |
the ipcore. If not used, this function will create a new channel object. |
|
Return: the same reference passed in ipcore_ref |
|
Notes: |
* This function automatically adds a special channel object |
(router-to-ipcore) and adjust its relations in all involved objects. |
""" |
if not isinstance(ipcore_ref, ipcore): |
raise ValueError("Argument 'ipcore_ref' is not an ipcore object.") |
if router_ref not in self.router_list(): |
raise ValueError("Argument 'router_ref' must be an existing router.") |
|
if channel_ref != None: |
if not isinstance(channel_ref, channel): |
raise ValueError("Argument 'channel_ref' is not a channel object.") |
else: |
channel_ref.index = None |
channel_ref.graph_ref = self |
channel_ref.endpoints = [router_ref, ipcore_ref] |
else: |
# channel default name format |
chname = "CH_IP_%d" % router_ref.index |
channel_ref = channel(index=None, name=chname, graph_ref=self, endpoints=[router_ref, ipcore_ref]) |
|
# fix references |
ipcore_ref.router_ref = router_ref |
ipcore_ref.channel_ref = channel_ref |
ipcore_ref.graph_ref = self |
router_ref.ipcore_ref = ipcore_ref |
|
return ipcore_ref |
|
def del_router(self, router_ref): |
""" |
Remove router_ref from the NoC model |
|
TODO: not implemented |
""" |
pass |
|
def del_channel(self, channel_ref): |
""" |
Remove channel_ref from the NoC model |
|
TODO: not implemented |
""" |
pass |
|
def del_ipcore(self, ipcore_ref): |
""" |
Remove ipcore_ref from the NoC model |
|
TODO: not implemented |
""" |
pass |
|
# list generation functions |
def router_list(self): |
l = [] |
for i in self.nodes_iter(data=True): |
l.append(i[1]["router_ref"]) |
return l |
|
def ipcore_list(self): |
l = [] |
for i in self.nodes_iter(data=True): |
if i[1]["router_ref"].ipcore_ref != None: |
l.append(i[1]["router_ref"].ipcore_ref) |
return l |
|
def channel_list(self): |
# this function does not list ipcore channels |
l = [] |
for i in self.edges_iter(data=True): |
l.append(i[2]["channel_ref"]) |
return l |
|
def all_list(self): |
l = self.router_list() |
l.extend(self.ipcore_list()) |
l.extend(self.channel_list()) |
return l |
|
# query functions |
def get_router_by_address(self, address): |
for r in self.router_list(): |
if r.address == address: |
return r |
return False |
|
# hidden functions |
def _add_router_from_node(self, node, name="", router_ref=None, **kwargs): |
""" |
Create a router object (or use an existing router reference) based on |
an existing empty node on graph object. |
""" |
if router_ref is None: |
# index comes from node |
if name == "": |
name = "R_%d" % node |
routernode = router(index=node, name=name, graph_ref=self, **kwargs) |
else: |
if not isinstance(router_ref, router): |
raise ValueError("Argument 'router_ref' is not a router object.") |
routernode = router_ref |
routernode.index = node |
routernode.graph_ref = self |
self.node[node]["router_ref"] = routernode |
return routernode |
|
def _add_channel_from_edge(self, edge, name="", channel_ref=None, **kwargs): |
""" |
Create a channel object (or use an existing channel reference) based |
on an existing edge on graph object. |
""" |
# inter-routers channels only |
rrefs = [self.node[edge[0]]["router_ref"], self.node[edge[1]]["router_ref"]] |
chindex = self.edges().index(edge) |
if channel_ref is None: |
if name == "": |
# channel default name format |
name = "CH_%s:%s" % (rrefs[0].name, rrefs[1].name) |
channelnode = channel(index=chindex, name=name, graph_ref=self, **kwargs) |
else: |
if not isinstance(channel_ref, channel): |
raise ValueError("Argument 'channel_ref' is not a channel object.") |
channelnode = channel_ref |
channelnode.index = chindex |
channelnode.graph_ref = self |
channelnode.endpoints = rrefs |
self.get_edge_data(edge[0], edge[1])["channel_ref"] = channelnode |
|
return channelnode |
|
def _get_next_nodeidx(self): |
# get the next node index number |
# don't use intermediate available indexes |
return len(self.nodes()) |
|
def _get_next_edgeidx(self): |
# get the next edge index number |
# don't use intermediate available indexes |
return len(self.edges()) |
|
# ******************************* |
# Generic models for NoC elements |
# ******************************* |
|
class nocobject(): |
""" |
NoC base object |
|
This base class is used to implement common methods for NoC objects. |
Don't use directly. |
""" |
def get_protocol_ref(self): |
""" |
Get protocol object for this instance |
""" |
if hasattr(self, "protocol_ref"): |
if isinstance(self.protocol_ref, protocol): |
return self.protocol_ref |
if isinstance(self.graph_ref.protocol_ref, protocol): |
return self.graph_ref.protocol_ref |
# nothing? |
return None |
|
class ipcore(nocobject): |
""" |
IP core base object |
|
This object represents a IP Core object and its properties. This base class |
is meant to either be inherited or extended by adding other attributes. |
|
Relations with other objects: |
* It should be related to one NoC model object (self.graph_ref) |
* It should have one reference to a router object (self.router_ref), even if |
the ipcore has a direct connection to the NoC. |
* It should have one reference to a channel object (self.channel_ref). This |
channel exclusively link this ipcore and its router. |
|
Attributes: |
* name |
* router_ref: optional reference to its related router. |
* channel_ref: optional reference to its related channel |
* graph_ref: optional reference to its graph model |
""" |
def __init__(self, name, **kwargs): |
# Basic properties |
self.name = name |
# default values |
self.router_ref = None |
self.channel_ref = None |
self.graph_ref = None |
for key in kwargs.keys(): |
setattr(self, key, kwargs[key]) |
|
class router(nocobject): |
""" |
Router base object |
|
This object represents a router object and its properties. This base class |
is meant to either be inherited or extended by adding other attributes. |
|
Relations with other objects: |
* It should be related to one NoC model object (self.graph_ref) |
* It should be one of the node attributes in the graph model |
(node["router_ref"]) |
* It may have one reference to an ipcore object (self.ipcore_ref) |
* It has a port list with relations to other routers through channel objects, |
and only one relation to its ipcore object through one channel. |
(self.ports). Note that this attribute must be updated after changing |
the NoC model. |
|
Attributes: |
* index: index on a noc object. Essential to search for a router object |
* name |
* ipcore_ref: optional reference to its related ipcore |
* graph_ref: optional reference to its graph model |
""" |
def __init__(self, index, name, **kwargs): |
# Basic properties |
self.index = index |
self.name = name |
# default values |
self.ipcore_ref = None |
self.graph_ref = None |
# address can be anything, but let use index by default |
# note that address can be overriden with optional arguments in kwargs |
self.address = index |
for key in kwargs.keys(): |
setattr(self, key, kwargs[key]) |
# ports structure |
self.ports = {} |
# available routes info |
self.routes_info = {} |
|
# update functions: call them when the underlying NoC structure |
# has changed |
def update_ports_info(self): |
""" |
Update the dictionary "ports": information about router neighbors, |
the channels that connect them and its references. |
|
Ports dictionary has the following structure: |
* key: address of the neighbor router that this port connects. |
* value: dictionary with the following keys: |
* "peer" (required): reference to the neighbor router |
* "channel" (required): reference to the channel that connects this |
router and its neighbor router. |
* Optional keys can be added to this dictionary. |
* Also, the special key "local address" holds the port to |
router's ipcore. Its values are: |
* "peer" (required): reference to its ipcore |
* "channel" (required): reference to the channel that connects this |
router and its ipcore. |
* Optional keys can be added to this dictionary with the same |
meaning as other ports. |
""" |
# port definitions |
localhash = self.address |
updated_addr = [self.address] |
for neighborhash in self.graph_ref.neighbors(localhash): |
neighbor = self.graph_ref.node[neighborhash]["router_ref"] |
#check if already defined in ports dictionary |
if neighbor.address not in self.ports: |
self.ports[neighbor.address] = {} |
# update relevant data |
self.ports[neighbor.address]["peer"] = neighbor |
ch_ref = self.graph_ref.edge[localhash][neighborhash]["channel_ref"] |
self.ports[neighbor.address]["channel"] = ch_ref |
updated_addr.append(neighbor.address) |
|
# special port: ipcore |
if self.address not in self.ports: |
self.ports[self.address] = {} |
self.ports[self.address]["peer"] = self.ipcore_ref |
# take channel reference from ipcore. Other channels are related to |
# an edge on the graph model. Channels in an ipcore are special because |
# they don't have a related edge, just link an ipcore and this router |
self.ports[self.address]["channel"] = self.ipcore_ref.channel_ref |
|
# clean 'deleted' ports |
keys = self.ports.iterkeys() |
for deleted in keys: |
if deleted not in updated_addr: |
del self.ports[deleted] |
|
def update_routes_info(self): |
""" |
Update the dictionary "routes_info": it is a table with information |
about how a package, starting from this router, can reach another one. |
|
routes_info dictionary has the following structure: |
* keys : the address of all the routers in NoC |
* values : an ordered list of dictionaries with |
* "next" : address of the next router |
* "paths" : list of possible paths for key destination |
|
""" |
# this function will calculate a new table! |
self.routes_info.clear() |
|
#mynodehash = (self.coord_x, self.coord_y) |
mynodehash = self.index |
|
for destrouter in self.graph_ref.router_list(): |
# discard route to myself |
if destrouter == self: |
continue |
#desthash = (destrouter.coord_x, destrouter.coord_y) |
desthash = destrouter.index |
|
# entry for destrouter |
self.routes_info[destrouter.index] = [] |
|
# first: take all shortest paths (function not available on NetworkX) |
shortest_routes = all_shortest_paths(self.graph_ref, mynodehash, desthash) |
# convert nodehashes to router addresses |
shortest_r_addr = [map(lambda x : self.graph_ref.node[x]["router_ref"].address, i) for i in shortest_routes] |
|
# NOTE about routing tables: need to think about which routes based on |
# shortest paths are better in general with other routers, so the links |
# are well balanced. A possible problem could be that some links will carry |
# more data flow than others. |
# A possible workaround lies in the generation of routing tables at |
# NoC level, taking account of neighbors tables and others parameters. |
|
# extract the next neighbor in each path |
for route in shortest_r_addr: |
# first element is myself, last element is its destination. |
# for this routing table, we only need the next router to |
# send the package. |
newroute = True |
for route_entry in self.routes_info[destrouter.index]: |
if route[1] == route_entry["next"]: |
# another route which next element was taken account |
route_entry["paths"].append(route) |
newroute = False |
if newroute: |
self.routes_info[destrouter.index].append({"next": route[1], "paths": [route]}) |
# last option: send through another node not in the shortest paths |
# NOTE: decide if this is needed or make sense |
|
class channel(nocobject): |
""" |
Channel base object |
|
This object represents a channel object and its properties. This base class |
is meant to either be inherited or extended by adding other attributes. |
|
Relations with other objects: |
* It should be related to one NoC model object (self.graph_ref) |
* It may be one of the edge attributes in the graph model |
(edge["channel_ref"]). In this case, this channel connects two routers |
in the NoC model. |
* It should have two references to NoC objects (self.endpoints). Two options |
exists: two routers references (channel has an edge object) or, one |
router and one ipcore (channel don't have any edge object). |
|
Attributes: |
* name |
* index: optional index on a noc object. Must have an index when it has |
a related edge in the graph model (and allowing it to be able to do |
channel searching). None means it is an ipcore related channel |
* graph_ref optional reference to its graph model |
* endpoints optional two-item list with references to the connected objects |
""" |
def __init__(self, name, index=None, **kwargs): |
# Basic properties |
self.index = index |
self.name = name |
# Default values |
self.graph_ref = None |
self.endpoints = [None, None] |
for key in kwargs.keys(): |
setattr(self, key, kwargs[key]) |
|
def is_ipcore_link(self): |
""" |
Checks if this channel is a special link for an ipcore. |
|
Return: True if the channel is related to an ipcore |
""" |
# Search for ipcore in endpoints. Don't check None on self.index. |
for ref in self.endpoints: |
if isinstance(ref, ipcore): |
return True |
return False |
|
class protocol(nocobject): |
""" |
Protocol base object |
|
This object represents the protocol that the NoC objects use. This |
object has attributes that define the protocol used, mainly it can be |
used to generate, encode, decode or interpret packets on the NoC. |
This base class can be either be inherited or extended by adding |
other attributes. |
|
Relations with other objects: |
* Each object on the NoC (routers, channels and ipcores) may have |
one reference to a protocol object (object.protocol_ref) |
* A NoC model may have a protocol object: in this case, all objects in |
the model will use this protocol (nocmodel.protocol_ref) |
* A protocol object is a generator of packet objects |
|
Attributes: |
* name |
|
Notes: |
* Optional arguments "packet_format" and "packet_order" can be |
added at object construction, but will not check its data consistency. |
At the moment, we recommend using update_packet_field() method to |
fill this data structures. |
""" |
def __init__(self, name="", **kwargs): |
""" |
Constructor |
|
Notes: |
* Optional arguments will be added as object attributes. |
""" |
# NOTE: to avoid python version requirements (2.7), implement ordered |
# dict with an additional list. When we are sure of using |
# Python > 2.7 , change to collections.OrderedDict |
self.name = name |
self.packet_format = {} |
self.packet_order = [] |
self.packet_class = packet |
for key in kwargs.keys(): |
setattr(self, key, kwargs[key]) |
|
def get_protocol_ref(self): |
# override to use myself |
return self |
|
def update_packet_field(self, name, type, bitlen, description=""): |
""" |
Add or update a packet field. |
|
Arguments |
* name |
* type: string that can be "int", "fixed" or "float" |
* bitlen: bit length of this field |
* description: optional description of this field |
|
Notes: |
* Each new field will be added at the end. |
""" |
if (type != "int") and (type != "fixed") and (type != "float"): |
raise ValueError("Argument 'type' must be 'int', 'fixed' or 'float'.") |
|
if name in self.packet_format: |
# update field |
previdx = self.packet_order.index(name) - 1 |
if previdx < 0: |
# first field |
lastbitpos = 0 |
else: |
lastbitpos = self.packet_format[self.packet_order[previdx]][lsb] |
nextbitpos = lastbitpos + bitlen |
self.packet_format[name]["type"] = type |
self.packet_format[name]["position"] = previdx + 1 |
# check if the packet format needs to adjust the bit positions |
if self.packet_format[name]["bitlen"] != bitlen: |
self.packet_format[name]["bitlen"] = bitlen |
self.packet_format[name]["lsb"] = nextbitpos |
self.packet_format[name]["msb"] = lastbitpos |
# iterate through the rest of the fields adjusting lsb and msb |
for idx in range(previdx+2, len(self.packet_order)): |
curname = self.packet_order[idx] |
curbitlen = self.packet_format[curname]["bitlen"] |
self.packet_format[curname]["lsb"] = nextbitpos + curbitlen |
self.packet_format[curname]["msb"] = nextbitpos |
nextbitpos += curbitlen |
else: |
# append |
if len(self.packet_format) == 0: |
lastbitpos = 0 |
else: |
lastbitpos = self.packet_format[self.packet_order[-1]]["lsb"] |
nextbitpos = lastbitpos + bitlen |
fieldpos = len(self.packet_order) |
self.packet_format[name] = {"type": type, "position": fieldpos, "bitlen": bitlen, "lsb": nextbitpos, "msb": lastbitpos} |
self.packet_order.append(name) |
|
def newpacket(self, zerodefault=True, *args, **kwargs): |
""" |
Return a new packet with all required fields. |
|
Arguments: |
* zerodefault: If True, all missing fields will be zeroed by default. |
If False, a missing value in arguments will throw an exception. |
* args: Nameless arguments will add field values based on packet field |
order. |
* kwargs: Key-based arguments will add specified field values based in |
its keys |
|
Notes: |
* kwargs takes precedence over args: i.e. named arguments can overwrite |
nameless arguments. |
""" |
retpacket = self.packet_class(protocol_ref=self) |
fieldlist = self.packet_order[:] |
# first named arguments |
for fkey, fvalue in kwargs.iteritems(): |
if fkey in fieldlist: |
retpacket[fkey] = fvalue |
fieldlist.remove(fkey) |
# then nameless |
for fidx, fvalue in enumerate(args): |
fkey = self.packet_order[fidx] |
if fkey in fieldlist: |
retpacket[fkey] = fvalue |
fieldlist.remove(fkey) |
# check for empty fields |
if len(fieldlist) > 0: |
if zerodefault: |
for fkey in fieldlist: |
retpacket[fkey] = 0 |
else: |
raise ValueError("Missing fields in argument list: %s" % repr(fieldlist)) |
return retpacket |
def register_packet_generator(self, packet_class): |
""" |
Register a special packet generator class. |
|
Must be a derived class of packet |
""" |
if not issubclass(packet_class, packet): |
raise TypeError("Argument 'packet_class' must derive from 'packet' class.") |
self.packet_class = packet_class |
|
class packet(dict): |
""" |
Packet base object |
|
This object represents a packet data, related to a protocol object. It |
behaves exactly like a Python dictionary, but adds methods to simplify |
packet transformations. |
|
Relations with other objects: |
* It should be generated by a protocol object (and will have a reference |
in self.protocol_ref) |
|
Attributes: |
* protocol_ref: protocol object that created this object. |
""" |
|
# the constructor |
def __init__(self, *args, **kwargs): |
# look for a protocol_ref key |
self.protocol_ref = kwargs.pop("protocol_ref", None) |
dict.__init__(self, *args, **kwargs) |
|
# ******************************* |
# Additional functions |
# ******************************* |
|
# Missing function in NetworkX |
def all_shortest_paths(G,a,b): |
""" |
Return a list of all shortest paths in graph G between nodes a and b |
This is a function not available in NetworkX (checked at 22-02-2011) |
|
Taken from: |
http://groups.google.com/group/networkx-discuss/browse_thread/thread/55465e6bb9bae12e |
""" |
ret = [] |
pred = nx.predecessor(G,b) |
if not pred.has_key(a): # b is not reachable from a |
return [] |
pth = [[a,0]] |
pthlength = 1 # instead of array shortening and appending, which are relatively |
ind = 0 # slow operations, we will just overwrite array elements at position ind |
while ind >= 0: |
n,i = pth[ind] |
if n == b: |
ret.append(map(lambda x:x[0],pth[:ind+1])) |
if len(pred[n]) > i: |
ind += 1 |
if ind == pthlength: |
pth.append([pred[n][i],0]) |
pthlength += 1 |
else: |
pth[ind] = [pred[n][i],0] |
else: |
ind -= 1 |
if ind >= 0: |
pth[ind][1] += 1 |
return ret |
/nocmodel/noc_guilib.py
0,0 → 1,109
#!/usr/bin/env python |
# -*- coding: utf-8 -*- |
|
# |
# Support for graphical representation of NoC objects |
# |
# Author: Oscar Diaz |
# Version: 0.1 |
# Date: 03-03-2011 |
|
# |
# This code is free software; you can redistribute it and/or |
# modify it under the terms of the GNU Lesser General Public |
# License as published by the Free Software Foundation; either |
# version 2.1 of the License, or (at your option) any later version. |
# |
# This code is distributed in the hope that it will be useful, |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
# Lesser General Public License for more details. |
# |
# You should have received a copy of the GNU Lesser General Public |
# License along with this library; if not, write to the |
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
# Boston, MA 02111-1307 USA |
# |
|
# |
# Changelog: |
# |
# 03-03-2011 : (OD) initial release |
# |
|
""" |
================ |
NoCmodel Graphic utilities |
================ |
|
This module declares functions to draw graphical representations of |
NoCmodel objects. |
|
""" |
|
import matplotlib.pyplot as plt |
import networkx as nx |
|
from noc_base import * |
|
def draw_noc(noc, rectangular=True, nodepos=None): |
""" |
Draw a representation of a NoC |
|
Arguments: |
* noc: Model to draw |
* rectangular: If True assumes rectangular layout, with routers |
having coord_x and coord_y attributes. If false, expect router's |
positions in nodepos argument |
* nodepos: Optional dictionary where keys are router's indexes and values |
are tuples with x and y positions. |
""" |
# node positions |
if rectangular: |
if nodepos == None: |
nodepos = {} |
for i in noc.router_list(): |
nodepos[i.index] = (i.coord_x, i.coord_y) |
else: |
if nodepos == None: |
raise ValueError("For non-rectangular layouts this function needs argument 'nodepos'") |
|
# some parameters |
ip_relpos = (-0.3, 0.3) # relative to router |
# node labels |
nodelabels = {} |
for i in nodepos.iterkeys(): |
nodelabels[i] = noc.node[i]["router_ref"].name |
|
# channel positions |
chpos = {} |
for i in noc.channel_list(): |
ep = i.endpoints |
ep_1x = nodepos[ep[0].index][0] |
ep_1y = nodepos[ep[0].index][1] |
ep_2x = nodepos[ep[1].index][0] |
ep_2y = nodepos[ep[1].index][1] |
thepos = (ep_2x + ((ep_1x - ep_2x)/2.0), ep_2y + ((ep_1y - ep_2y)/2.0)) |
chpos[i.index] = {"pos": thepos, "text": i.name} |
|
# start drawing |
nx.draw_networkx_nodes(noc, pos=nodepos, node_size=1000, node_color="blue", alpha=0.5) |
nx.draw_networkx_edges(noc, pos=nodepos, edge_color="black", alpha=1.0, width=3.0) |
nx.draw_networkx_labels(noc, pos=nodepos, labels=nodelabels, font_color="red") |
|
ax=plt.gca() |
# channel labels |
for i in chpos.itervalues(): |
ax.text(i["pos"][0], i["pos"][1], i["text"], horizontalalignment="center", verticalalignment="top", bbox=dict(facecolor='red', alpha=0.2)) |
|
# ipcore with channels and labels |
for i in noc.ipcore_list(): |
thepos = nodepos[i.router_ref.index] |
# channel |
ax.arrow(thepos[0], thepos[1], ip_relpos[0], ip_relpos[1]) |
# ip channel label |
ax.text(thepos[0]+(ip_relpos[0]/2), thepos[1]+(ip_relpos[1]/2), i.channel_ref.name, horizontalalignment="center", bbox=dict(facecolor='red', alpha=0.2)) |
# box with ipcore labels |
ax.text(thepos[0]+ip_relpos[0], thepos[1]+ip_relpos[1], i.name, horizontalalignment="center", bbox=dict(facecolor='green', alpha=0.2)) |
|
plt.show() |
/nocmodel/noc_tlm_utils.py
0,0 → 1,61
#!/usr/bin/env python |
# -*- coding: utf-8 -*- |
|
# |
# NoC TLM simulation support - Utilities |
# This module declares additional helper functions |
# |
# Author: Oscar Diaz |
# Version: 0.1 |
# Date: 03-03-2011 |
|
# |
# This code is free software; you can redistribute it and/or |
# modify it under the terms of the GNU Lesser General Public |
# License as published by the Free Software Foundation; either |
# version 2.1 of the License, or (at your option) any later version. |
# |
# This code is distributed in the hope that it will be useful, |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
# Lesser General Public License for more details. |
# |
# You should have received a copy of the GNU Lesser General Public |
# License along with this library; if not, write to the |
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
# Boston, MA 02111-1307 USA |
# |
|
# |
# Changelog: |
# |
# 03-03-2011 : (OD) initial release |
# |
|
from noc_tlm_base import * |
from nocmodel.basicmodels import * |
|
# helper functions |
def add_tlm_basic_support(instance, **kwargs): |
""" |
This function will add for every object in noc_instance a noc_tlm object |
""" |
if isinstance(instance, noc): |
# add simulation object |
instance.tlmsim = noc_tlm_simulation(instance, **kwargs) |
# and add tlm objects recursively |
for obj in instance.all_list(): |
altkwargs = kwargs |
altkwargs.pop("log_file", None) |
altkwargs.pop("log_level", None) |
add_tlm_basic_support(obj, **kwargs) |
elif isinstance(instance, ipcore): |
instance.tlm = basic_ipcore_tlm(instance, **kwargs) |
# don't forget internal channel |
instance.channel_ref.tlm = basic_channel_tlm(instance.channel_ref, **kwargs) |
elif isinstance(instance, router): |
instance.tlm = basic_router_tlm(instance, **kwargs) |
elif isinstance(instance, channel): |
instance.tlm = basic_channel_tlm(instance, **kwargs) |
else: |
print "Unsupported object: type %s" % type(instance) |
/nocmodel/basicmodels/basic_channel.py
0,0 → 1,184
#!/usr/bin/env python |
# -*- coding: utf-8 -*- |
|
# |
# Basic Channel model |
# * TLM model |
# |
# Author: Oscar Diaz |
# Version: 0.1 |
# Date: 03-03-2011 |
|
# |
# This code is free software; you can redistribute it and/or |
# modify it under the terms of the GNU Lesser General Public |
# License as published by the Free Software Foundation; either |
# version 2.1 of the License, or (at your option) any later version. |
# |
# This code is distributed in the hope that it will be useful, |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
# Lesser General Public License for more details. |
# |
# You should have received a copy of the GNU Lesser General Public |
# License along with this library; if not, write to the |
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
# Boston, MA 02111-1307 USA |
# |
|
# |
# Changelog: |
# |
# 03-03-2011 : (OD) initial release |
# |
|
""" |
Basic channel TLM model |
""" |
|
from nocmodel.noc_tlm_base import * |
|
# --------------------------- |
# Channel TLM model |
|
class basic_channel_tlm(noc_tlm_base): |
""" |
TLM model of a NoC channel. It models a simple FIFO channel with |
adjustable delay. This channel will move any kind of data as a whole, but |
ideally will move packet objects. |
|
Attributes: |
* Channel delay: delay in clock ticks. |
|
Notes: |
*This model is completely behavioral |
""" |
def __init__(self, channel_ref, channel_delay=1): |
noc_tlm_base.__init__(self) |
if isinstance(channel_ref, channel): |
self.channel_ref = channel_ref |
self.graph_ref = channel_ref.graph_ref |
self.logname = "Channel '%s'" % channel_ref.name |
else: |
raise TypeError("This class needs a channel object as constructor argument.") |
|
self.debug("constructor") |
|
# channel parameters |
self.channel_delay = channel_delay |
|
# list of router endpoints |
self.endpoints = self.channel_ref.endpoints |
|
# generators |
self.generators = [] |
|
self.has_delay = False |
if self.channel_delay > 0: |
self.has_delay = True |
self.delay_fifo = [] |
self.delay_fifo_max = 10 # error-catch parameter, avoid fifo excessive growing |
self.delay_event = myhdl.Signal(False) |
# implement delay generator |
@myhdl.instance |
def delay_generator(): |
while True: |
while len(self.delay_fifo) > 0: |
# extract packet and recorded time |
timed_packet = self.delay_fifo.pop(0) |
# calculate the exact delay value |
next_delay = self.channel_delay - (myhdl.now() - timed_packet[0]) |
if next_delay <= 0: |
self.debug("delay_generator CATCH next_delay is '%d'" % next_delay) |
else: |
yield myhdl.delay(next_delay) |
self.debug("delay_generator sending delayed packet (by %d), timed_packet format %s" % (next_delay, repr(timed_packet)) ) |
# use send() |
retval = self.send(*timed_packet[1:]) |
# what to do in error case? report and continue |
if retval != noc_tlm_errcodes.no_error: |
self.error("delay_generator send returns code '%d'?" % retval ) |
self.delay_event.next = False |
yield self.delay_event |
self.generators.append(delay_generator) |
|
self.debugstate() |
|
# channel only relays transactions |
# Transaction - related methods |
def send(self, src, dest, packet, addattrs=None): |
""" |
This method will be called by recv (no delay) or by delay_generator |
src always is self |
""" |
# dest MUST be one of the channel endpoints |
self.debug("-> send( %s , %s , %s , %s )" % (repr(src), repr(dest), repr(packet), repr(addattrs))) |
if isinstance(dest, int): |
# assume router direction |
thedest = self.graph_ref.get_router_by_address(dest) |
if thedest == False: |
self.error("-> send: dest %s not found" % repr(dest) ) |
return noc_tlm_errcodes.tlm_badcall_send |
elif isinstance(dest, (router, ipcore)): |
thedest = dest |
else: |
self.error("-> send: what is dest '%s'?" % repr(dest) ) |
return noc_tlm_errcodes.tlm_badcall_send |
|
# check dest as one of the channel endpoints |
if thedest not in self.endpoints: |
self.error("-> send: object %s is NOT one of the channel endpoints [%s,%s]" % (repr(thedest), repr(self.endpoints[0]), repr(self.endpoints[1])) ) |
return noc_tlm_errcodes.tlm_badcall_send |
|
# call recv on the dest object |
retval = thedest.tlm.recv(self.channel_ref, dest, packet, addattrs) |
|
# Something to do with the retval? Only report it. |
self.debug("-> send returns code '%s'" % repr(retval)) |
return retval |
|
def recv(self, src, dest, packet, addattrs=None): |
""" |
receive a packet from an object. src is the object source and |
it MUST be one of the objects in channel endpoints |
""" |
|
self.debug("-> recv( %s , %s , %s , %s )" % (repr(src), repr(dest), repr(packet), repr(addattrs))) |
# src can be an address or a noc object. |
if isinstance(src, int): |
# assume router direction |
thesrc = self.graph_ref.get_router_by_address(src) |
if thesrc == False: |
self.error("-> recv: src %s not found" % repr(src) ) |
return noc_tlm_errcodes.tlm_badcall_recv |
elif isinstance(src, (router, ipcore)): |
thesrc = src |
else: |
self.error("-> recv: what is src '%s'?" % repr(src) ) |
return noc_tlm_errcodes.tlm_badcall_recv |
|
# check src as one of the channel endpoints |
if thesrc not in self.endpoints: |
self.error("-> recv: object %s is NOT one of the channel endpoints [%s,%s]" % (repr(thesrc), repr(self.endpoints[0]), repr(self.endpoints[1])) ) |
return noc_tlm_errcodes.tlm_badcall_recv |
|
# calculate the other endpoint |
end_index = self.endpoints.index(thesrc) - 1 |
|
if self.has_delay: |
# put in delay fifo: store time and call attributes |
self.delay_fifo.append([myhdl.now(), self.channel_ref, self.endpoints[end_index], packet, addattrs]) |
self.debug("-> recv put in delay_fifo (delay %d)" % self.channel_delay) |
# catch growing fifo |
if len(self.delay_fifo) > self.delay_fifo_max: |
self.warning("-> recv: delay_fifo is getting bigger! current size is %d" % len(self.delay_fifo) ) |
# trigger event |
self.delay_event.next = True |
retval = noc_tlm_errcodes.no_error |
else: |
# use send() call directly |
router_dest = self.endpoints[end_index] |
retval = self.send(self.channel_ref, router_dest, packet, addattrs) |
|
self.debug("-> recv returns code '%d'", retval) |
return retval |
/nocmodel/basicmodels/__init__.py
0,0 → 1,53
#!/usr/bin/env python |
# -*- coding: utf-8 -*- |
|
# |
# NoCmodel basic models for testing |
# |
# Author: Oscar Diaz |
# Version: 0.1 |
# Date: 03-03-2011 |
|
# |
# This code is free software; you can redistribute it and/or |
# modify it under the terms of the GNU Lesser General Public |
# License as published by the Free Software Foundation; either |
# version 2.1 of the License, or (at your option) any later version. |
# |
# This code is distributed in the hope that it will be useful, |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
# Lesser General Public License for more details. |
# |
# You should have received a copy of the GNU Lesser General Public |
# License along with this library; if not, write to the |
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
# Boston, MA 02111-1307 USA |
# |
|
# |
# Changelog: |
# |
# 03-03-2011 : (OD) initial release |
# |
|
""" |
================ |
NoCmodel basic models for testing |
================ |
|
This package includes: |
|
* Module basic_channel |
* Module basic_ipcore |
* Module basic_protocol |
* Module basic_router |
""" |
|
# provided modules |
from basic_channel import * |
from basic_ipcore import * |
from basic_protocol import * |
from basic_router import * |
|
__version__ = "0.1" |
/nocmodel/basicmodels/basic_router.py
0,0 → 1,264
#!/usr/bin/env python |
# -*- coding: utf-8 -*- |
|
# |
# Basic Router model |
# * TLM model |
# |
# Author: Oscar Diaz |
# Version: 0.1 |
# Date: 03-03-2011 |
|
# |
# This code is free software; you can redistribute it and/or |
# modify it under the terms of the GNU Lesser General Public |
# License as published by the Free Software Foundation; either |
# version 2.1 of the License, or (at your option) any later version. |
# |
# This code is distributed in the hope that it will be useful, |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
# Lesser General Public License for more details. |
# |
# You should have received a copy of the GNU Lesser General Public |
# License along with this library; if not, write to the |
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
# Boston, MA 02111-1307 USA |
# |
|
# |
# Changelog: |
# |
# 03-03-2011 : (OD) initial release |
# |
|
""" |
Basic router TLM model |
""" |
|
from nocmodel.noc_tlm_base import * |
|
# --------------------------- |
# Router TLM model |
|
class basic_router_tlm(noc_tlm_base): |
""" |
TLM model of a NoC router. This router uses store-and-forward technique, |
using the routing information from the router object. This model just |
forward the packet, and if the packet is in its router destination, send it |
to its ipcore. Each package that the ipcore generates is delivered |
automátically. |
|
Attributes: |
* router_ref : base reference |
* fifo_len: max number of packets to hold in each port |
|
Notes: |
* This model is completely behavioral. |
* See code comments to better understanding. |
""" |
def __init__(self, router_ref, fifo_len=4): |
noc_tlm_base.__init__(self) |
if isinstance(router_ref, router): |
self.router_ref = router_ref |
self.graph_ref = router_ref.graph_ref |
self.logname = "Router '%s'" % router_ref.name |
if router_ref.name == "": |
self.logname = "Router addr '%s'" % router_ref.address |
else: |
raise TypeError("This class needs a router object as constructor argument.") |
|
self.debug("constructor") |
|
# generic parameters |
self.fifo_len = fifo_len |
|
# delay parameters |
self.delay_route = 5 # delay for each routing decisition |
self.delay_outfromfifo = 2 # delay for extract packet from fifo to output port |
self.delay_ipcorebus = 1 # delay for ipcore local bus operations |
|
# router parameters (Assume rectangular coords) |
self.myaddress = router_ref.address |
self.mynodecoord = (router_ref.coord_x, router_ref.coord_y) |
|
# port additions: use a copy of the ports list, and add |
# fifo storage and signal events |
router_ref.update_ports_info() |
self.ports_info = router_ref.ports.copy() |
for p in self.ports_info.itervalues(): |
p["fifo_in"] = [] |
p["fifo_out"] = [] |
p["fifo_in_event"] = myhdl.Signal(False) |
p["fifo_out_event"] = myhdl.Signal(False) |
|
# extract a list of all fifo event signals |
self.list_fifo_in_events = [i["fifo_in_event"] for i in self.ports_info.itervalues()] |
self.list_fifo_out_events = [i["fifo_out_event"] for i in self.ports_info.itervalues()] |
|
# the routing table is generated from the routes_info dict |
# key: its destination address |
# values: a list of ports where the package should send it. First element |
# is the default option, next elements are alternate routes |
router_ref.update_routes_info() |
self.detailed_routingtable = self.router_ref.routes_info.copy() |
self.routingtable = {} |
for dest, data in self.detailed_routingtable.iteritems(): |
self.routingtable[dest] = [x["next"] for x in data] |
# add route to myself |
self.routingtable[self.myaddress] = [self.myaddress] |
|
# log interesting info |
self.info(" router params: fifo_len=%d" % self.fifo_len) |
self.info(" router info: addr=%d coord=%s" % (self.myaddress, repr(self.mynodecoord))) |
self.info(" router ports: %s" % repr(self.ports_info)) |
self.info(" router routing table: %s" % repr(self.routingtable)) |
|
# myhdl generators (concurrent processes) |
self.generators = [] |
|
# fifo out process |
@myhdl.instance |
def flush_fifo_out(): |
while True: |
for port, data in self.ports_info.iteritems(): |
if len(data["fifo_out"]) > 0: |
if not data["fifo_out_event"].val: |
self.debug("flush_fifo_out CATCH fifo not empty and NO trigger! fifo has %s" % repr(data["fifo_out"])) |
self.info("flush_fifo_out event in port %d" % port) |
packet = data["fifo_out"].pop(0) |
self.debug("flush_fifo_out port %d packet is %s (delay %d)" % (port, repr(packet), self.delay_outfromfifo)) |
# DELAY model: time to move from fifo to external port in destination object |
yield myhdl.delay(self.delay_outfromfifo) |
# try to send it |
retval = self.send(self.router_ref, data["channel"], packet) |
if retval == noc_tlm_errcodes.no_error: |
# clean trigger |
data["fifo_out_event"].next = False |
#continue |
else: |
self.error("flush_fifo_out FAILED in port %d (code %d)" % (port, retval)) |
# error management: |
#TODO: temporally put back to fifo |
self.info("flush_fifo_out packet went back to fifo.") |
data["fifo_out"].append(packet) |
yield self.list_fifo_out_events |
self.debug("flush_fifo_out event hit. list %s" % repr(self.list_fifo_out_events)) |
|
# routing loop |
@myhdl.instance |
def routing_loop(): |
while True: |
# routing update: check all fifos |
for port, data in self.ports_info.iteritems(): |
while len(data["fifo_in"]) > 0: |
if not data["fifo_in_event"].val: |
self.debug("routing_loop CATCH fifo not empty and NO trigger! fifo has %s" % repr(data["fifo_in"])) |
self.info("routing_loop fifo_in event in port %d" % port) |
# data in fifo |
packet = data["fifo_in"].pop(0) |
data["fifo_in_event"].next = False |
self.debug("routing_loop port %d packet %s to ipcore (delay %d)" % (port, repr(packet), self.delay_route)) |
# destination needed. extract from routing table |
destaddr = packet["dst"] |
self.debug("routing_loop port %d routingtable %s (dest %d)" % (port, repr(self.routingtable), destaddr)) |
nextaddr = self.routingtable[destaddr][0] |
self.debug("routing_loop port %d to port %s (dest %d)" % (port, nextaddr, destaddr)) |
# DELAY model: time spent to make a route decisition |
yield myhdl.delay(self.delay_route) |
self.ports_info[nextaddr]["fifo_out"].append(packet) |
# fifo trigger |
if self.ports_info[nextaddr]["fifo_out_event"]: |
self.debug("routing_loop CATCH possible miss event because port %d fifo_out_event=True", self.myaddress) |
self.ports_info[nextaddr]["fifo_out_event"].next = True |
|
yield self.list_fifo_in_events |
self.debug("routing_loop event hit. list %s" % repr(self.list_fifo_in_events)) |
|
# list of all generators |
self.generators.extend([flush_fifo_out, routing_loop]) |
self.debugstate() |
|
# Transaction - related methods |
def send(self, src, dest, packet, addattrs=None): |
""" |
This method will be called on a fifo available data event |
|
Notes: |
* Ignore src object. |
* dest should be a channel object, but also can be a router address or |
a router object. |
""" |
self.debug("-> send( %s , %s , %s , %s )" % (repr(src), repr(dest), repr(packet), repr(addattrs))) |
if isinstance(dest, int): |
# it means dest is a router address |
therouter = self.graph_ref.get_router_by_address(dest) |
if therouter == False: |
self.error("-> send: dest %s not found" % repr(dest) ) |
return noc_tlm_errcodes.tlm_badcall_send |
# extract channel ref from ports_info |
thedest = self.ports_info[therouter.address]["channel"] |
elif isinstance(dest, router): |
# extract channel ref from ports_info |
thedest = self.ports_info[dest.address]["channel"] |
elif isinstance(dest, channel): |
# use it directly |
thedest = dest |
else: |
self.error("-> send: what is dest '%s'?" % repr(dest) ) |
return noc_tlm_errcodes.tlm_badcall_send |
|
# call recv on the dest channel object |
retval = thedest.tlm.recv(self.router_ref, thedest, packet, addattrs) |
|
# TODO: something to do with the retval? |
self.debug("-> send returns code '%s'" % repr(retval)) |
return retval |
|
def recv(self, src, dest, packet, addattrs=None): |
""" |
This method will be called by channel objects connected to this router. |
|
Notes: |
* The recv method only affect the receiver FIFO sets |
* Ignore dest object. |
""" |
|
self.debug("-> recv( %s , %s , %s , %s )" % (repr(src), repr(dest), repr(packet), repr(addattrs))) |
# src can be an address or a noc object. |
# convert to addresses |
if isinstance(src, int): |
thesrc = src |
elif isinstance(src, router): |
thesrc = src.address |
elif isinstance(src, channel): |
# get address from the other end. Use the endpoints to calculate |
# source router |
src_index = src.endpoints.index(self.router_ref) - 1 |
theend = src.endpoints[src_index] |
if isinstance(theend, router): |
thesrc = theend.address |
elif isinstance(theend, ipcore): |
thesrc = theend.router_ref.address |
else: |
self.error("-> recv: what is endpoint '%s' in channel '%s'?" % (repr(theend), repr(src)) ) |
return noc_tlm_errcodes.tlm_badcall_recv |
else: |
self.error("-> recv: what is src '%s'?" % repr(src) ) |
return noc_tlm_errcodes.tlm_badcall_recv |
|
# thesrc becomes the port number |
# check if there is enough space on the FIFO |
if len(self.ports_info[thesrc]["fifo_in"]) == self.fifo_len: |
# full FIFO |
self.error("-> recv: full fifo. Try later.") |
return noc_tlm_errcodes.full_fifo |
# get into fifo |
self.ports_info[thesrc]["fifo_in"].append(packet) |
# trigger a new routing event |
if self.ports_info[thesrc]["fifo_in_event"].val: |
self.debug("-> recv: CATCH possible miss event because in port %d fifo_in_event=True", thesrc) |
self.ports_info[thesrc]["fifo_in_event"].next = True |
|
self.debug("-> recv returns 'noc_tlm_errcodes.no_error'") |
return noc_tlm_errcodes.no_error |
/nocmodel/basicmodels/basic_ipcore.py
0,0 → 1,154
#!/usr/bin/env python |
# -*- coding: utf-8 -*- |
|
# |
# Basic IPcore model |
# * TLM model |
# |
# Author: Oscar Diaz |
# Version: 0.1 |
# Date: 03-03-2011 |
|
# |
# This code is free software; you can redistribute it and/or |
# modify it under the terms of the GNU Lesser General Public |
# License as published by the Free Software Foundation; either |
# version 2.1 of the License, or (at your option) any later version. |
# |
# This code is distributed in the hope that it will be useful, |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
# Lesser General Public License for more details. |
# |
# You should have received a copy of the GNU Lesser General Public |
# License along with this library; if not, write to the |
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
# Boston, MA 02111-1307 USA |
# |
|
# |
# Changelog: |
# |
# 03-03-2011 : (OD) initial release |
# |
|
""" |
Basic ipcore TLM model |
""" |
|
from nocmodel.noc_tlm_base import * |
|
# --------------------------- |
# Basic IPCore TLM model |
|
class basic_ipcore_tlm(noc_tlm_base): |
""" |
TLM model of a NoC ipcore. Its based on sending and receiving packets |
to a custom-based MyHDL generators. This class does not define any |
functionality. |
|
Attributes: |
* ipcore_ref: reference to ipcore base object |
|
Notes: |
* This model is completely behavioral. |
* See code comments to better understanding. |
""" |
def __init__(self, ipcore_ref): |
noc_tlm_base.__init__(self) |
if isinstance(ipcore_ref, ipcore): |
self.ipcore_ref = ipcore_ref |
self.graph_ref = ipcore_ref.graph_ref |
self.logname = "IPCore '%s'" % ipcore_ref.name |
if ipcore_ref.name == "": |
self.logname = "IPCore '%s'" % ipcore_ref.router_ref.name |
else: |
raise TypeError("This class needs a ipcore object as constructor argument.") |
|
self.debug("constructor") |
# generic parameters |
|
# one-port support: get a reference to the related channel |
self.localch = self.ipcore_ref.channel_ref |
|
# get protocol reference |
self.protocol_ref = self.ipcore_ref.get_protocol_ref() |
|
# bidirectional port: the sender part will write data to the signal |
# outgoing_packet. This class provides a generator thar call send() |
# method when there is new data. |
# for receiving data, recv() method will write |
# to the signal incoming_packet, and the ipcore must provide a generator |
# sensible to that signal. Use the method register_generator() |
self.incoming_packet = myhdl.Signal(packet()) |
self.outgoing_packet = myhdl.Signal(packet()) |
|
@myhdl.instance |
def outgoing_process(): |
while True: |
yield self.outgoing_packet |
retval = self.send(self.ipcore_ref, self.localch, self.outgoing_packet.val) |
|
self.generators = [outgoing_process] |
self.debugstate() |
|
def register_generator(self, genfunction, **kwargs): |
""" |
Register a new generator for this ipcore. |
|
Arguments: |
* genfunction: function that returns a MyHDL generator |
* kwargs: optional keyed arguments to pass to genfunction call |
|
Notes: |
* This method requires that genfunction has the following prototype: |
* my_function(din, dout, tlm_ref, <other_arguments>) |
* din is a MyHDL Signal of type packet, and is the input signal |
to the ipcore. Use this signal to react to input events and |
receive input packets. |
* dout is a MyHDL Signal of type packet, and is the output |
signal to the ipcore. Use this signal to send out packets to |
local channel (and then insert into the NoC). |
* tlm_ref is a reference to this object. Normal use is to access |
logging methods (e.g. tlm_ref.info("message") ). |
* <other_arguments> may be defined, this method use kwargs |
argument to pass them. |
""" |
makegen = genfunction(din=self.incoming_packet, dout=self.outgoing_packet, tlm_ref=self, **kwargs) |
self.debug("register_generator( %s ) generator is %s args %s" % (repr(genfunction), repr(makegen), repr(kwargs))) |
self.generators.append(makegen) |
|
# Transaction - related methods |
def send(self, src, dest, packet, addattrs=None): |
""" |
Assumptions: |
* Safely ignore src and dest arguments, because this method |
is called only by this object generators, therefore it always send |
packets to the ipcore related channel. |
* In theory src should be self.ipcore_ref, and dest should be |
self.localch . This may be checked for errors. |
""" |
self.debug("-> send( %s , %s , %s , %s )" % (repr(src), repr(dest), repr(packet), repr(addattrs))) |
|
# call recv on the local channel object |
retval = self.localch.tlm.recv(self.ipcore_ref, self.localch, packet, addattrs) |
|
# something to do with the retval? Only report it. |
self.debug("-> send returns code '%s'" % repr(retval)) |
return retval |
|
def recv(self, src, dest, packet, addattrs=None): |
""" |
Assumptions: |
* Safely ignore src and dest arguments, because this method |
is called only by local channel object. |
* In theory src should be self.localch, and dest should be |
self.ipcore_ref . This may be checked for errors. |
""" |
self.debug("-> recv( %s , %s , %s , %s )" % (repr(src), repr(dest), repr(packet), repr(addattrs))) |
|
# update signal |
self.incoming_packet.next = packet |
|
self.debug("-> recv returns 'noc_tlm_errcodes.no_error'") |
return noc_tlm_errcodes.no_error |
/nocmodel/basicmodels/basic_protocol.py
0,0 → 1,54
#!/usr/bin/env python |
# -*- coding: utf-8 -*- |
|
# |
# Basic Protocol model |
# |
# Author: Oscar Diaz |
# Version: 0.1 |
# Date: 03-03-2011 |
|
# |
# This code is free software; you can redistribute it and/or |
# modify it under the terms of the GNU Lesser General Public |
# License as published by the Free Software Foundation; either |
# version 2.1 of the License, or (at your option) any later version. |
# |
# This code is distributed in the hope that it will be useful, |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
# Lesser General Public License for more details. |
# |
# You should have received a copy of the GNU Lesser General Public |
# License along with this library; if not, write to the |
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
# Boston, MA 02111-1307 USA |
# |
|
# |
# Changelog: |
# |
# 03-03-2011 : (OD) initial release |
# |
|
""" |
Basic protocol helper |
""" |
|
from nocmodel.noc_base import * |
|
class basic_protocol(protocol): |
""" |
Basic protocol class |
|
This class simplify protocol object creation. It defines a simple packet |
with the following fields: |
|
|0 7|8 15|16 31| |
| src | dst | data | |
""" |
def __init__(self): |
protocol.__init__(self, name="Basic protocol") |
self.update_packet_field("src", "int", 8, "Source address") |
self.update_packet_field("dst", "int", 8, "Destination address") |
self.update_packet_field("data", "int", 16, "Data payload") |
/nocmodel/__init__.py
0,0 → 1,57
#!/usr/bin/env python |
# -*- coding: utf-8 -*- |
|
# |
# NoCmodel package |
# |
# Author: Oscar Diaz |
# Version: 0.1 |
# Date: 03-03-2011 |
|
# |
# This code is free software; you can redistribute it and/or |
# modify it under the terms of the GNU Lesser General Public |
# License as published by the Free Software Foundation; either |
# version 2.1 of the License, or (at your option) any later version. |
# |
# This code is distributed in the hope that it will be useful, |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
# Lesser General Public License for more details. |
# |
# You should have received a copy of the GNU Lesser General Public |
# License along with this library; if not, write to the |
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
# Boston, MA 02111-1307 USA |
# |
|
# |
# Changelog: |
# |
# 03-03-2011 : (OD) initial release |
# |
|
""" |
================ |
NoCmodel package |
================ |
|
This package includes: |
|
* Module noc_base: NoCmodel Base Objects |
* Module noc_guilib: NoCmodel Graphic utilities |
* Module noc_tlm_base: NoCmodel TLM simulation support |
* Module noc_tlm_utils: helper functions for TLM simulation |
* Package basicmodels: basic examples of NoC objects (not imported by default) |
""" |
|
# required modules |
import networkx as nx |
|
# provided modules |
from noc_base import * |
from noc_guilib import * |
from noc_tlm_base import * |
from noc_tlm_utils import * |
|
__version__ = "0.1" |
/nocmodel/noc_tlm_base.py
0,0 → 1,255
#!/usr/bin/env python |
# -*- coding: utf-8 -*- |
|
# |
# NoC TLM simulation support |
# This module declares classes for Transaction Level Model simulation |
# |
# Author: Oscar Diaz |
# Version: 0.1 |
# Date: 03-03-2011 |
|
# |
# This code is free software; you can redistribute it and/or |
# modify it under the terms of the GNU Lesser General Public |
# License as published by the Free Software Foundation; either |
# version 2.1 of the License, or (at your option) any later version. |
# |
# This code is distributed in the hope that it will be useful, |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
# Lesser General Public License for more details. |
# |
# You should have received a copy of the GNU Lesser General Public |
# License along with this library; if not, write to the |
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
# Boston, MA 02111-1307 USA |
# |
|
# Transaction model: |
# |
# Objects in a noc model have a "tlm" member |
# This "tlm" implements function send() and recv() |
|
import networkx as nx |
import myhdl |
import logging |
|
from noc_base import * |
|
class noc_tlm_base(): |
""" |
Base class for NoC TLM simulator. |
|
This class add methods to a NoC object, required for the TLM model. Each |
derived class must override the methods: |
|
* __init__() : its constructor contains the object TLM model (data |
structures, generators, etc). |
* send() |
* recv() |
|
Other methods are related to simulation configuration and logging support. |
""" |
def __init__(self): |
self.log = logging.getLogger() |
self.logname = "BASECLASS" |
self.generators = [] |
|
def get_generators(self): |
return self.generators |
|
# TLM main: every object must define this functions |
def send(self, src, dest, data, addattrs=None): |
""" |
SEND method: this method MUST be called only by the local |
object who wants to start a transaction. |
|
This function will call the recv method in the right object. |
|
Arguments: |
* src: source object (or router address) that call this method, i.e. the |
object that starts the transaction. |
* dest: destination object (or router address) that receive the data in |
the transaction. This method will call dest' recv method. |
* data: data to be sent. Can be anything, but normally is an object of |
type packet. |
* addattrs: optional dictionary with additional arguments |
|
Return: Must return a number: 0 for everything OK, != 0 to show an error |
relevant to the caller, an exception in case of attribute error |
""" |
self.debug("-> send( %s , %s , %s , %s )" % (repr(src), repr(dest), repr(packet), repr(addattrs))) |
return noc_tlm_errcodes.not_implemented |
|
def recv(self, src, dest, data, addattrs=None): |
""" |
RECV method: this method MUST be called only by the send |
method of the object who started the transaction. |
|
Arguments: |
* src: source object (or router address) that call this method, i.e. the |
object that starts the transaction. |
* dest: destination object (or router address) that receive the data in |
the transaction. This method will call dest' recv method. |
* data: data to be sent. Can be anything, but normally is an object of |
type packet. |
* addattrs: optional dictionary with additional arguments |
|
@return Must return a number: 0 for everything OK, != 0 to show an error |
relevant to the caller, an exception in case of attribute error |
""" |
self.debug("-> recv( %s , %s , %s , %s )" % (repr(src), repr(dest), repr(packet), repr(addattrs))) |
return noc_tlm_errcodes.not_implemented |
|
# logging methods (only use 4 levels) |
def debug(self, msg, *args, **kwargs): |
self.log.debug(msg, extra={"objname": self.logname}, *args, **kwargs) |
def info(self, msg, *args, **kwargs): |
self.log.info(msg, extra={"objname": self.logname}, *args, **kwargs) |
def warning(self, msg, *args, **kwargs): |
self.log.warning(msg, extra={"objname": self.logname}, *args, **kwargs) |
def error(self, msg, *args, **kwargs): |
self.log.error(msg, extra={"objname": self.logname}, *args, **kwargs) |
|
# special log |
def debugstate(self): |
self.debug(" '%s' object state: " % repr(self)) |
for i in dir(self): |
# exclude hidden attributes |
if i[0] == "_": |
continue |
self.debug(" ['%s'] = %s " % (i, repr(getattr(self, i)))) |
|
class noc_tlm_simulation(): |
""" |
NoC TLM simulator object |
|
This class manages the MyHDL simulation on a NoC object and its logging |
support. |
|
Attributes: |
* noc_ref: reference to NoC model to simulate |
* log_file: optional file to save the simulation log |
* log_level: optional logging level for the previous file |
* kwargs: optional attributes to add to this object |
""" |
def __init__(self, noc_ref, log_file=None, log_level=logging.INFO, **kwargs): |
if isinstance(noc_ref, noc): |
self.noc_ref = noc_ref |
else: |
raise TypeError("This class needs a noc object as constructor argument.") |
# configure logging system |
# log errors to console, custom log to log_file if specified |
addmsg = "" |
self.log = logging.getLogger() |
self.log.setLevel(log_level) |
console_hdl = logging.StreamHandler() |
console_hdl.setLevel(logging.WARNING) |
class SimTimeFilter(logging.Filter): |
def filter(self, record): |
record.myhdltime = myhdl.now() |
return True |
self.log.addFilter(SimTimeFilter()) |
self.noc_formatter = logging.Formatter("%(myhdltime)4d:%(levelname)-5s:%(objname)-16s - %(message)s") |
console_hdl.setFormatter(self.noc_formatter) |
self.log.addHandler(console_hdl) |
if log_file != None: |
file_hdl = logging.FileHandler(log_file, 'w') |
file_hdl.setLevel(log_level) |
file_hdl.setFormatter(self.noc_formatter) |
self.log.addHandler(file_hdl) |
addmsg = "and on file (%s) level %s" % (log_file, logging._levelNames[log_level]) |
# ready to roll |
self.debug("Logging enabled! Running log on console level WARNING %s" % addmsg) |
|
def configure_simulation(self, max_time=None, add_generators=[]): |
""" |
Configure MyHDL simulation. |
|
Arguments: |
* max_time: optional max time to simulate. None means simulation |
without time limit. |
* add_generators: external MyHDL generators to add to the simulation |
""" |
# myhdl simulation: extract all generators and prepare |
# arguments |
for obj in self.noc_ref.all_list(): |
add_generators.extend(obj.tlm.get_generators()) |
if isinstance(obj, ipcore): |
add_generators.extend(obj.channel_ref.tlm.get_generators()) |
# debug info |
#self.debug("configure_simulation: list of generators:") |
#for gen in add_generators: |
#self.debug("configure_simulation: generator '%s'" % repr(gen)) |
self.sim_object = myhdl.Simulation(*add_generators) |
self.sim_duration = max_time |
self.debug("configure_simulation: will run until simulation time '%d'" % max_time) |
|
def run(self): |
""" |
Run MyHDL simulation |
""" |
self.debug("Start simulation") |
self.sim_object.run(self.sim_duration) |
self.debug("End simulation") |
|
# custom logging methods (only use 4 levels) |
def debug(self, msg, *args, **kwargs): |
self.log.debug(msg, extra={"objname": "TopNoC"}, *args, **kwargs) |
def info(self, msg, *args, **kwargs): |
self.log.info(msg, extra={"objname": "TopNoC"}, *args, **kwargs) |
def warning(self, msg, *args, **kwargs): |
self.log.warning(msg, extra={"objname": "TopNoC"}, *args, **kwargs) |
def error(self, msg, *args, **kwargs): |
self.log.error(msg, extra={"objname": "TopNoC"}, *args, **kwargs) |
|
# special log filter: log individually by object name |
def configure_byobject_logging(self, basefilename="", log_level=logging.INFO): |
""" |
Special log filter: log individually by object name |
|
Arguments: |
* basefilename: generated filenames will start with this string |
* log_level: optional logging level for previous files |
""" |
# base filter |
class ObjFilter(logging.Filter): |
def __init__(self, basename): |
self.basename = basename |
def filter(self, record): |
if record.objname == self.basename: |
return True |
return False |
# need a handler for each object |
for obj in self.noc_ref.all_list(): |
newfilter = ObjFilter(obj.tlm.logname) |
newhandler = logging.FileHandler("%s_%s.log" % (basefilename, obj.tlm.logname), "w") |
newhandler.setLevel(log_level) |
newhandler.addFilter(newfilter) |
newhandler.setFormatter(self.noc_formatter) |
self.log.addHandler(newhandler) |
# Transactions logger |
class TransFilter(logging.Filter): |
def filter(self, record): |
if record.message.find("->") == 0: |
return True |
return False |
newhandler = logging.FileHandler("%s_transactions.log" % basefilename, "w") |
newhandler.setLevel(log_level) |
newhandler.addFilter(TransFilter()) |
newhandler.setFormatter(self.noc_formatter) |
self.log.addHandler(newhandler) |
# TopNoC will not be added to this set |
self.debug("Special logging enabled. basefilename=%s level %s" % (basefilename, logging._levelNames[log_level])) |
|
class noc_tlm_errcodes(): |
""" |
Common error codes definition |
""" |
no_error = 0 |
full_fifo = -1 |
packet_bad_data = -2 |
tlm_badcall_recv = -3 |
tlm_badcall_send = -4 |
not_implemented = -5 |
/LICENSE.txt
0,0 → 1,504
GNU LESSER GENERAL PUBLIC LICENSE |
Version 2.1, February 1999 |
|
Copyright (C) 1991, 1999 Free Software Foundation, Inc. |
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Everyone is permitted to copy and distribute verbatim copies |
of this license document, but changing it is not allowed. |
|
[This is the first released version of the Lesser GPL. It also counts |
as the successor of the GNU Library Public License, version 2, hence |
the version number 2.1.] |
|
Preamble |
|
The licenses for most software are designed to take away your |
freedom to share and change it. By contrast, the GNU General Public |
Licenses are intended to guarantee your freedom to share and change |
free software--to make sure the software is free for all its users. |
|
This license, the Lesser General Public License, applies to some |
specially designated software packages--typically libraries--of the |
Free Software Foundation and other authors who decide to use it. You |
can use it too, but we suggest you first think carefully about whether |
this license or the ordinary General Public License is the better |
strategy to use in any particular case, based on the explanations below. |
|
When we speak of free software, we are referring to freedom of use, |
not price. Our General Public Licenses are designed to make sure that |
you have the freedom to distribute copies of free software (and charge |
for this service if you wish); that you receive source code or can get |
it if you want it; that you can change the software and use pieces of |
it in new free programs; and that you are informed that you can do |
these things. |
|
To protect your rights, we need to make restrictions that forbid |
distributors to deny you these rights or to ask you to surrender these |
rights. These restrictions translate to certain responsibilities for |
you if you distribute copies of the library or if you modify it. |
|
For example, if you distribute copies of the library, whether gratis |
or for a fee, you must give the recipients all the rights that we gave |
you. You must make sure that they, too, receive or can get the source |
code. If you link other code with the library, you must provide |
complete object files to the recipients, so that they can relink them |
with the library after making changes to the library and recompiling |
it. And you must show them these terms so they know their rights. |
|
We protect your rights with a two-step method: (1) we copyright the |
library, and (2) we offer you this license, which gives you legal |
permission to copy, distribute and/or modify the library. |
|
To protect each distributor, we want to make it very clear that |
there is no warranty for the free library. Also, if the library is |
modified by someone else and passed on, the recipients should know |
that what they have is not the original version, so that the original |
author's reputation will not be affected by problems that might be |
introduced by others. |
|
Finally, software patents pose a constant threat to the existence of |
any free program. We wish to make sure that a company cannot |
effectively restrict the users of a free program by obtaining a |
restrictive license from a patent holder. Therefore, we insist that |
any patent license obtained for a version of the library must be |
consistent with the full freedom of use specified in this license. |
|
Most GNU software, including some libraries, is covered by the |
ordinary GNU General Public License. This license, the GNU Lesser |
General Public License, applies to certain designated libraries, and |
is quite different from the ordinary General Public License. We use |
this license for certain libraries in order to permit linking those |
libraries into non-free programs. |
|
When a program is linked with a library, whether statically or using |
a shared library, the combination of the two is legally speaking a |
combined work, a derivative of the original library. The ordinary |
General Public License therefore permits such linking only if the |
entire combination fits its criteria of freedom. The Lesser General |
Public License permits more lax criteria for linking other code with |
the library. |
|
We call this license the "Lesser" General Public License because it |
does Less to protect the user's freedom than the ordinary General |
Public License. It also provides other free software developers Less |
of an advantage over competing non-free programs. These disadvantages |
are the reason we use the ordinary General Public License for many |
libraries. However, the Lesser license provides advantages in certain |
special circumstances. |
|
For example, on rare occasions, there may be a special need to |
encourage the widest possible use of a certain library, so that it becomes |
a de-facto standard. To achieve this, non-free programs must be |
allowed to use the library. A more frequent case is that a free |
library does the same job as widely used non-free libraries. In this |
case, there is little to gain by limiting the free library to free |
software only, so we use the Lesser General Public License. |
|
In other cases, permission to use a particular library in non-free |
programs enables a greater number of people to use a large body of |
free software. For example, permission to use the GNU C Library in |
non-free programs enables many more people to use the whole GNU |
operating system, as well as its variant, the GNU/Linux operating |
system. |
|
Although the Lesser General Public License is Less protective of the |
users' freedom, it does ensure that the user of a program that is |
linked with the Library has the freedom and the wherewithal to run |
that program using a modified version of the Library. |
|
The precise terms and conditions for copying, distribution and |
modification follow. Pay close attention to the difference between a |
"work based on the library" and a "work that uses the library". The |
former contains code derived from the library, whereas the latter must |
be combined with the library in order to run. |
|
GNU LESSER GENERAL PUBLIC LICENSE |
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION |
|
0. This License Agreement applies to any software library or other |
program which contains a notice placed by the copyright holder or |
other authorized party saying it may be distributed under the terms of |
this Lesser General Public License (also called "this License"). |
Each licensee is addressed as "you". |
|
A "library" means a collection of software functions and/or data |
prepared so as to be conveniently linked with application programs |
(which use some of those functions and data) to form executables. |
|
The "Library", below, refers to any such software library or work |
which has been distributed under these terms. A "work based on the |
Library" means either the Library or any derivative work under |
copyright law: that is to say, a work containing the Library or a |
portion of it, either verbatim or with modifications and/or translated |
straightforwardly into another language. (Hereinafter, translation is |
included without limitation in the term "modification".) |
|
"Source code" for a work means the preferred form of the work for |
making modifications to it. For a library, complete source code means |
all the source code for all modules it contains, plus any associated |
interface definition files, plus the scripts used to control compilation |
and installation of the library. |
|
Activities other than copying, distribution and modification are not |
covered by this License; they are outside its scope. The act of |
running a program using the Library is not restricted, and output from |
such a program is covered only if its contents constitute a work based |
on the Library (independent of the use of the Library in a tool for |
writing it). Whether that is true depends on what the Library does |
and what the program that uses the Library does. |
|
1. You may copy and distribute verbatim copies of the Library's |
complete source code as you receive it, in any medium, provided that |
you conspicuously and appropriately publish on each copy an |
appropriate copyright notice and disclaimer of warranty; keep intact |
all the notices that refer to this License and to the absence of any |
warranty; and distribute a copy of this License along with the |
Library. |
|
You may charge a fee for the physical act of transferring a copy, |
and you may at your option offer warranty protection in exchange for a |
fee. |
|
2. You may modify your copy or copies of the Library or any portion |
of it, thus forming a work based on the Library, and copy and |
distribute such modifications or work under the terms of Section 1 |
above, provided that you also meet all of these conditions: |
|
a) The modified work must itself be a software library. |
|
b) You must cause the files modified to carry prominent notices |
stating that you changed the files and the date of any change. |
|
c) You must cause the whole of the work to be licensed at no |
charge to all third parties under the terms of this License. |
|
d) If a facility in the modified Library refers to a function or a |
table of data to be supplied by an application program that uses |
the facility, other than as an argument passed when the facility |
is invoked, then you must make a good faith effort to ensure that, |
in the event an application does not supply such function or |
table, the facility still operates, and performs whatever part of |
its purpose remains meaningful. |
|
(For example, a function in a library to compute square roots has |
a purpose that is entirely well-defined independent of the |
application. Therefore, Subsection 2d requires that any |
application-supplied function or table used by this function must |
be optional: if the application does not supply it, the square |
root function must still compute square roots.) |
|
These requirements apply to the modified work as a whole. If |
identifiable sections of that work are not derived from the Library, |
and can be reasonably considered independent and separate works in |
themselves, then this License, and its terms, do not apply to those |
sections when you distribute them as separate works. But when you |
distribute the same sections as part of a whole which is a work based |
on the Library, the distribution of the whole must be on the terms of |
this License, whose permissions for other licensees extend to the |
entire whole, and thus to each and every part regardless of who wrote |
it. |
|
Thus, it is not the intent of this section to claim rights or contest |
your rights to work written entirely by you; rather, the intent is to |
exercise the right to control the distribution of derivative or |
collective works based on the Library. |
|
In addition, mere aggregation of another work not based on the Library |
with the Library (or with a work based on the Library) on a volume of |
a storage or distribution medium does not bring the other work under |
the scope of this License. |
|
3. You may opt to apply the terms of the ordinary GNU General Public |
License instead of this License to a given copy of the Library. To do |
this, you must alter all the notices that refer to this License, so |
that they refer to the ordinary GNU General Public License, version 2, |
instead of to this License. (If a newer version than version 2 of the |
ordinary GNU General Public License has appeared, then you can specify |
that version instead if you wish.) Do not make any other change in |
these notices. |
|
Once this change is made in a given copy, it is irreversible for |
that copy, so the ordinary GNU General Public License applies to all |
subsequent copies and derivative works made from that copy. |
|
This option is useful when you wish to copy part of the code of |
the Library into a program that is not a library. |
|
4. You may copy and distribute the Library (or a portion or |
derivative of it, under Section 2) in object code or executable form |
under the terms of Sections 1 and 2 above provided that you accompany |
it with the complete corresponding machine-readable source code, which |
must be distributed under the terms of Sections 1 and 2 above on a |
medium customarily used for software interchange. |
|
If distribution of object code is made by offering access to copy |
from a designated place, then offering equivalent access to copy the |
source code from the same place satisfies the requirement to |
distribute the source code, even though third parties are not |
compelled to copy the source along with the object code. |
|
5. A program that contains no derivative of any portion of the |
Library, but is designed to work with the Library by being compiled or |
linked with it, is called a "work that uses the Library". Such a |
work, in isolation, is not a derivative work of the Library, and |
therefore falls outside the scope of this License. |
|
However, linking a "work that uses the Library" with the Library |
creates an executable that is a derivative of the Library (because it |
contains portions of the Library), rather than a "work that uses the |
library". The executable is therefore covered by this License. |
Section 6 states terms for distribution of such executables. |
|
When a "work that uses the Library" uses material from a header file |
that is part of the Library, the object code for the work may be a |
derivative work of the Library even though the source code is not. |
Whether this is true is especially significant if the work can be |
linked without the Library, or if the work is itself a library. The |
threshold for this to be true is not precisely defined by law. |
|
If such an object file uses only numerical parameters, data |
structure layouts and accessors, and small macros and small inline |
functions (ten lines or less in length), then the use of the object |
file is unrestricted, regardless of whether it is legally a derivative |
work. (Executables containing this object code plus portions of the |
Library will still fall under Section 6.) |
|
Otherwise, if the work is a derivative of the Library, you may |
distribute the object code for the work under the terms of Section 6. |
Any executables containing that work also fall under Section 6, |
whether or not they are linked directly with the Library itself. |
|
6. As an exception to the Sections above, you may also combine or |
link a "work that uses the Library" with the Library to produce a |
work containing portions of the Library, and distribute that work |
under terms of your choice, provided that the terms permit |
modification of the work for the customer's own use and reverse |
engineering for debugging such modifications. |
|
You must give prominent notice with each copy of the work that the |
Library is used in it and that the Library and its use are covered by |
this License. You must supply a copy of this License. If the work |
during execution displays copyright notices, you must include the |
copyright notice for the Library among them, as well as a reference |
directing the user to the copy of this License. Also, you must do one |
of these things: |
|
a) Accompany the work with the complete corresponding |
machine-readable source code for the Library including whatever |
changes were used in the work (which must be distributed under |
Sections 1 and 2 above); and, if the work is an executable linked |
with the Library, with the complete machine-readable "work that |
uses the Library", as object code and/or source code, so that the |
user can modify the Library and then relink to produce a modified |
executable containing the modified Library. (It is understood |
that the user who changes the contents of definitions files in the |
Library will not necessarily be able to recompile the application |
to use the modified definitions.) |
|
b) Use a suitable shared library mechanism for linking with the |
Library. A suitable mechanism is one that (1) uses at run time a |
copy of the library already present on the user's computer system, |
rather than copying library functions into the executable, and (2) |
will operate properly with a modified version of the library, if |
the user installs one, as long as the modified version is |
interface-compatible with the version that the work was made with. |
|
c) Accompany the work with a written offer, valid for at |
least three years, to give the same user the materials |
specified in Subsection 6a, above, for a charge no more |
than the cost of performing this distribution. |
|
d) If distribution of the work is made by offering access to copy |
from a designated place, offer equivalent access to copy the above |
specified materials from the same place. |
|
e) Verify that the user has already received a copy of these |
materials or that you have already sent this user a copy. |
|
For an executable, the required form of the "work that uses the |
Library" must include any data and utility programs needed for |
reproducing the executable from it. However, as a special exception, |
the materials to be distributed need not include anything that is |
normally distributed (in either source or binary form) with the major |
components (compiler, kernel, and so on) of the operating system on |
which the executable runs, unless that component itself accompanies |
the executable. |
|
It may happen that this requirement contradicts the license |
restrictions of other proprietary libraries that do not normally |
accompany the operating system. Such a contradiction means you cannot |
use both them and the Library together in an executable that you |
distribute. |
|
7. You may place library facilities that are a work based on the |
Library side-by-side in a single library together with other library |
facilities not covered by this License, and distribute such a combined |
library, provided that the separate distribution of the work based on |
the Library and of the other library facilities is otherwise |
permitted, and provided that you do these two things: |
|
a) Accompany the combined library with a copy of the same work |
based on the Library, uncombined with any other library |
facilities. This must be distributed under the terms of the |
Sections above. |
|
b) Give prominent notice with the combined library of the fact |
that part of it is a work based on the Library, and explaining |
where to find the accompanying uncombined form of the same work. |
|
8. You may not copy, modify, sublicense, link with, or distribute |
the Library except as expressly provided under this License. Any |
attempt otherwise to copy, modify, sublicense, link with, or |
distribute the Library is void, and will automatically terminate your |
rights under this License. However, parties who have received copies, |
or rights, from you under this License will not have their licenses |
terminated so long as such parties remain in full compliance. |
|
9. You are not required to accept this License, since you have not |
signed it. However, nothing else grants you permission to modify or |
distribute the Library or its derivative works. These actions are |
prohibited by law if you do not accept this License. Therefore, by |
modifying or distributing the Library (or any work based on the |
Library), you indicate your acceptance of this License to do so, and |
all its terms and conditions for copying, distributing or modifying |
the Library or works based on it. |
|
10. Each time you redistribute the Library (or any work based on the |
Library), the recipient automatically receives a license from the |
original licensor to copy, distribute, link with or modify the Library |
subject to these terms and conditions. You may not impose any further |
restrictions on the recipients' exercise of the rights granted herein. |
You are not responsible for enforcing compliance by third parties with |
this License. |
|
11. If, as a consequence of a court judgment or allegation of patent |
infringement or for any other reason (not limited to patent issues), |
conditions are imposed on you (whether by court order, agreement or |
otherwise) that contradict the conditions of this License, they do not |
excuse you from the conditions of this License. If you cannot |
distribute so as to satisfy simultaneously your obligations under this |
License and any other pertinent obligations, then as a consequence you |
may not distribute the Library at all. For example, if a patent |
license would not permit royalty-free redistribution of the Library by |
all those who receive copies directly or indirectly through you, then |
the only way you could satisfy both it and this License would be to |
refrain entirely from distribution of the Library. |
|
If any portion of this section is held invalid or unenforceable under any |
particular circumstance, the balance of the section is intended to apply, |
and the section as a whole is intended to apply in other circumstances. |
|
It is not the purpose of this section to induce you to infringe any |
patents or other property right claims or to contest validity of any |
such claims; this section has the sole purpose of protecting the |
integrity of the free software distribution system which is |
implemented by public license practices. Many people have made |
generous contributions to the wide range of software distributed |
through that system in reliance on consistent application of that |
system; it is up to the author/donor to decide if he or she is willing |
to distribute software through any other system and a licensee cannot |
impose that choice. |
|
This section is intended to make thoroughly clear what is believed to |
be a consequence of the rest of this License. |
|
12. If the distribution and/or use of the Library is restricted in |
certain countries either by patents or by copyrighted interfaces, the |
original copyright holder who places the Library under this License may add |
an explicit geographical distribution limitation excluding those countries, |
so that distribution is permitted only in or among countries not thus |
excluded. In such case, this License incorporates the limitation as if |
written in the body of this License. |
|
13. The Free Software Foundation may publish revised and/or new |
versions of the Lesser General Public License from time to time. |
Such new versions will be similar in spirit to the present version, |
but may differ in detail to address new problems or concerns. |
|
Each version is given a distinguishing version number. If the Library |
specifies a version number of this License which applies to it and |
"any later version", you have the option of following the terms and |
conditions either of that version or of any later version published by |
the Free Software Foundation. If the Library does not specify a |
license version number, you may choose any version ever published by |
the Free Software Foundation. |
|
14. If you wish to incorporate parts of the Library into other free |
programs whose distribution conditions are incompatible with these, |
write to the author to ask for permission. For software which is |
copyrighted by the Free Software Foundation, write to the Free |
Software Foundation; we sometimes make exceptions for this. Our |
decision will be guided by the two goals of preserving the free status |
of all derivatives of our free software and of promoting the sharing |
and reuse of software generally. |
|
NO WARRANTY |
|
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO |
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. |
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR |
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY |
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE |
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE |
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME |
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. |
|
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN |
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY |
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU |
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR |
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE |
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING |
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A |
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF |
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
DAMAGES. |
|
END OF TERMS AND CONDITIONS |
|
How to Apply These Terms to Your New Libraries |
|
If you develop a new library, and you want it to be of the greatest |
possible use to the public, we recommend making it free software that |
everyone can redistribute and change. You can do so by permitting |
redistribution under these terms (or, alternatively, under the terms of the |
ordinary General Public License). |
|
To apply these terms, attach the following notices to the library. It is |
safest to attach them to the start of each source file to most effectively |
convey the exclusion of warranty; and each file should have at least the |
"copyright" line and a pointer to where the full notice is found. |
|
<one line to give the library's name and a brief idea of what it does.> |
Copyright (C) <year> <name of author> |
|
This library is free software; you can redistribute it and/or |
modify it under the terms of the GNU Lesser General Public |
License as published by the Free Software Foundation; either |
version 2.1 of the License, or (at your option) any later version. |
|
This library is distributed in the hope that it will be useful, |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
Lesser General Public License for more details. |
|
You should have received a copy of the GNU Lesser General Public |
License along with this library; if not, write to the Free Software |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
Also add information on how to contact you by electronic and paper mail. |
|
You should also get your employer (if you work as a programmer) or your |
school, if any, to sign a "copyright disclaimer" for the library, if |
necessary. Here is a sample; alter the names: |
|
Yoyodyne, Inc., hereby disclaims all copyright interest in the |
library `Frob' (a library for tweaking knobs) written by James Random Hacker. |
|
<signature of Ty Coon>, 1 April 1990 |
Ty Coon, President of Vice |
|
That's all there is to it! |
|
|
/TODO.txt
0,0 → 1,10
Plan for future releases: |
|
nocmodel (0.1) |
|
* Write a set of examples using unittest. |
* Add more NoC object models |
* Start with code generation mechanism |
* Add more detailed documentation |
|
-- Oscar Diaz <dargor@opencores.org> Thr, 03 Mar 2011 23:10:25 +0100 |
/doc/nocmodel.basicmodels.basic_channel.html
0,0 → 1,79
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
<html><head><title>Python: module nocmodel.basicmodels.basic_channel</title> |
</head><body bgcolor="#f0f0f8"> |
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading"> |
<tr bgcolor="#7799ee"> |
<td valign=bottom> <br> |
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="nocmodel.html"><font color="#ffffff">nocmodel</font></a>.<a href="nocmodel.basicmodels.html"><font color="#ffffff">basicmodels</font></a>.basic_channel</strong></big></big></font></td |
><td align=right valign=bottom |
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/oscard/Documentos/proyectos/nocmodel-0.1/nocmodel/basicmodels/basic_channel.py">/home/oscard/Documentos/proyectos/nocmodel-0.1/nocmodel/basicmodels/basic_channel.py</a></font></td></tr></table> |
<p><tt>Basic channel TLM model</tt></p> |
<p> |
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
<tr bgcolor="#aa55cc"> |
<td colspan=3 valign=bottom> <br> |
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr> |
|
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td> |
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="logging.html">logging</a><br> |
</td><td width="25%" valign=top><a href="myhdl.html">myhdl</a><br> |
</td><td width="25%" valign=top><a href="networkx.html">networkx</a><br> |
</td><td width="25%" valign=top></td></tr></table></td></tr></table><p> |
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
<tr bgcolor="#ee77aa"> |
<td colspan=3 valign=bottom> <br> |
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr> |
|
<tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td> |
<td width="100%"><dl> |
<dt><font face="helvetica, arial"><a href="nocmodel.noc_tlm_base.html#noc_tlm_base">nocmodel.noc_tlm_base.noc_tlm_base</a> |
</font></dt><dd> |
<dl> |
<dt><font face="helvetica, arial"><a href="nocmodel.basicmodels.basic_channel.html#basic_channel_tlm">basic_channel_tlm</a> |
</font></dt></dl> |
</dd> |
</dl> |
<p> |
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
<tr bgcolor="#ffc8d8"> |
<td colspan=3 valign=bottom> <br> |
<font color="#000000" face="helvetica, arial"><a name="basic_channel_tlm">class <strong>basic_channel_tlm</strong></a>(<a href="nocmodel.noc_tlm_base.html#noc_tlm_base">nocmodel.noc_tlm_base.noc_tlm_base</a>)</font></td></tr> |
|
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
<td colspan=2><tt>TLM model of a NoC channel. It models a simple FIFO channel with<br> |
adjustable delay. This channel will move any kind of data as a whole, but<br> |
ideally will move packet objects.<br> |
<br> |
Attributes:<br> |
* Channel delay: delay in clock ticks.<br> |
<br> |
Notes:<br> |
*This model is completely behavioral<br> </tt></td></tr> |
<tr><td> </td> |
<td width="100%">Methods defined here:<br> |
<dl><dt><a name="basic_channel_tlm-__init__"><strong>__init__</strong></a>(self, channel_ref, channel_delay<font color="#909090">=1</font>)</dt></dl> |
|
<dl><dt><a name="basic_channel_tlm-recv"><strong>recv</strong></a>(self, src, dest, packet, addattrs<font color="#909090">=None</font>)</dt><dd><tt>receive a packet from an object. src is the object source and<br> |
it MUST be one of the objects in channel endpoints</tt></dd></dl> |
|
<dl><dt><a name="basic_channel_tlm-send"><strong>send</strong></a>(self, src, dest, packet, addattrs<font color="#909090">=None</font>)</dt><dd><tt>This method will be called by recv (no delay) or by delay_generator<br> |
src always is self</tt></dd></dl> |
|
<hr> |
Methods inherited from <a href="nocmodel.noc_tlm_base.html#noc_tlm_base">nocmodel.noc_tlm_base.noc_tlm_base</a>:<br> |
<dl><dt><a name="basic_channel_tlm-debug"><strong>debug</strong></a>(self, msg, *args, **kwargs)</dt><dd><tt># logging methods (only use 4 levels)</tt></dd></dl> |
|
<dl><dt><a name="basic_channel_tlm-debugstate"><strong>debugstate</strong></a>(self)</dt><dd><tt># special log</tt></dd></dl> |
|
<dl><dt><a name="basic_channel_tlm-error"><strong>error</strong></a>(self, msg, *args, **kwargs)</dt></dl> |
|
<dl><dt><a name="basic_channel_tlm-get_generators"><strong>get_generators</strong></a>(self)</dt></dl> |
|
<dl><dt><a name="basic_channel_tlm-info"><strong>info</strong></a>(self, msg, *args, **kwargs)</dt></dl> |
|
<dl><dt><a name="basic_channel_tlm-warning"><strong>warning</strong></a>(self, msg, *args, **kwargs)</dt></dl> |
|
</td></tr></table></td></tr></table> |
</body></html> |
/doc/nocmodel.html
0,0 → 1,43
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
<html><head><title>Python: package nocmodel</title> |
</head><body bgcolor="#f0f0f8"> |
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading"> |
<tr bgcolor="#7799ee"> |
<td valign=bottom> <br> |
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong>nocmodel</strong></big></big> (version 0.1)</font></td |
><td align=right valign=bottom |
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/oscard/Documentos/proyectos/nocmodel-0.1/nocmodel/__init__.py">/home/oscard/Documentos/proyectos/nocmodel-0.1/nocmodel/__init__.py</a></font></td></tr></table> |
<p><tt>================<br> |
NoCmodel package<br> |
================<br> |
<br> |
This package includes:<br> |
<br> |
* Module noc_base: NoCmodel Base Objects<br> |
* Module noc_guilib: NoCmodel Graphic utilities<br> |
* Module noc_tlm_base: NoCmodel TLM simulation support<br> |
* Module noc_tlm_utils: helper functions for TLM simulation<br> |
* Package basicmodels: basic examples of NoC objects (not imported by default)</tt></p> |
<p> |
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
<tr bgcolor="#aa55cc"> |
<td colspan=3 valign=bottom> <br> |
<font color="#ffffff" face="helvetica, arial"><big><strong>Package Contents</strong></big></font></td></tr> |
|
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td> |
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="nocmodel.basicmodels.html"><strong>basicmodels</strong> (package)</a><br> |
<a href="nocmodel.noc_base.html">noc_base</a><br> |
</td><td width="25%" valign=top><a href="nocmodel.noc_guilib.html">noc_guilib</a><br> |
<a href="nocmodel.noc_tlm_base.html">noc_tlm_base</a><br> |
</td><td width="25%" valign=top><a href="nocmodel.noc_tlm_utils.html">noc_tlm_utils</a><br> |
</td><td width="25%" valign=top></td></tr></table></td></tr></table><p> |
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
<tr bgcolor="#55aa55"> |
<td colspan=3 valign=bottom> <br> |
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr> |
|
<tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td> |
<td width="100%"><strong>__version__</strong> = '0.1'</td></tr></table> |
</body></html> |
/doc/nocmodel.noc_tlm_base.html
0,0 → 1,72
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
<html><head><title>Python: class noc_tlm_base</title> |
</head><body bgcolor="#f0f0f8"> |
<p> |
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
<tr bgcolor="#ffc8d8"> |
<td colspan=3 valign=bottom> <br> |
<font color="#000000" face="helvetica, arial"><strong>nocmodel.noc_tlm_base</strong> = <a name="nocmodel.noc_tlm_base">class noc_tlm_base</a></font></td></tr> |
|
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
<td colspan=2><tt>Base class for NoC TLM simulator.<br> |
<br> |
This class add methods to a NoC object, required for the TLM model. Each <br> |
derived class must override the methods:<br> |
<br> |
* <a href="#nocmodel.noc_tlm_base-__init__">__init__</a>() : its constructor contains the object TLM model (data <br> |
structures, generators, etc).<br> |
* <a href="#nocmodel.noc_tlm_base-send">send</a>() <br> |
* <a href="#nocmodel.noc_tlm_base-recv">recv</a>()<br> |
<br> |
Other methods are related to simulation configuration and logging support.<br> </tt></td></tr> |
<tr><td> </td> |
<td width="100%">Methods defined here:<br> |
<dl><dt><a name="noc_tlm_base-__init__"><strong>__init__</strong></a>(self)</dt></dl> |
|
<dl><dt><a name="noc_tlm_base-debug"><strong>debug</strong></a>(self, msg, *args, **kwargs)</dt><dd><tt># logging methods (only use 4 levels)</tt></dd></dl> |
|
<dl><dt><a name="noc_tlm_base-debugstate"><strong>debugstate</strong></a>(self)</dt><dd><tt># special log</tt></dd></dl> |
|
<dl><dt><a name="noc_tlm_base-error"><strong>error</strong></a>(self, msg, *args, **kwargs)</dt></dl> |
|
<dl><dt><a name="noc_tlm_base-get_generators"><strong>get_generators</strong></a>(self)</dt></dl> |
|
<dl><dt><a name="noc_tlm_base-info"><strong>info</strong></a>(self, msg, *args, **kwargs)</dt></dl> |
|
<dl><dt><a name="noc_tlm_base-recv"><strong>recv</strong></a>(self, src, dest, data, addattrs<font color="#909090">=None</font>)</dt><dd><tt>RECV method: this method MUST be called only by the send<br> |
method of the object who started the transaction.<br> |
<br> |
Arguments:<br> |
* src: source object (or router address) that call this method, i.e. the<br> |
object that starts the transaction.<br> |
* dest: destination object (or router address) that receive the data in<br> |
the transaction. This method will call dest' recv method.<br> |
* data: data to be sent. Can be anything, but normally is an object of<br> |
type packet.<br> |
* addattrs: optional dictionary with additional arguments<br> |
<br> |
@return Must return a number: 0 for everything OK, != 0 to show an error<br> |
relevant to the caller, an exception in case of attribute error</tt></dd></dl> |
|
<dl><dt><a name="noc_tlm_base-send"><strong>send</strong></a>(self, src, dest, data, addattrs<font color="#909090">=None</font>)</dt><dd><tt>SEND method: this method MUST be called only by the local<br> |
object who wants to start a transaction.<br> |
<br> |
This function will call the recv method in the right object.<br> |
<br> |
Arguments:<br> |
* src: source object (or router address) that call this method, i.e. the<br> |
object that starts the transaction.<br> |
* dest: destination object (or router address) that receive the data in<br> |
the transaction. This method will call dest' recv method.<br> |
* data: data to be sent. Can be anything, but normally is an object of<br> |
type packet.<br> |
* addattrs: optional dictionary with additional arguments<br> |
<br> |
Return: Must return a number: 0 for everything OK, != 0 to show an error<br> |
relevant to the caller, an exception in case of attribute error</tt></dd></dl> |
|
<dl><dt><a name="noc_tlm_base-warning"><strong>warning</strong></a>(self, msg, *args, **kwargs)</dt></dl> |
|
</td></tr></table> |
</body></html> |
/doc/nocmodel.basicmodels.html
0,0 → 1,41
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
<html><head><title>Python: package nocmodel.basicmodels</title> |
</head><body bgcolor="#f0f0f8"> |
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading"> |
<tr bgcolor="#7799ee"> |
<td valign=bottom> <br> |
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="nocmodel.html"><font color="#ffffff">nocmodel</font></a>.basicmodels</strong></big></big> (version 0.1)</font></td |
><td align=right valign=bottom |
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/oscard/Documentos/proyectos/nocmodel-0.1/nocmodel/basicmodels/__init__.py">/home/oscard/Documentos/proyectos/nocmodel-0.1/nocmodel/basicmodels/__init__.py</a></font></td></tr></table> |
<p><tt>================<br> |
NoCmodel basic models for testing<br> |
================<br> |
<br> |
This package includes:<br> |
<br> |
* Module basic_channel<br> |
* Module basic_ipcore<br> |
* Module basic_protocol<br> |
* Module basic_router</tt></p> |
<p> |
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
<tr bgcolor="#aa55cc"> |
<td colspan=3 valign=bottom> <br> |
<font color="#ffffff" face="helvetica, arial"><big><strong>Package Contents</strong></big></font></td></tr> |
|
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td> |
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="nocmodel.basicmodels.basic_channel.html">basic_channel</a><br> |
</td><td width="25%" valign=top><a href="nocmodel.basicmodels.basic_ipcore.html">basic_ipcore</a><br> |
</td><td width="25%" valign=top><a href="nocmodel.basicmodels.basic_protocol.html">basic_protocol</a><br> |
</td><td width="25%" valign=top><a href="nocmodel.basicmodels.basic_router.html">basic_router</a><br> |
</td></tr></table></td></tr></table><p> |
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
<tr bgcolor="#55aa55"> |
<td colspan=3 valign=bottom> <br> |
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr> |
|
<tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td> |
<td width="100%"><strong>__version__</strong> = '0.1'</td></tr></table> |
</body></html> |
/doc/nocmodel.basicmodels.basic_router.html
0,0 → 1,90
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
<html><head><title>Python: module nocmodel.basicmodels.basic_router</title> |
</head><body bgcolor="#f0f0f8"> |
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading"> |
<tr bgcolor="#7799ee"> |
<td valign=bottom> <br> |
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="nocmodel.html"><font color="#ffffff">nocmodel</font></a>.<a href="nocmodel.basicmodels.html"><font color="#ffffff">basicmodels</font></a>.basic_router</strong></big></big></font></td |
><td align=right valign=bottom |
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/oscard/Documentos/proyectos/nocmodel-0.1/nocmodel/basicmodels/basic_router.py">/home/oscard/Documentos/proyectos/nocmodel-0.1/nocmodel/basicmodels/basic_router.py</a></font></td></tr></table> |
<p><tt>Basic router TLM model</tt></p> |
<p> |
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
<tr bgcolor="#aa55cc"> |
<td colspan=3 valign=bottom> <br> |
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr> |
|
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td> |
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="logging.html">logging</a><br> |
</td><td width="25%" valign=top><a href="myhdl.html">myhdl</a><br> |
</td><td width="25%" valign=top><a href="networkx.html">networkx</a><br> |
</td><td width="25%" valign=top></td></tr></table></td></tr></table><p> |
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
<tr bgcolor="#ee77aa"> |
<td colspan=3 valign=bottom> <br> |
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr> |
|
<tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td> |
<td width="100%"><dl> |
<dt><font face="helvetica, arial"><a href="nocmodel.noc_tlm_base.html#noc_tlm_base">nocmodel.noc_tlm_base.noc_tlm_base</a> |
</font></dt><dd> |
<dl> |
<dt><font face="helvetica, arial"><a href="nocmodel.basicmodels.basic_router.html#basic_router_tlm">basic_router_tlm</a> |
</font></dt></dl> |
</dd> |
</dl> |
<p> |
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
<tr bgcolor="#ffc8d8"> |
<td colspan=3 valign=bottom> <br> |
<font color="#000000" face="helvetica, arial"><a name="basic_router_tlm">class <strong>basic_router_tlm</strong></a>(<a href="nocmodel.noc_tlm_base.html#noc_tlm_base">nocmodel.noc_tlm_base.noc_tlm_base</a>)</font></td></tr> |
|
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
<td colspan=2><tt>TLM model of a NoC router. This router uses store-and-forward technique, <br> |
using the routing information from the router object. This model just<br> |
forward the packet, and if the packet is in its router destination, send it<br> |
to its ipcore. Each package that the ipcore generates is delivered <br> |
automátically.<br> |
<br> |
Attributes:<br> |
* router_ref : base reference<br> |
* fifo_len: max number of packets to hold in each port<br> |
<br> |
Notes:<br> |
* This model is completely behavioral.<br> |
* See code comments to better understanding.<br> </tt></td></tr> |
<tr><td> </td> |
<td width="100%">Methods defined here:<br> |
<dl><dt><a name="basic_router_tlm-__init__"><strong>__init__</strong></a>(self, router_ref, fifo_len<font color="#909090">=4</font>)</dt></dl> |
|
<dl><dt><a name="basic_router_tlm-recv"><strong>recv</strong></a>(self, src, dest, packet, addattrs<font color="#909090">=None</font>)</dt><dd><tt>This method will be called by channel objects connected to this router.<br> |
<br> |
Notes:<br> |
* The recv method only affect the receiver FIFO sets<br> |
* Ignore dest object.</tt></dd></dl> |
|
<dl><dt><a name="basic_router_tlm-send"><strong>send</strong></a>(self, src, dest, packet, addattrs<font color="#909090">=None</font>)</dt><dd><tt>This method will be called on a fifo available data event<br> |
<br> |
Notes: <br> |
* Ignore src object.<br> |
* dest should be a channel object, but also can be a router address or<br> |
a router object.</tt></dd></dl> |
|
<hr> |
Methods inherited from <a href="nocmodel.noc_tlm_base.html#noc_tlm_base">nocmodel.noc_tlm_base.noc_tlm_base</a>:<br> |
<dl><dt><a name="basic_router_tlm-debug"><strong>debug</strong></a>(self, msg, *args, **kwargs)</dt><dd><tt># logging methods (only use 4 levels)</tt></dd></dl> |
|
<dl><dt><a name="basic_router_tlm-debugstate"><strong>debugstate</strong></a>(self)</dt><dd><tt># special log</tt></dd></dl> |
|
<dl><dt><a name="basic_router_tlm-error"><strong>error</strong></a>(self, msg, *args, **kwargs)</dt></dl> |
|
<dl><dt><a name="basic_router_tlm-get_generators"><strong>get_generators</strong></a>(self)</dt></dl> |
|
<dl><dt><a name="basic_router_tlm-info"><strong>info</strong></a>(self, msg, *args, **kwargs)</dt></dl> |
|
<dl><dt><a name="basic_router_tlm-warning"><strong>warning</strong></a>(self, msg, *args, **kwargs)</dt></dl> |
|
</td></tr></table></td></tr></table> |
</body></html> |
/doc/nocmodel.basicmodels.basic_protocol.html
0,0 → 1,63
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
<html><head><title>Python: class basic_protocol</title> |
</head><body bgcolor="#f0f0f8"> |
<p> |
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
<tr bgcolor="#ffc8d8"> |
<td colspan=3 valign=bottom> <br> |
<font color="#000000" face="helvetica, arial"><strong>nocmodel.basicmodels.basic_protocol</strong> = <a name="nocmodel.basicmodels.basic_protocol">class basic_protocol</a>(<a href="nocmodel.noc_base.html#protocol">nocmodel.noc_base.protocol</a>)</font></td></tr> |
|
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
<td colspan=2><tt>Basic protocol class<br> |
<br> |
This class simplify protocol object creation. It defines a simple packet<br> |
with the following fields:<br> |
<br> |
|0 7|8 15|16 31|<br> |
| src | dst | data |<br> </tt></td></tr> |
<tr><td> </td> |
<td width="100%"><dl><dt>Method resolution order:</dt> |
<dd><a href="nocmodel.basicmodels.basic_protocol.html#basic_protocol">basic_protocol</a></dd> |
<dd><a href="nocmodel.noc_base.html#protocol">nocmodel.noc_base.protocol</a></dd> |
<dd><a href="nocmodel.noc_base.html#nocobject">nocmodel.noc_base.nocobject</a></dd> |
</dl> |
<hr> |
Methods defined here:<br> |
<dl><dt><a name="basic_protocol-__init__"><strong>__init__</strong></a>(self)</dt></dl> |
|
<hr> |
Methods inherited from <a href="nocmodel.noc_base.html#protocol">nocmodel.noc_base.protocol</a>:<br> |
<dl><dt><a name="basic_protocol-get_protocol_ref"><strong>get_protocol_ref</strong></a>(self)</dt></dl> |
|
<dl><dt><a name="basic_protocol-newpacket"><strong>newpacket</strong></a>(self, zerodefault<font color="#909090">=True</font>, *args, **kwargs)</dt><dd><tt>Return a new packet with all required fields.<br> |
<br> |
Arguments:<br> |
* zerodefault: If True, all missing fields will be zeroed by default.<br> |
If False, a missing value in arguments will throw an exception.<br> |
* args: Nameless arguments will add field values based on packet field<br> |
order.<br> |
* kwargs: Key-based arguments will add specified field values based in <br> |
its keys<br> |
<br> |
Notes: <br> |
* kwargs takes precedence over args: i.e. named arguments can overwrite<br> |
nameless arguments.</tt></dd></dl> |
|
<dl><dt><a name="basic_protocol-register_packet_generator"><strong>register_packet_generator</strong></a>(self, packet_class)</dt><dd><tt>Register a special packet generator class.<br> |
<br> |
Must be a derived class of packet</tt></dd></dl> |
|
<dl><dt><a name="basic_protocol-update_packet_field"><strong>update_packet_field</strong></a>(self, name, type, bitlen, description<font color="#909090">=''</font>)</dt><dd><tt>Add or update a packet field.<br> |
<br> |
Arguments<br> |
* name<br> |
* type: string that can be "int", "fixed" or "float"<br> |
* bitlen: bit length of this field<br> |
* description: optional description of this field<br> |
<br> |
Notes: <br> |
* Each new field will be added at the end.</tt></dd></dl> |
|
</td></tr></table> |
</body></html> |
/doc/nocmodel.basicmodels.basic_ipcore.html
0,0 → 1,107
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
<html><head><title>Python: module nocmodel.basicmodels.basic_ipcore</title> |
</head><body bgcolor="#f0f0f8"> |
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading"> |
<tr bgcolor="#7799ee"> |
<td valign=bottom> <br> |
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="nocmodel.html"><font color="#ffffff">nocmodel</font></a>.<a href="nocmodel.basicmodels.html"><font color="#ffffff">basicmodels</font></a>.basic_ipcore</strong></big></big></font></td |
><td align=right valign=bottom |
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/oscard/Documentos/proyectos/nocmodel-0.1/nocmodel/basicmodels/basic_ipcore.py">/home/oscard/Documentos/proyectos/nocmodel-0.1/nocmodel/basicmodels/basic_ipcore.py</a></font></td></tr></table> |
<p><tt>Basic ipcore TLM model</tt></p> |
<p> |
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
<tr bgcolor="#aa55cc"> |
<td colspan=3 valign=bottom> <br> |
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr> |
|
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td> |
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="logging.html">logging</a><br> |
</td><td width="25%" valign=top><a href="myhdl.html">myhdl</a><br> |
</td><td width="25%" valign=top><a href="networkx.html">networkx</a><br> |
</td><td width="25%" valign=top></td></tr></table></td></tr></table><p> |
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
<tr bgcolor="#ee77aa"> |
<td colspan=3 valign=bottom> <br> |
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr> |
|
<tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td> |
<td width="100%"><dl> |
<dt><font face="helvetica, arial"><a href="nocmodel.noc_tlm_base.html#noc_tlm_base">nocmodel.noc_tlm_base.noc_tlm_base</a> |
</font></dt><dd> |
<dl> |
<dt><font face="helvetica, arial"><a href="nocmodel.basicmodels.basic_ipcore.html#basic_ipcore_tlm">basic_ipcore_tlm</a> |
</font></dt></dl> |
</dd> |
</dl> |
<p> |
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
<tr bgcolor="#ffc8d8"> |
<td colspan=3 valign=bottom> <br> |
<font color="#000000" face="helvetica, arial"><a name="basic_ipcore_tlm">class <strong>basic_ipcore_tlm</strong></a>(<a href="nocmodel.noc_tlm_base.html#noc_tlm_base">nocmodel.noc_tlm_base.noc_tlm_base</a>)</font></td></tr> |
|
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
<td colspan=2><tt>TLM model of a NoC ipcore. Its based on sending and receiving packets<br> |
to a custom-based MyHDL generators. This class does not define any<br> |
functionality.<br> |
<br> |
Attributes:<br> |
* ipcore_ref: reference to ipcore base object<br> |
<br> |
Notes:<br> |
* This model is completely behavioral.<br> |
* See code comments to better understanding.<br> </tt></td></tr> |
<tr><td> </td> |
<td width="100%">Methods defined here:<br> |
<dl><dt><a name="basic_ipcore_tlm-__init__"><strong>__init__</strong></a>(self, ipcore_ref)</dt></dl> |
|
<dl><dt><a name="basic_ipcore_tlm-recv"><strong>recv</strong></a>(self, src, dest, packet, addattrs<font color="#909090">=None</font>)</dt><dd><tt>Assumptions: <br> |
* Safely ignore src and dest arguments, because this method <br> |
is called only by local channel object.<br> |
* In theory src should be self.<strong>localch</strong>, and dest should be <br> |
self.<strong>ipcore_ref</strong> . This may be checked for errors.</tt></dd></dl> |
|
<dl><dt><a name="basic_ipcore_tlm-register_generator"><strong>register_generator</strong></a>(self, genfunction, **kwargs)</dt><dd><tt>Register a new generator for this ipcore. <br> |
<br> |
Arguments:<br> |
* genfunction: function that returns a MyHDL generator<br> |
* kwargs: optional keyed arguments to pass to genfunction call<br> |
<br> |
Notes:<br> |
* This method requires that genfunction has the following prototype:<br> |
* my_function(din, dout, tlm_ref, <other_arguments>)<br> |
* din is a MyHDL Signal of type packet, and is the input signal <br> |
to the ipcore. Use this signal to react to input events and <br> |
receive input packets.<br> |
* dout is a MyHDL Signal of type packet, and is the output <br> |
signal to the ipcore. Use this signal to send out packets to<br> |
local channel (and then insert into the NoC).<br> |
* tlm_ref is a reference to this object. Normal use is to access<br> |
logging methods (e.g. tlm_ref.<a href="#basic_ipcore_tlm-info">info</a>("message") ).<br> |
* <other_arguments> may be defined, this method use kwargs <br> |
argument to pass them.</tt></dd></dl> |
|
<dl><dt><a name="basic_ipcore_tlm-send"><strong>send</strong></a>(self, src, dest, packet, addattrs<font color="#909090">=None</font>)</dt><dd><tt>Assumptions: <br> |
* Safely ignore src and dest arguments, because this method <br> |
is called only by this object generators, therefore it always send <br> |
packets to the ipcore related channel.<br> |
* In theory src should be self.<strong>ipcore_ref</strong>, and dest should be <br> |
self.<strong>localch</strong> . This may be checked for errors.</tt></dd></dl> |
|
<hr> |
Methods inherited from <a href="nocmodel.noc_tlm_base.html#noc_tlm_base">nocmodel.noc_tlm_base.noc_tlm_base</a>:<br> |
<dl><dt><a name="basic_ipcore_tlm-debug"><strong>debug</strong></a>(self, msg, *args, **kwargs)</dt><dd><tt># logging methods (only use 4 levels)</tt></dd></dl> |
|
<dl><dt><a name="basic_ipcore_tlm-debugstate"><strong>debugstate</strong></a>(self)</dt><dd><tt># special log</tt></dd></dl> |
|
<dl><dt><a name="basic_ipcore_tlm-error"><strong>error</strong></a>(self, msg, *args, **kwargs)</dt></dl> |
|
<dl><dt><a name="basic_ipcore_tlm-get_generators"><strong>get_generators</strong></a>(self)</dt></dl> |
|
<dl><dt><a name="basic_ipcore_tlm-info"><strong>info</strong></a>(self, msg, *args, **kwargs)</dt></dl> |
|
<dl><dt><a name="basic_ipcore_tlm-warning"><strong>warning</strong></a>(self, msg, *args, **kwargs)</dt></dl> |
|
</td></tr></table></td></tr></table> |
</body></html> |
/doc/nocmodel.noc_base.html
0,0 → 1,1733
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
<html><head><title>Python: module nocmodel.noc_base</title> |
</head><body bgcolor="#f0f0f8"> |
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading"> |
<tr bgcolor="#7799ee"> |
<td valign=bottom> <br> |
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="nocmodel.html"><font color="#ffffff">nocmodel</font></a>.noc_base</strong></big></big></font></td |
><td align=right valign=bottom |
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/oscard/Documentos/proyectos/nocmodel-0.1/nocmodel/noc_base.py">/home/oscard/Documentos/proyectos/nocmodel-0.1/nocmodel/noc_base.py</a></font></td></tr></table> |
<p><tt>================<br> |
NoCmodel Base Objects<br> |
================<br> |
<br> |
This module declares classes used on a Network-on-chip representation:<br> |
<br> |
* NoC container class<br> |
* Router base class<br> |
* Channel base class<br> |
* IPCore base class<br> |
* Protocol base class<br> |
* Packet class</tt></p> |
<p> |
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
<tr bgcolor="#aa55cc"> |
<td colspan=3 valign=bottom> <br> |
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr> |
|
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td> |
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="networkx.html">networkx</a><br> |
</td><td width="25%" valign=top></td><td width="25%" valign=top></td><td width="25%" valign=top></td></tr></table></td></tr></table><p> |
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
<tr bgcolor="#ee77aa"> |
<td colspan=3 valign=bottom> <br> |
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr> |
|
<tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td> |
<td width="100%"><dl> |
<dt><font face="helvetica, arial"><a href="__builtin__.html#dict">__builtin__.dict</a>(<a href="__builtin__.html#object">__builtin__.object</a>) |
</font></dt><dd> |
<dl> |
<dt><font face="helvetica, arial"><a href="nocmodel.noc_base.html#packet">packet</a> |
</font></dt></dl> |
</dd> |
<dt><font face="helvetica, arial"><a href="networkx.classes.graph.html#Graph">networkx.classes.graph.Graph</a>(<a href="__builtin__.html#object">__builtin__.object</a>) |
</font></dt><dd> |
<dl> |
<dt><font face="helvetica, arial"><a href="nocmodel.noc_base.html#noc">noc</a> |
</font></dt></dl> |
</dd> |
<dt><font face="helvetica, arial"><a href="nocmodel.noc_base.html#nocobject">nocobject</a> |
</font></dt><dd> |
<dl> |
<dt><font face="helvetica, arial"><a href="nocmodel.noc_base.html#channel">channel</a> |
</font></dt><dt><font face="helvetica, arial"><a href="nocmodel.noc_base.html#ipcore">ipcore</a> |
</font></dt><dt><font face="helvetica, arial"><a href="nocmodel.noc_base.html#protocol">protocol</a> |
</font></dt><dt><font face="helvetica, arial"><a href="nocmodel.noc_base.html#router">router</a> |
</font></dt></dl> |
</dd> |
</dl> |
<p> |
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
<tr bgcolor="#ffc8d8"> |
<td colspan=3 valign=bottom> <br> |
<font color="#000000" face="helvetica, arial"><a name="channel">class <strong>channel</strong></a>(<a href="nocmodel.noc_base.html#nocobject">nocobject</a>)</font></td></tr> |
|
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
<td colspan=2><tt>Channel base object<br> |
<br> |
This object represents a <a href="#channel">channel</a> object and its properties. This base class<br> |
is meant to either be inherited or extended by adding other attributes.<br> |
<br> |
Relations with other objects:<br> |
* It should be related to one NoC model object (self.<strong>graph_ref</strong>)<br> |
* It may be one of the edge attributes in the graph model <br> |
(edge["channel_ref"]). In this case, this <a href="#channel">channel</a> connects two routers<br> |
in the NoC model.<br> |
* It should have two references to NoC objects (self.<strong>endpoints</strong>). Two options<br> |
exists: two routers references (<a href="#channel">channel</a> has an edge object) or, one<br> |
<a href="#router">router</a> and one <a href="#ipcore">ipcore</a> (<a href="#channel">channel</a> don't have any edge object).<br> |
<br> |
Attributes:<br> |
* name<br> |
* index: optional index on a <a href="#noc">noc</a> object. Must have an index when it has<br> |
a related edge in the graph model (and allowing it to be able to do<br> |
<a href="#channel">channel</a> searching). None means it is an <a href="#ipcore">ipcore</a> related <a href="#channel">channel</a><br> |
* graph_ref optional reference to its graph model<br> |
* endpoints optional two-item list with references to the connected objects<br> </tt></td></tr> |
<tr><td> </td> |
<td width="100%">Methods defined here:<br> |
<dl><dt><a name="channel-__init__"><strong>__init__</strong></a>(self, name, index<font color="#909090">=None</font>, **kwargs)</dt></dl> |
|
<dl><dt><a name="channel-is_ipcore_link"><strong>is_ipcore_link</strong></a>(self)</dt><dd><tt>Checks if this <a href="#channel">channel</a> is a special link for an <a href="#ipcore">ipcore</a>.<br> |
<br> |
Return: True if the <a href="#channel">channel</a> is related to an <a href="#ipcore">ipcore</a></tt></dd></dl> |
|
<hr> |
Methods inherited from <a href="nocmodel.noc_base.html#nocobject">nocobject</a>:<br> |
<dl><dt><a name="channel-get_protocol_ref"><strong>get_protocol_ref</strong></a>(self)</dt><dd><tt>Get <a href="#protocol">protocol</a> object for this instance</tt></dd></dl> |
|
</td></tr></table> <p> |
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
<tr bgcolor="#ffc8d8"> |
<td colspan=3 valign=bottom> <br> |
<font color="#000000" face="helvetica, arial"><a name="ipcore">class <strong>ipcore</strong></a>(<a href="nocmodel.noc_base.html#nocobject">nocobject</a>)</font></td></tr> |
|
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
<td colspan=2><tt>IP core base object<br> |
<br> |
This object represents a IP Core object and its properties. This base class<br> |
is meant to either be inherited or extended by adding other attributes.<br> |
<br> |
Relations with other objects:<br> |
* It should be related to one NoC model object (self.<strong>graph_ref</strong>)<br> |
* It should have one reference to a <a href="#router">router</a> object (self.<strong>router_ref</strong>), even if<br> |
the <a href="#ipcore">ipcore</a> has a direct connection to the NoC.<br> |
* It should have one reference to a <a href="#channel">channel</a> object (self.<strong>channel_ref</strong>). This<br> |
<a href="#channel">channel</a> exclusively link this <a href="#ipcore">ipcore</a> and its <a href="#router">router</a>.<br> |
<br> |
Attributes:<br> |
* name<br> |
* router_ref: optional reference to its related <a href="#router">router</a>.<br> |
* channel_ref: optional reference to its related <a href="#channel">channel</a><br> |
* graph_ref: optional reference to its graph model<br> </tt></td></tr> |
<tr><td> </td> |
<td width="100%">Methods defined here:<br> |
<dl><dt><a name="ipcore-__init__"><strong>__init__</strong></a>(self, name, **kwargs)</dt></dl> |
|
<hr> |
Methods inherited from <a href="nocmodel.noc_base.html#nocobject">nocobject</a>:<br> |
<dl><dt><a name="ipcore-get_protocol_ref"><strong>get_protocol_ref</strong></a>(self)</dt><dd><tt>Get <a href="#protocol">protocol</a> object for this instance</tt></dd></dl> |
|
</td></tr></table> <p> |
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
<tr bgcolor="#ffc8d8"> |
<td colspan=3 valign=bottom> <br> |
<font color="#000000" face="helvetica, arial"><a name="noc">class <strong>noc</strong></a>(<a href="networkx.classes.graph.html#Graph">networkx.classes.graph.Graph</a>)</font></td></tr> |
|
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
<td colspan=2><tt>Base class for NoC modeling.<br> |
Based on a <a href="networkx.classes.graph.html#Graph">Graph</a> object that hold the NoC structure<br> |
<br> |
Arguments<br> |
* kwargs: optional parameters to put as object attributes<br> </tt></td></tr> |
<tr><td> </td> |
<td width="100%"><dl><dt>Method resolution order:</dt> |
<dd><a href="nocmodel.noc_base.html#noc">noc</a></dd> |
<dd><a href="networkx.classes.graph.html#Graph">networkx.classes.graph.Graph</a></dd> |
<dd><a href="__builtin__.html#object">__builtin__.object</a></dd> |
</dl> |
<hr> |
Methods defined here:<br> |
<dl><dt><a name="noc-__init__"><strong>__init__</strong></a>(self, **kwargs)</dt><dd><tt>NoCmodel constructor</tt></dd></dl> |
|
<dl><dt><a name="noc-add_channel"><strong>add_channel</strong></a>(self, router1, router2, name<font color="#909090">=''</font>, **kwargs)</dt><dd><tt>Create a base <a href="#channel">channel</a> object to link two objects and add it <br> |
to NoC model.<br> |
<br> |
Arguments:<br> |
* router1: reference to a <a href="#router">router</a>, <a href="#router">router</a> index or <a href="#ipcore">ipcore</a><br> |
* router2: -idem-<br> |
* name: optional argument for <a href="#channel">channel</a> name<br> |
* kwargs: optional parameters to put as object attributes<br> |
<br> |
Notes:<br> |
* If router1 or router2 is an <a href="#ipcore">ipcore</a> reference, this method creates<br> |
the special <a href="#channel">channel</a> object and update <a href="#ipcore">ipcore</a> references. Additionally,<br> |
if both arguments are ipcores, throw an error exception</tt></dd></dl> |
|
<dl><dt><a name="noc-add_from_channel"><strong>add_from_channel</strong></a>(self, channel_ref, router1<font color="#909090">=None</font>, router2<font color="#909090">=None</font>)</dt><dd><tt>Add a <a href="#channel">channel</a> object to NoC model.<br> |
<br> |
Use this function to add an object based on a derived class of <br> |
base <a href="#channel">channel</a> defined in this module.<br> |
<br> |
Arguments<br> |
* channel_ref: reference to the <a href="#channel">channel</a> object<br> |
* router1: optional reference to a <a href="#router">router</a>, <a href="#router">router</a> index or <a href="#ipcore">ipcore</a><br> |
* router2: -idem-<br> |
<br> |
Return: the same reference passed in channel_ref<br> |
<br> |
Notes:<br> |
* If router1 or router2 are not used as arguments, will assume that<br> |
<a href="#channel">channel</a> object has defined its attribute "endpoints" with the <br> |
objects to connect. If the objects don't exist in the NoC model,<br> |
throw an error exception.<br> |
<br> |
* If router1 or router2 is an <a href="#ipcore">ipcore</a> reference, this method creates<br> |
the special <a href="#channel">channel</a> object and update <a href="#ipcore">ipcore</a> references. Additionally,<br> |
if both arguments are ipcores, throw an error exception.<br> |
<br> |
* This function will change channel_ref.index and channel_ref.graph_ref <br> |
attributes when inserted in the NoC model. Also it may change <br> |
channel_ref.endpoints with router1 and router2 references.</tt></dd></dl> |
|
<dl><dt><a name="noc-add_from_ipcore"><strong>add_from_ipcore</strong></a>(self, ipcore_ref, router_ref, channel_ref<font color="#909090">=None</font>)</dt><dd><tt>Add a <a href="#ipcore">ipcore</a> object to NoC model.<br> |
<br> |
Arguments<br> |
* ipcore_ref: reference to <a href="#ipcore">ipcore</a> object<br> |
* router_ref: reference to an existing <a href="#router">router</a> to connect<br> |
* channel_ref: optional <a href="#channel">channel</a> object that connect the <a href="#router">router</a> and<br> |
the <a href="#ipcore">ipcore</a>. If not used, this function will create a new <a href="#channel">channel</a> object.<br> |
<br> |
Return: the same reference passed in ipcore_ref<br> |
<br> |
Notes:<br> |
* This function automatically adds a special <a href="#channel">channel</a> object <br> |
(<a href="#router">router</a>-to-<a href="#ipcore">ipcore</a>) and adjust its relations in all involved objects.</tt></dd></dl> |
|
<dl><dt><a name="noc-add_ipcore"><strong>add_ipcore</strong></a>(self, router_ref, name<font color="#909090">=''</font>, **kwargs)</dt><dd><tt>Create an <a href="#ipcore">ipcore</a> object and connect it to the <a href="#router">router</a> reference argument<br> |
<br> |
Arguments<br> |
* router_ref: reference to an existing <a href="#router">router</a><br> |
* name: optional name for this <a href="#router">router</a>. By default has the form of <br> |
"IP_<router_index>"<br> |
* kwargs: optional parameters to put as object attributes<br> |
<br> |
Return: reference to the created <a href="#ipcore">ipcore</a> object<br> |
<br> |
Notes:<br> |
* This function automatically adds a special <a href="#channel">channel</a> object <br> |
(<a href="#router">router</a>-to-<a href="#ipcore">ipcore</a>) and adjust its relations in all involved objects.</tt></dd></dl> |
|
<dl><dt><a name="noc-add_router"><strong>add_router</strong></a>(self, name<font color="#909090">=''</font>, with_ipcore<font color="#909090">=False</font>, **kwargs)</dt><dd><tt>Create a base <a href="#router">router</a> object and add it to NoC model.<br> |
<br> |
Arguments<br> |
* name: optional name for this <a href="#router">router</a>. By default has the form of <br> |
"R_<index>"<br> |
* with_ipcore: If True, add an <a href="#ipcore">ipcore</a> to the created <a href="#router">router</a>.<br> |
* kwargs: optional parameters to put as object attributes<br> |
<br> |
Return: reference to the created <a href="#router">router</a> object</tt></dd></dl> |
|
<dl><dt><a name="noc-add_router_from_object"><strong>add_router_from_object</strong></a>(self, router_ref)</dt><dd><tt>Add an existing <a href="#router">router</a> object to NoC model.<br> |
<br> |
Use this function to add an object based on a derived class of <br> |
base <a href="#router">router</a> defined in this module.<br> |
<br> |
Arguments<br> |
* router_ref: reference to the <a href="#router">router</a> object<br> |
<br> |
Return: the same reference passed in router_ref<br> |
<br> |
Notes: <br> |
* This function will change router_ref.index and router_ref.graph_ref <br> |
attributes when inserted in the NoC model.</tt></dd></dl> |
|
<dl><dt><a name="noc-all_list"><strong>all_list</strong></a>(self)</dt></dl> |
|
<dl><dt><a name="noc-channel_list"><strong>channel_list</strong></a>(self)</dt></dl> |
|
<dl><dt><a name="noc-del_channel"><strong>del_channel</strong></a>(self, channel_ref)</dt><dd><tt>Remove channel_ref from the NoC model<br> |
<br> |
TODO: not implemented</tt></dd></dl> |
|
<dl><dt><a name="noc-del_ipcore"><strong>del_ipcore</strong></a>(self, ipcore_ref)</dt><dd><tt>Remove ipcore_ref from the NoC model<br> |
<br> |
TODO: not implemented</tt></dd></dl> |
|
<dl><dt><a name="noc-del_router"><strong>del_router</strong></a>(self, router_ref)</dt><dd><tt>Remove router_ref from the NoC model<br> |
<br> |
TODO: not implemented</tt></dd></dl> |
|
<dl><dt><a name="noc-get_router_by_address"><strong>get_router_by_address</strong></a>(self, address)</dt><dd><tt># query functions</tt></dd></dl> |
|
<dl><dt><a name="noc-ipcore_list"><strong>ipcore_list</strong></a>(self)</dt></dl> |
|
<dl><dt><a name="noc-router_list"><strong>router_list</strong></a>(self)</dt><dd><tt># list generation functions</tt></dd></dl> |
|
<hr> |
Methods inherited from <a href="networkx.classes.graph.html#Graph">networkx.classes.graph.Graph</a>:<br> |
<dl><dt><a name="noc-__contains__"><strong>__contains__</strong></a>(self, n)</dt><dd><tt>Return True if n is a node, False otherwise. Use the expression<br> |
'n in G'.<br> |
<br> |
Examples<br> |
--------<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> |
>>> print 1 in G<br> |
True</tt></dd></dl> |
|
<dl><dt><a name="noc-__getitem__"><strong>__getitem__</strong></a>(self, n)</dt><dd><tt>Return a <a href="__builtin__.html#dict">dict</a> of neighbors of node n. Use the expression 'G[n]'.<br> |
<br> |
Parameters<br> |
----------<br> |
n : node<br> |
A node in the graph.<br> |
<br> |
Returns<br> |
-------<br> |
adj_dict : dictionary<br> |
The adjacency dictionary for nodes connected to n.<br> |
<br> |
Notes<br> |
-----<br> |
G[n] is similar to G.<a href="#noc-neighbors">neighbors</a>(n) but the internal data dictionary<br> |
is returned instead of a list.<br> |
<br> |
Assigning G[n] will corrupt the internal graph data structure.<br> |
Use G[n] for reading data only.<br> |
<br> |
Examples<br> |
--------<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> |
>>> print G[0]<br> |
{1: {}}</tt></dd></dl> |
|
<dl><dt><a name="noc-__iter__"><strong>__iter__</strong></a>(self)</dt><dd><tt>Iterate over the nodes. Use the expression 'for n in G'.<br> |
<br> |
Returns<br> |
-------<br> |
niter : iterator<br> |
An iterator over all nodes in the graph.<br> |
<br> |
Examples<br> |
--------<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> |
>>> for n in G:<br> |
... print n,<br> |
0 1 2 3</tt></dd></dl> |
|
<dl><dt><a name="noc-__len__"><strong>__len__</strong></a>(self)</dt><dd><tt>Return the number of nodes. Use the expression 'len(G)'.<br> |
<br> |
Returns<br> |
-------<br> |
nnodes : int<br> |
The number of nodes in the graph.<br> |
<br> |
Examples<br> |
--------<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> |
>>> print len(G)<br> |
4</tt></dd></dl> |
|
<dl><dt><a name="noc-__str__"><strong>__str__</strong></a>(self)</dt><dd><tt>Return the graph name.<br> |
<br> |
Returns<br> |
-------<br> |
name : string<br> |
The name of the graph.<br> |
<br> |
Examples<br> |
--------<br> |
>>> G = nx.path_graph(4) <br> |
>>> print G<br> |
path_graph(4)</tt></dd></dl> |
|
<dl><dt><a name="noc-add_cycle"><strong>add_cycle</strong></a>(self, nlist, **attr)</dt><dd><tt>Add a cycle.<br> |
<br> |
Parameters<br> |
----------<br> |
nlist : list <br> |
A list of nodes. A cycle will be constructed from<br> |
the nodes (in order) and added to the graph.<br> |
attr : keyword arguments, optional (default= no attributes)<br> |
Attributes to add to every edge in cycle.<br> |
<br> |
See Also<br> |
--------<br> |
add_path, add_star<br> |
<br> |
Examples<br> |
--------<br> |
>>> G=nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_cycle">add_cycle</a>([0,1,2,3])<br> |
>>> G.<a href="#noc-add_cycle">add_cycle</a>([10,11,12],weight=7)</tt></dd></dl> |
|
<dl><dt><a name="noc-add_edge"><strong>add_edge</strong></a>(self, u, v, attr_dict<font color="#909090">=None</font>, **attr)</dt><dd><tt>Add an edge between u and v.<br> |
<br> |
The nodes u and v will be automatically added if they are <br> |
not already in the graph. <br> |
<br> |
Edge attributes can be specified with keywords or by providing<br> |
a dictionary with key/value pairs. See examples below.<br> |
<br> |
Parameters<br> |
----------<br> |
u,v : nodes<br> |
Nodes can be, for example, strings or numbers. <br> |
Nodes must be hashable (and not None) Python objects.<br> |
attr_dict : dictionary, optional (default= no attributes)<br> |
Dictionary of edge attributes. Key/value pairs will<br> |
update existing data associated with the edge.<br> |
attr : keyword arguments, optional<br> |
Edge data (or labels or objects) can be assigned using<br> |
keyword arguments. <br> |
<br> |
See Also<br> |
--------<br> |
add_edges_from : add a collection of edges<br> |
<br> |
Notes <br> |
-----<br> |
Adding an edge that already exists updates the edge data.<br> |
<br> |
NetworkX algorithms designed for weighted graphs use as<br> |
the edge weight a numerical value assigned to the keyword<br> |
'weight'.<br> |
<br> |
Examples<br> |
--------<br> |
The following all add the edge e=(1,2) to graph G:<br> |
<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> e = (1,2)<br> |
>>> G.<a href="#noc-add_edge">add_edge</a>(1, 2) # explicit two-node form<br> |
>>> G.<a href="#noc-add_edge">add_edge</a>(*e) # single edge as tuple of two nodes<br> |
>>> G.<a href="#noc-add_edges_from">add_edges_from</a>( [(1,2)] ) # add edges from iterable container<br> |
<br> |
Associate data to edges using keywords:<br> |
<br> |
>>> G.<a href="#noc-add_edge">add_edge</a>(1, 2, weight=3)<br> |
>>> G.<a href="#noc-add_edge">add_edge</a>(1, 3, weight=7, capacity=15, length=342.7)</tt></dd></dl> |
|
<dl><dt><a name="noc-add_edges_from"><strong>add_edges_from</strong></a>(self, ebunch, attr_dict<font color="#909090">=None</font>, **attr)</dt><dd><tt>Add all the edges in ebunch.<br> |
<br> |
Parameters<br> |
----------<br> |
ebunch : container of edges<br> |
Each edge given in the container will be added to the<br> |
graph. The edges must be given as as 2-tuples (u,v) or<br> |
3-tuples (u,v,d) where d is a dictionary containing edge<br> |
data.<br> |
attr_dict : dictionary, optional (default= no attributes)<br> |
Dictionary of edge attributes. Key/value pairs will<br> |
update existing data associated with each edge.<br> |
attr : keyword arguments, optional<br> |
Edge data (or labels or objects) can be assigned using<br> |
keyword arguments. <br> |
<br> |
<br> |
See Also<br> |
--------<br> |
add_edge : add a single edge<br> |
add_weighted_edges_from : convenient way to add weighted edges<br> |
<br> |
Notes<br> |
-----<br> |
Adding the same edge twice has no effect but any edge data<br> |
will be updated when each duplicate edge is added.<br> |
<br> |
Examples<br> |
--------<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_edges_from">add_edges_from</a>([(0,1),(1,2)]) # using a list of edge tuples<br> |
>>> e = zip(range(0,3),range(1,4))<br> |
>>> G.<a href="#noc-add_edges_from">add_edges_from</a>(e) # Add the path graph 0-1-2-3<br> |
<br> |
Associate data to edges<br> |
<br> |
>>> G.<a href="#noc-add_edges_from">add_edges_from</a>([(1,2),(2,3)], weight=3)<br> |
>>> G.<a href="#noc-add_edges_from">add_edges_from</a>([(3,4),(1,4)], label='WN2898')</tt></dd></dl> |
|
<dl><dt><a name="noc-add_node"><strong>add_node</strong></a>(self, n, attr_dict<font color="#909090">=None</font>, **attr)</dt><dd><tt>Add a single node n and update node attributes.<br> |
<br> |
Parameters<br> |
----------<br> |
n : node<br> |
A node can be any hashable Python object except None.<br> |
attr_dict : dictionary, optional (default= no attributes)<br> |
Dictionary of node attributes. Key/value pairs will<br> |
update existing data associated with the node.<br> |
attr : keyword arguments, optional<br> |
Set or change attributes using key=value.<br> |
<br> |
See Also<br> |
--------<br> |
add_nodes_from<br> |
<br> |
Examples<br> |
--------<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_node">add_node</a>(1)<br> |
>>> G.<a href="#noc-add_node">add_node</a>('Hello')<br> |
>>> K3 = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>([(0,1),(1,2),(2,0)])<br> |
>>> G.<a href="#noc-add_node">add_node</a>(K3)<br> |
>>> G.<a href="#noc-number_of_nodes">number_of_nodes</a>()<br> |
3<br> |
<br> |
Use keywords set/change node attributes:<br> |
<br> |
>>> G.<a href="#noc-add_node">add_node</a>(1,size=10)<br> |
>>> G.<a href="#noc-add_node">add_node</a>(3,weight=0.4,UTM=('13S',382871,3972649))<br> |
<br> |
Notes<br> |
-----<br> |
A hashable object is one that can be used as a key in a Python<br> |
dictionary. This includes strings, numbers, tuples of strings<br> |
and numbers, etc.<br> |
<br> |
On many platforms hashable items also include mutables such as<br> |
NetworkX Graphs, though one should be careful that the hash<br> |
doesn't change on mutables.</tt></dd></dl> |
|
<dl><dt><a name="noc-add_nodes_from"><strong>add_nodes_from</strong></a>(self, nodes, **attr)</dt><dd><tt>Add multiple nodes.<br> |
<br> |
Parameters<br> |
----------<br> |
nodes : iterable container<br> |
A container of nodes (list, <a href="__builtin__.html#dict">dict</a>, set, etc.). <br> |
OR<br> |
A container of (node, attribute <a href="__builtin__.html#dict">dict</a>) tuples.<br> |
Node attributes are updated using the attribute <a href="__builtin__.html#dict">dict</a>.<br> |
attr : keyword arguments, optional (default= no attributes)<br> |
Update attributes for all nodes in nodes.<br> |
Node attributes specified in nodes as a tuple<br> |
take precedence over attributes specified generally.<br> |
<br> |
See Also<br> |
--------<br> |
add_node<br> |
<br> |
Examples<br> |
--------<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_nodes_from">add_nodes_from</a>('Hello')<br> |
>>> K3 = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>([(0,1),(1,2),(2,0)])<br> |
>>> G.<a href="#noc-add_nodes_from">add_nodes_from</a>(K3)<br> |
>>> sorted(G.<a href="#noc-nodes">nodes</a>())<br> |
[0, 1, 2, 'H', 'e', 'l', 'o']<br> |
<br> |
Use keywords to update specific node attributes for every node.<br> |
<br> |
>>> G.<a href="#noc-add_nodes_from">add_nodes_from</a>([1,2], size=10)<br> |
>>> G.<a href="#noc-add_nodes_from">add_nodes_from</a>([3,4], weight=0.4)<br> |
<br> |
Use (node, attrdict) tuples to update attributes for specific<br> |
nodes.<br> |
<br> |
>>> G.<a href="#noc-add_nodes_from">add_nodes_from</a>([(1,<a href="__builtin__.html#dict">dict</a>(size=11)), (2,{'color':'blue'})])<br> |
>>> G.node[1]['size']<br> |
11<br> |
>>> H = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>()<br> |
>>> H.<a href="#noc-add_nodes_from">add_nodes_from</a>(G.<a href="#noc-nodes">nodes</a>(data=True))<br> |
>>> H.node[1]['size']<br> |
11</tt></dd></dl> |
|
<dl><dt><a name="noc-add_path"><strong>add_path</strong></a>(self, nlist, **attr)</dt><dd><tt>Add a path.<br> |
<br> |
Parameters<br> |
----------<br> |
nlist : list <br> |
A list of nodes. A path will be constructed from<br> |
the nodes (in order) and added to the graph.<br> |
attr : keyword arguments, optional (default= no attributes)<br> |
Attributes to add to every edge in path.<br> |
<br> |
See Also<br> |
--------<br> |
add_star, add_cycle<br> |
<br> |
Examples<br> |
--------<br> |
>>> G=nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> |
>>> G.<a href="#noc-add_path">add_path</a>([10,11,12],weight=7)</tt></dd></dl> |
|
<dl><dt><a name="noc-add_star"><strong>add_star</strong></a>(self, nlist, **attr)</dt><dd><tt>Add a star.<br> |
<br> |
The first node in nlist is the middle of the star. It is connected <br> |
to all other nodes in nlist.<br> |
<br> |
Parameters<br> |
----------<br> |
nlist : list <br> |
A list of nodes. <br> |
attr : keyword arguments, optional (default= no attributes)<br> |
Attributes to add to every edge in star.<br> |
<br> |
See Also<br> |
--------<br> |
add_path, add_cycle<br> |
<br> |
Examples<br> |
--------<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_star">add_star</a>([0,1,2,3])<br> |
>>> G.<a href="#noc-add_star">add_star</a>([10,11,12],weight=2)</tt></dd></dl> |
|
<dl><dt><a name="noc-add_weighted_edges_from"><strong>add_weighted_edges_from</strong></a>(self, ebunch, **attr)</dt><dd><tt>Add all the edges in ebunch as weighted edges with specified<br> |
weights.<br> |
<br> |
Parameters<br> |
----------<br> |
ebunch : container of edges<br> |
Each edge given in the list or container will be added<br> |
to the graph. The edges must be given as 3-tuples (u,v,w)<br> |
where w is a number.<br> |
attr : keyword arguments, optional (default= no attributes)<br> |
Edge attributes to add/update for all edges.<br> |
<br> |
See Also<br> |
--------<br> |
add_edge : add a single edge<br> |
add_edges_from : add multiple edges<br> |
<br> |
Notes<br> |
-----<br> |
Adding the same edge twice has no effect but any edge data<br> |
will be updated when each duplicate edge is added.<br> |
<br> |
Examples<br> |
--------<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_weighted_edges_from">add_weighted_edges_from</a>([(0,1,3.0),(1,2,7.5)])</tt></dd></dl> |
|
<dl><dt><a name="noc-adjacency_iter"><strong>adjacency_iter</strong></a>(self)</dt><dd><tt>Return an iterator of (node, adjacency <a href="__builtin__.html#dict">dict</a>) tuples for all nodes.<br> |
<br> |
This is the fastest way to look at every edge. <br> |
For directed graphs, only outgoing adjacencies are included.<br> |
<br> |
Returns<br> |
-------<br> |
adj_iter : iterator<br> |
An iterator of (node, adjacency dictionary) for all nodes in<br> |
the graph.<br> |
<br> |
See Also<br> |
--------<br> |
adjacency_list<br> |
<br> |
Examples <br> |
--------<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> |
>>> [(n,nbrdict) for n,nbrdict in G.<a href="#noc-adjacency_iter">adjacency_iter</a>()]<br> |
[(0, {1: {}}), (1, {0: {}, 2: {}}), (2, {1: {}, 3: {}}), (3, {2: {}})]</tt></dd></dl> |
|
<dl><dt><a name="noc-adjacency_list"><strong>adjacency_list</strong></a>(self)</dt><dd><tt>Return an adjacency list representation of the graph.<br> |
<br> |
The output adjacency list is in the order of G.<a href="#noc-nodes">nodes</a>().<br> |
For directed graphs, only outgoing adjacencies are included. <br> |
<br> |
Returns<br> |
-------<br> |
adj_list : lists of lists<br> |
The adjacency structure of the graph as a list of lists.<br> |
<br> |
See Also<br> |
--------<br> |
adjacency_iter<br> |
<br> |
Examples<br> |
--------<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> |
>>> G.<a href="#noc-adjacency_list">adjacency_list</a>() # in order given by G.<a href="#noc-nodes">nodes</a>()<br> |
[[1], [0, 2], [1, 3], [2]]</tt></dd></dl> |
|
<dl><dt><a name="noc-clear"><strong>clear</strong></a>(self)</dt><dd><tt>Remove all nodes and edges from the graph.<br> |
<br> |
This also removes the name, and all graph, node, and edge attributes.<br> |
<br> |
Examples<br> |
--------<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> |
>>> G.<a href="#noc-clear">clear</a>()<br> |
>>> G.<a href="#noc-nodes">nodes</a>()<br> |
[]<br> |
>>> G.<a href="#noc-edges">edges</a>()<br> |
[]</tt></dd></dl> |
|
<dl><dt><a name="noc-copy"><strong>copy</strong></a>(self)</dt><dd><tt>Return a copy of the graph.<br> |
<br> |
Returns<br> |
-------<br> |
G : <a href="networkx.classes.graph.html#Graph">Graph</a><br> |
A copy of the graph. <br> |
<br> |
See Also<br> |
--------<br> |
to_directed: return a directed copy of the graph.<br> |
<br> |
Notes<br> |
-----<br> |
This makes a complete copy of the graph including all of the <br> |
node or edge attributes. <br> |
<br> |
Examples<br> |
--------<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> |
>>> H = G.<a href="#noc-copy">copy</a>()</tt></dd></dl> |
|
<dl><dt><a name="noc-degree"><strong>degree</strong></a>(self, nbunch<font color="#909090">=None</font>, weighted<font color="#909090">=False</font>)</dt><dd><tt>Return the degree of a node or nodes.<br> |
<br> |
The node degree is the number of edges adjacent to that node. <br> |
<br> |
Parameters<br> |
----------<br> |
nbunch : iterable container, optional (default=all nodes)<br> |
A container of nodes. The container will be iterated<br> |
through once. <br> |
weighted : bool, optional (default=False)<br> |
If True return the sum of edge weights adjacent to the node. <br> |
<br> |
Returns<br> |
-------<br> |
nd : dictionary, or number<br> |
A dictionary with nodes as keys and degree as values or<br> |
a number if a single node is specified.<br> |
<br> |
Examples<br> |
--------<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> |
>>> G.<a href="#noc-degree">degree</a>(0)<br> |
1<br> |
>>> G.<a href="#noc-degree">degree</a>([0,1])<br> |
{0: 1, 1: 2}<br> |
>>> G.<a href="#noc-degree">degree</a>([0,1]).values()<br> |
[1, 2]</tt></dd></dl> |
|
<dl><dt><a name="noc-degree_iter"><strong>degree_iter</strong></a>(self, nbunch<font color="#909090">=None</font>, weighted<font color="#909090">=False</font>)</dt><dd><tt>Return an iterator for (node, degree). <br> |
<br> |
The node degree is the number of edges adjacent to the node. <br> |
<br> |
Parameters<br> |
----------<br> |
nbunch : iterable container, optional (default=all nodes)<br> |
A container of nodes. The container will be iterated<br> |
through once. <br> |
weighted : bool, optional (default=False)<br> |
If True return the sum of edge weights adjacent to the node. <br> |
<br> |
Returns<br> |
-------<br> |
nd_iter : an iterator <br> |
The iterator returns two-tuples of (node, degree).<br> |
<br> |
See Also<br> |
--------<br> |
degree<br> |
<br> |
Examples<br> |
--------<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> |
>>> list(G.<a href="#noc-degree_iter">degree_iter</a>(0)) # node 0 with degree 1<br> |
[(0, 1)]<br> |
>>> list(G.<a href="#noc-degree_iter">degree_iter</a>([0,1]))<br> |
[(0, 1), (1, 2)]</tt></dd></dl> |
|
<dl><dt><a name="noc-edges"><strong>edges</strong></a>(self, nbunch<font color="#909090">=None</font>, data<font color="#909090">=False</font>)</dt><dd><tt>Return a list of edges.<br> |
<br> |
Edges are returned as tuples with optional data <br> |
in the order (node, neighbor, data).<br> |
<br> |
Parameters<br> |
----------<br> |
nbunch : iterable container, optional (default= all nodes)<br> |
A container of nodes. The container will be iterated<br> |
through once.<br> |
data : bool, optional (default=False)<br> |
Return two tuples (u,v) (False) or three-tuples (u,v,data) (True).<br> |
<br> |
Returns<br> |
--------<br> |
edge_list: list of edge tuples<br> |
Edges that are adjacent to any node in nbunch, or a list<br> |
of all edges if nbunch is not specified.<br> |
<br> |
See Also<br> |
--------<br> |
edges_iter : return an iterator over the edges<br> |
<br> |
Notes<br> |
-----<br> |
Nodes in nbunch that are not in the graph will be (quietly) ignored.<br> |
<br> |
Examples<br> |
--------<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> |
>>> G.<a href="#noc-edges">edges</a>()<br> |
[(0, 1), (1, 2), (2, 3)]<br> |
>>> G.<a href="#noc-edges">edges</a>(data=True) # default edge data is {} (empty dictionary)<br> |
[(0, 1, {}), (1, 2, {}), (2, 3, {})]<br> |
>>> G.<a href="#noc-edges">edges</a>([0,3])<br> |
[(0, 1), (3, 2)]<br> |
>>> G.<a href="#noc-edges">edges</a>(0)<br> |
[(0, 1)]</tt></dd></dl> |
|
<dl><dt><a name="noc-edges_iter"><strong>edges_iter</strong></a>(self, nbunch<font color="#909090">=None</font>, data<font color="#909090">=False</font>)</dt><dd><tt>Return an iterator over the edges.<br> |
<br> |
Edges are returned as tuples with optional data <br> |
in the order (node, neighbor, data).<br> |
<br> |
Parameters<br> |
----------<br> |
nbunch : iterable container, optional (default= all nodes)<br> |
A container of nodes. The container will be iterated<br> |
through once.<br> |
data : bool, optional (default=False)<br> |
If True, return edge attribute <a href="__builtin__.html#dict">dict</a> in 3-tuple (u,v,data).<br> |
<br> |
Returns<br> |
-------<br> |
edge_iter : iterator<br> |
An iterator of (u,v) or (u,v,d) tuples of edges.<br> |
<br> |
See Also<br> |
--------<br> |
edges : return a list of edges<br> |
<br> |
Notes<br> |
-----<br> |
Nodes in nbunch that are not in the graph will be (quietly) ignored.<br> |
<br> |
Examples<br> |
--------<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or MultiGraph, etc<br> |
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> |
>>> [e for e in G.<a href="#noc-edges_iter">edges_iter</a>()]<br> |
[(0, 1), (1, 2), (2, 3)]<br> |
>>> list(G.<a href="#noc-edges_iter">edges_iter</a>(data=True)) # default data is {} (empty <a href="__builtin__.html#dict">dict</a>)<br> |
[(0, 1, {}), (1, 2, {}), (2, 3, {})]<br> |
>>> list(G.<a href="#noc-edges_iter">edges_iter</a>([0,3]))<br> |
[(0, 1), (3, 2)]<br> |
>>> list(G.<a href="#noc-edges_iter">edges_iter</a>(0))<br> |
[(0, 1)]</tt></dd></dl> |
|
<dl><dt><a name="noc-get_edge_data"><strong>get_edge_data</strong></a>(self, u, v, default<font color="#909090">=None</font>)</dt><dd><tt>Return the attribute dictionary associated with edge (u,v).<br> |
<br> |
Parameters<br> |
----------<br> |
u,v : nodes<br> |
default: any Python object (default=None) <br> |
Value to return if the edge (u,v) is not found. <br> |
<br> |
Returns<br> |
-------<br> |
edge_dict : dictionary<br> |
The edge attribute dictionary.<br> |
<br> |
Notes<br> |
-----<br> |
It is faster to use G[u][v].<br> |
<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> |
>>> G[0][1]<br> |
{}<br> |
<br> |
Warning: Assigning G[u][v] corrupts the graph data structure.<br> |
But it is safe to assign attributes to that dictionary,<br> |
<br> |
>>> G[0][1]['weight'] = 7<br> |
>>> G[0][1]['weight']<br> |
7<br> |
>>> G[1][0]['weight']<br> |
7<br> |
<br> |
Examples<br> |
--------<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> |
>>> G.<a href="#noc-get_edge_data">get_edge_data</a>(0,1) # default edge data is {}<br> |
{}<br> |
>>> e = (0,1)<br> |
>>> G.<a href="#noc-get_edge_data">get_edge_data</a>(*e) # tuple form<br> |
{}<br> |
>>> G.<a href="#noc-get_edge_data">get_edge_data</a>('a','b',default=0) # edge not in graph, return 0<br> |
0</tt></dd></dl> |
|
<dl><dt><a name="noc-has_edge"><strong>has_edge</strong></a>(self, u, v)</dt><dd><tt>Return True if the edge (u,v) is in the graph.<br> |
<br> |
Parameters<br> |
----------<br> |
u,v : nodes<br> |
Nodes can be, for example, strings or numbers. <br> |
Nodes must be hashable (and not None) Python objects.<br> |
<br> |
Returns<br> |
-------<br> |
edge_ind : bool<br> |
True if edge is in the graph, False otherwise.<br> |
<br> |
Examples<br> |
--------<br> |
Can be called either using two nodes u,v or edge tuple (u,v)<br> |
<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> |
>>> G.<a href="#noc-has_edge">has_edge</a>(0,1) # using two nodes<br> |
True<br> |
>>> e = (0,1)<br> |
>>> G.<a href="#noc-has_edge">has_edge</a>(*e) # e is a 2-tuple (u,v)<br> |
True<br> |
>>> e = (0,1,{'weight':7})<br> |
>>> G.<a href="#noc-has_edge">has_edge</a>(*e[:2]) # e is a 3-tuple (u,v,data_dictionary)<br> |
True<br> |
<br> |
The following syntax are all equivalent: <br> |
<br> |
>>> G.<a href="#noc-has_edge">has_edge</a>(0,1)<br> |
True<br> |
>>> 1 in G[0] # though this gives KeyError if 0 not in G<br> |
True</tt></dd></dl> |
|
<dl><dt><a name="noc-has_node"><strong>has_node</strong></a>(self, n)</dt><dd><tt>Return True if the graph contains the node n.<br> |
<br> |
Parameters<br> |
----------<br> |
n : node<br> |
<br> |
Examples<br> |
--------<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2])<br> |
>>> print G.<a href="#noc-has_node">has_node</a>(0)<br> |
True<br> |
<br> |
It is more readable and simpler to use<br> |
<br> |
>>> 0 in G<br> |
True</tt></dd></dl> |
|
<dl><dt><a name="noc-is_directed"><strong>is_directed</strong></a>(self)</dt><dd><tt>Return True if graph is directed, False otherwise.</tt></dd></dl> |
|
<dl><dt><a name="noc-is_multigraph"><strong>is_multigraph</strong></a>(self)</dt><dd><tt>Return True if graph is a multigraph, False otherwise.</tt></dd></dl> |
|
<dl><dt><a name="noc-nbunch_iter"><strong>nbunch_iter</strong></a>(self, nbunch<font color="#909090">=None</font>)</dt><dd><tt>Return an iterator of nodes contained in nbunch that are <br> |
also in the graph.<br> |
<br> |
The nodes in nbunch are checked for membership in the graph<br> |
and if not are silently ignored.<br> |
<br> |
Parameters<br> |
----------<br> |
nbunch : iterable container, optional (default=all nodes)<br> |
A container of nodes. The container will be iterated<br> |
through once. <br> |
<br> |
Returns<br> |
-------<br> |
niter : iterator<br> |
An iterator over nodes in nbunch that are also in the graph.<br> |
If nbunch is None, iterate over all nodes in the graph.<br> |
<br> |
Raises<br> |
------<br> |
NetworkXError<br> |
If nbunch is not a node or or sequence of nodes.<br> |
If a node in nbunch is not hashable.<br> |
<br> |
See Also<br> |
--------<br> |
<a href="networkx.classes.graph.html#Graph">Graph</a>.__iter__<br> |
<br> |
Notes <br> |
-----<br> |
When nbunch is an iterator, the returned iterator yields values <br> |
directly from nbunch, becoming exhausted when nbunch is exhausted.<br> |
<br> |
To test whether nbunch is a single node, one can use <br> |
"if nbunch in self:", even after processing with this routine.<br> |
<br> |
If nbunch is not a node or a (possibly empty) sequence/iterator<br> |
or None, a NetworkXError is raised. Also, if any object in<br> |
nbunch is not hashable, a NetworkXError is raised.</tt></dd></dl> |
|
<dl><dt><a name="noc-neighbors"><strong>neighbors</strong></a>(self, n)</dt><dd><tt>Return a list of the nodes connected to the node n.<br> |
<br> |
Parameters<br> |
----------<br> |
n : node<br> |
A node in the graph<br> |
<br> |
Returns<br> |
-------<br> |
nlist : list<br> |
A list of nodes that are adjacent to n.<br> |
<br> |
Raises<br> |
------<br> |
NetworkXError<br> |
If the node n is not in the graph. <br> |
<br> |
Notes<br> |
-----<br> |
It is usually more convenient (and faster) to access the<br> |
adjacency dictionary as G[n]:<br> |
<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_edge">add_edge</a>('a','b',weight=7)<br> |
>>> G['a']<br> |
{'b': {'weight': 7}}<br> |
<br> |
Examples<br> |
--------<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> |
>>> G.<a href="#noc-neighbors">neighbors</a>(0)<br> |
[1]</tt></dd></dl> |
|
<dl><dt><a name="noc-neighbors_iter"><strong>neighbors_iter</strong></a>(self, n)</dt><dd><tt>Return an iterator over all neighbors of node n.<br> |
<br> |
Examples<br> |
--------<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> |
>>> print [n for n in G.<a href="#noc-neighbors_iter">neighbors_iter</a>(0)]<br> |
[1]<br> |
<br> |
Notes<br> |
-----<br> |
It is faster to use the idiom "in G[0]", e.g.<br> |
>>> for n in G[0]:<br> |
... print n<br> |
1</tt></dd></dl> |
|
<dl><dt><a name="noc-nodes"><strong>nodes</strong></a>(self, data<font color="#909090">=False</font>)</dt><dd><tt>Return a list of the nodes in the graph.<br> |
<br> |
Parameters<br> |
----------<br> |
data : boolean, optional (default=False) <br> |
If False return a list of nodes. If True return a<br> |
two-tuple of node and node data dictionary<br> |
<br> |
Returns<br> |
-------<br> |
nlist : list<br> |
A list of nodes. If data=True a list of two-tuples containing<br> |
(node, node data dictionary). <br> |
<br> |
Examples<br> |
--------<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2])<br> |
>>> print G.<a href="#noc-nodes">nodes</a>()<br> |
[0, 1, 2]<br> |
>>> G.<a href="#noc-add_node">add_node</a>(1, time='5pm')<br> |
>>> print G.<a href="#noc-nodes">nodes</a>(data=True)<br> |
[(0, {}), (1, {'time': '5pm'}), (2, {})]</tt></dd></dl> |
|
<dl><dt><a name="noc-nodes_iter"><strong>nodes_iter</strong></a>(self, data<font color="#909090">=False</font>)</dt><dd><tt>Return an iterator over the nodes.<br> |
<br> |
Parameters<br> |
----------<br> |
data : boolean, optional (default=False)<br> |
If False the iterator returns nodes. If True<br> |
return a two-tuple of node and node data dictionary<br> |
<br> |
Returns<br> |
-------<br> |
niter : iterator<br> |
An iterator over nodes. If data=True the iterator gives <br> |
two-tuples containing (node, node data, dictionary) <br> |
<br> |
Notes<br> |
-----<br> |
If the node data is not required it is simpler and equivalent <br> |
to use the expression 'for n in G'.<br> |
<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2])<br> |
>>> for n in G:<br> |
... print n,<br> |
0 1 2<br> |
<br> |
<br> |
Examples<br> |
--------<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2])<br> |
>>> for n in G.<a href="#noc-nodes_iter">nodes_iter</a>():<br> |
... print n,<br> |
0 1 2<br> |
>>> for n,d in G.<a href="#noc-nodes_iter">nodes_iter</a>(data=True):<br> |
... print d,<br> |
{} {} {}</tt></dd></dl> |
|
<dl><dt><a name="noc-nodes_with_selfloops"><strong>nodes_with_selfloops</strong></a>(self)</dt><dd><tt>Return a list of nodes with self loops.<br> |
<br> |
A node with a self loop has an edge with both ends adjacent<br> |
to that node.<br> |
<br> |
Returns<br> |
-------<br> |
nodelist : list<br> |
A list of nodes with self loops.<br> |
<br> |
See Also<br> |
--------<br> |
selfloop_edges, number_of_selfloops<br> |
<br> |
Examples<br> |
--------<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_edge">add_edge</a>(1,1)<br> |
>>> G.<a href="#noc-add_edge">add_edge</a>(1,2)<br> |
>>> G.<a href="#noc-nodes_with_selfloops">nodes_with_selfloops</a>()<br> |
[1]</tt></dd></dl> |
|
<dl><dt><a name="noc-number_of_edges"><strong>number_of_edges</strong></a>(self, u<font color="#909090">=None</font>, v<font color="#909090">=None</font>)</dt><dd><tt>Return the number of edges between two nodes.<br> |
<br> |
Parameters<br> |
----------<br> |
u,v : nodes, optional (default=all edges)<br> |
If u and v are specified, return the number of edges between <br> |
u and v. Otherwise return the total number of all edges.<br> |
<br> |
Returns<br> |
-------<br> |
nedges : int<br> |
The number of edges in the graph. If nodes u and v are specified<br> |
return the number of edges between those nodes.<br> |
<br> |
See Also<br> |
--------<br> |
size<br> |
<br> |
Examples<br> |
--------<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> |
>>> G.<a href="#noc-number_of_edges">number_of_edges</a>()<br> |
3<br> |
>>> G.<a href="#noc-number_of_edges">number_of_edges</a>(0,1) <br> |
1<br> |
>>> e = (0,1)<br> |
>>> G.<a href="#noc-number_of_edges">number_of_edges</a>(*e)<br> |
1</tt></dd></dl> |
|
<dl><dt><a name="noc-number_of_nodes"><strong>number_of_nodes</strong></a>(self)</dt><dd><tt>Return the number of nodes in the graph.<br> |
<br> |
Returns<br> |
-------<br> |
nnodes : int<br> |
The number of nodes in the graph.<br> |
<br> |
See Also<br> |
--------<br> |
order, __len__ which are identical <br> |
<br> |
Examples<br> |
--------<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2])<br> |
>>> print len(G)<br> |
3</tt></dd></dl> |
|
<dl><dt><a name="noc-number_of_selfloops"><strong>number_of_selfloops</strong></a>(self)</dt><dd><tt>Return the number of selfloop edges.<br> |
<br> |
A selfloop edge has the same node at both ends.<br> |
<br> |
Returns<br> |
-------<br> |
nloops : int<br> |
The number of selfloops. <br> |
<br> |
See Also<br> |
--------<br> |
selfloop_nodes, selfloop_edges<br> |
<br> |
Examples<br> |
--------<br> |
>>> G=nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_edge">add_edge</a>(1,1)<br> |
>>> G.<a href="#noc-add_edge">add_edge</a>(1,2)<br> |
>>> G.<a href="#noc-number_of_selfloops">number_of_selfloops</a>()<br> |
1</tt></dd></dl> |
|
<dl><dt><a name="noc-order"><strong>order</strong></a>(self)</dt><dd><tt>Return the number of nodes in the graph.<br> |
<br> |
Returns<br> |
-------<br> |
nnodes : int<br> |
The number of nodes in the graph.<br> |
<br> |
See Also<br> |
--------<br> |
number_of_nodes, __len__ which are identical</tt></dd></dl> |
|
<dl><dt><a name="noc-remove_edge"><strong>remove_edge</strong></a>(self, u, v)</dt><dd><tt>Remove the edge between u and v.<br> |
<br> |
Parameters<br> |
----------<br> |
u,v: nodes <br> |
Remove the edge between nodes u and v.<br> |
<br> |
Raises<br> |
------<br> |
NetworkXError<br> |
If there is not an edge between u and v.<br> |
<br> |
See Also<br> |
--------<br> |
remove_edges_from : remove a collection of edges<br> |
<br> |
Examples<br> |
--------<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, etc<br> |
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> |
>>> G.<a href="#noc-remove_edge">remove_edge</a>(0,1)<br> |
>>> e = (1,2)<br> |
>>> G.<a href="#noc-remove_edge">remove_edge</a>(*e) # unpacks e from an edge tuple<br> |
>>> e = (2,3,{'weight':7}) # an edge with attribute data<br> |
>>> G.<a href="#noc-remove_edge">remove_edge</a>(*e[:2]) # select first part of edge tuple</tt></dd></dl> |
|
<dl><dt><a name="noc-remove_edges_from"><strong>remove_edges_from</strong></a>(self, ebunch)</dt><dd><tt>Remove all edges specified in ebunch.<br> |
<br> |
Parameters<br> |
----------<br> |
ebunch: list or container of edge tuples<br> |
Each edge given in the list or container will be removed <br> |
from the graph. The edges can be:<br> |
<br> |
- 2-tuples (u,v) edge between u and v.<br> |
- 3-tuples (u,v,k) where k is ignored.<br> |
<br> |
See Also<br> |
--------<br> |
remove_edge : remove a single edge<br> |
<br> |
Notes<br> |
-----<br> |
Will fail silently if an edge in ebunch is not in the graph.<br> |
<br> |
Examples<br> |
--------<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> |
>>> ebunch=[(1,2),(2,3)]<br> |
>>> G.<a href="#noc-remove_edges_from">remove_edges_from</a>(ebunch)</tt></dd></dl> |
|
<dl><dt><a name="noc-remove_node"><strong>remove_node</strong></a>(self, n)</dt><dd><tt>Remove node n.<br> |
<br> |
Removes the node n and all adjacent edges.<br> |
Attempting to remove a non-existent node will raise an exception.<br> |
<br> |
Parameters<br> |
----------<br> |
n : node<br> |
A node in the graph<br> |
<br> |
Raises<br> |
-------<br> |
NetworkXError<br> |
If n is not in the graph.<br> |
<br> |
See Also<br> |
--------<br> |
remove_nodes_from<br> |
<br> |
Examples<br> |
--------<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2])<br> |
>>> G.<a href="#noc-edges">edges</a>()<br> |
[(0, 1), (1, 2)]<br> |
>>> G.<a href="#noc-remove_node">remove_node</a>(1)<br> |
>>> G.<a href="#noc-edges">edges</a>()<br> |
[]</tt></dd></dl> |
|
<dl><dt><a name="noc-remove_nodes_from"><strong>remove_nodes_from</strong></a>(self, nodes)</dt><dd><tt>Remove multiple nodes.<br> |
<br> |
Parameters<br> |
----------<br> |
nodes : iterable container<br> |
A container of nodes (list, <a href="__builtin__.html#dict">dict</a>, set, etc.). If a node<br> |
in the container is not in the graph it is silently<br> |
ignored.<br> |
<br> |
See Also<br> |
--------<br> |
remove_node<br> |
<br> |
Examples<br> |
--------<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2])<br> |
>>> e = G.<a href="#noc-nodes">nodes</a>()<br> |
>>> e<br> |
[0, 1, 2]<br> |
>>> G.<a href="#noc-remove_nodes_from">remove_nodes_from</a>(e)<br> |
>>> G.<a href="#noc-nodes">nodes</a>()<br> |
[]</tt></dd></dl> |
|
<dl><dt><a name="noc-selfloop_edges"><strong>selfloop_edges</strong></a>(self, data<font color="#909090">=False</font>)</dt><dd><tt>Return a list of selfloop edges.<br> |
<br> |
A selfloop edge has the same node at both ends.<br> |
<br> |
Parameters<br> |
-----------<br> |
data : bool, optional (default=False)<br> |
Return selfloop edges as two tuples (u,v) (data=False)<br> |
or three-tuples (u,v,data) (data=True)<br> |
<br> |
Returns<br> |
-------<br> |
edgelist : list of edge tuples<br> |
A list of all selfloop edges.<br> |
<br> |
See Also<br> |
--------<br> |
selfloop_nodes, number_of_selfloops<br> |
<br> |
Examples<br> |
--------<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_edge">add_edge</a>(1,1)<br> |
>>> G.<a href="#noc-add_edge">add_edge</a>(1,2)<br> |
>>> G.<a href="#noc-selfloop_edges">selfloop_edges</a>()<br> |
[(1, 1)]<br> |
>>> G.<a href="#noc-selfloop_edges">selfloop_edges</a>(data=True)<br> |
[(1, 1, {})]</tt></dd></dl> |
|
<dl><dt><a name="noc-size"><strong>size</strong></a>(self, weighted<font color="#909090">=False</font>)</dt><dd><tt>Return the number of edges.<br> |
<br> |
Parameters<br> |
----------<br> |
weighted : boolean, optional (default=False)<br> |
If True return the sum of the edge weights.<br> |
<br> |
Returns<br> |
-------<br> |
nedges : int<br> |
The number of edges in the graph.<br> |
<br> |
See Also<br> |
--------<br> |
number_of_edges<br> |
<br> |
Examples<br> |
--------<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> |
>>> G.<a href="#noc-size">size</a>()<br> |
3<br> |
<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_edge">add_edge</a>('a','b',weight=2)<br> |
>>> G.<a href="#noc-add_edge">add_edge</a>('b','c',weight=4)<br> |
>>> G.<a href="#noc-size">size</a>()<br> |
2<br> |
>>> G.<a href="#noc-size">size</a>(weighted=True)<br> |
6</tt></dd></dl> |
|
<dl><dt><a name="noc-subgraph"><strong>subgraph</strong></a>(self, nbunch)</dt><dd><tt>Return the subgraph induced on nodes in nbunch.<br> |
<br> |
The induced subgraph of the graph contains the nodes in nbunch <br> |
and the edges between those nodes. <br> |
<br> |
Parameters<br> |
----------<br> |
nbunch : list, iterable<br> |
A container of nodes which will be iterated through once. <br> |
<br> |
Returns<br> |
-------<br> |
G : <a href="networkx.classes.graph.html#Graph">Graph</a><br> |
A subgraph of the graph with the same edge attributes. <br> |
<br> |
Notes<br> |
-----<br> |
The graph, edge or node attributes just point to the original graph.<br> |
So changes to the node or edge structure will not be reflected in<br> |
the original graph while changes to the attributes will.<br> |
<br> |
To create a subgraph with its own copy of the edge/node attributes use:<br> |
nx.<a href="networkx.classes.graph.html#Graph">Graph</a>(G.<a href="#noc-subgraph">subgraph</a>(nbunch))<br> |
<br> |
If edge attributes are containers, a deep copy can be obtained using:<br> |
G.<a href="#noc-subgraph">subgraph</a>(nbunch).<a href="#noc-copy">copy</a>()<br> |
<br> |
For an in-place reduction of a graph to a subgraph you can remove nodes:<br> |
G.<a href="#noc-remove_nodes_from">remove_nodes_from</a>([ n in G if n not in set(nbunch)]) <br> |
<br> |
Examples<br> |
--------<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> |
>>> H = G.<a href="#noc-subgraph">subgraph</a>([0,1,2])<br> |
>>> print H.<a href="#noc-edges">edges</a>()<br> |
[(0, 1), (1, 2)]</tt></dd></dl> |
|
<dl><dt><a name="noc-to_directed"><strong>to_directed</strong></a>(self)</dt><dd><tt>Return a directed representation of the graph.<br> |
<br> |
Returns<br> |
-------<br> |
G : DiGraph<br> |
A directed graph with the same name, same nodes, and with<br> |
each edge (u,v,data) replaced by two directed edges<br> |
(u,v,data) and (v,u,data).<br> |
<br> |
Notes<br> |
-----<br> |
This returns a "deepcopy" of the edge, node, and <br> |
graph attributes which attempts to completely copy<br> |
all of the data and references.<br> |
<br> |
This is in contrast to the similar D=DiGraph(G) which returns a <br> |
shallow copy of the data. <br> |
<br> |
See the Python copy module for more information on shallow<br> |
and deep copies, <a href="http://docs.python.org/library/copy.html">http://docs.python.org/library/copy.html</a>.<br> |
<br> |
Examples<br> |
--------<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or MultiGraph, etc<br> |
>>> G.<a href="#noc-add_path">add_path</a>([0,1])<br> |
>>> H = G.<a href="#noc-to_directed">to_directed</a>()<br> |
>>> H.<a href="#noc-edges">edges</a>()<br> |
[(0, 1), (1, 0)]<br> |
<br> |
If already directed, return a (deep) copy<br> |
<br> |
>>> G = nx.DiGraph() # or MultiDiGraph, etc<br> |
>>> G.<a href="#noc-add_path">add_path</a>([0,1])<br> |
>>> H = G.<a href="#noc-to_directed">to_directed</a>()<br> |
>>> H.<a href="#noc-edges">edges</a>()<br> |
[(0, 1)]</tt></dd></dl> |
|
<dl><dt><a name="noc-to_undirected"><strong>to_undirected</strong></a>(self)</dt><dd><tt>Return an undirected copy of the graph. <br> |
<br> |
Returns<br> |
-------<br> |
G : <a href="networkx.classes.graph.html#Graph">Graph</a>/MultiGraph<br> |
A deepcopy of the graph.<br> |
<br> |
See Also<br> |
--------<br> |
copy, add_edge, add_edges_from<br> |
<br> |
Notes<br> |
-----<br> |
This returns a "deepcopy" of the edge, node, and <br> |
graph attributes which attempts to completely copy<br> |
all of the data and references.<br> |
<br> |
This is in contrast to the similar G=DiGraph(D) which returns a <br> |
shallow copy of the data. <br> |
<br> |
See the Python copy module for more information on shallow<br> |
and deep copies, <a href="http://docs.python.org/library/copy.html">http://docs.python.org/library/copy.html</a>.<br> |
<br> |
Examples<br> |
--------<br> |
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or MultiGraph, etc<br> |
>>> G.<a href="#noc-add_path">add_path</a>([0,1])<br> |
>>> H = G.<a href="#noc-to_directed">to_directed</a>()<br> |
>>> H.<a href="#noc-edges">edges</a>()<br> |
[(0, 1), (1, 0)]<br> |
>>> G2 = H.<a href="#noc-to_undirected">to_undirected</a>()<br> |
>>> G2.<a href="#noc-edges">edges</a>()<br> |
[(0, 1)]</tt></dd></dl> |
|
<hr> |
Data descriptors inherited from <a href="networkx.classes.graph.html#Graph">networkx.classes.graph.Graph</a>:<br> |
<dl><dt><strong>__dict__</strong></dt> |
<dd><tt>dictionary for instance variables (if defined)</tt></dd> |
</dl> |
<dl><dt><strong>__weakref__</strong></dt> |
<dd><tt>list of weak references to the object (if defined)</tt></dd> |
</dl> |
</td></tr></table> <p> |
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
<tr bgcolor="#ffc8d8"> |
<td colspan=3 valign=bottom> <br> |
<font color="#000000" face="helvetica, arial"><a name="nocobject">class <strong>nocobject</strong></a></font></td></tr> |
|
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
<td colspan=2><tt>NoC base object<br> |
<br> |
This base class is used to implement common methods for NoC objects.<br> |
Don't use directly.<br> </tt></td></tr> |
<tr><td> </td> |
<td width="100%">Methods defined here:<br> |
<dl><dt><a name="nocobject-get_protocol_ref"><strong>get_protocol_ref</strong></a>(self)</dt><dd><tt>Get <a href="#protocol">protocol</a> object for this instance</tt></dd></dl> |
|
</td></tr></table> <p> |
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
<tr bgcolor="#ffc8d8"> |
<td colspan=3 valign=bottom> <br> |
<font color="#000000" face="helvetica, arial"><a name="packet">class <strong>packet</strong></a>(<a href="__builtin__.html#dict">__builtin__.dict</a>)</font></td></tr> |
|
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
<td colspan=2><tt>Packet base object<br> |
<br> |
This object represents a <a href="#packet">packet</a> data, related to a <a href="#protocol">protocol</a> object. It <br> |
behaves exactly like a Python dictionary, but adds methods to simplify <br> |
<a href="#packet">packet</a> transformations. <br> |
<br> |
Relations with other objects:<br> |
* It should be generated by a <a href="#protocol">protocol</a> object (and will have a reference <br> |
in self.<strong>protocol_ref</strong>)<br> |
<br> |
Attributes:<br> |
* protocol_ref: <a href="#protocol">protocol</a> object that created this object.<br> </tt></td></tr> |
<tr><td> </td> |
<td width="100%"><dl><dt>Method resolution order:</dt> |
<dd><a href="nocmodel.noc_base.html#packet">packet</a></dd> |
<dd><a href="__builtin__.html#dict">__builtin__.dict</a></dd> |
<dd><a href="__builtin__.html#object">__builtin__.object</a></dd> |
</dl> |
<hr> |
Methods defined here:<br> |
<dl><dt><a name="packet-__init__"><strong>__init__</strong></a>(self, *args, **kwargs)</dt><dd><tt># the constructor</tt></dd></dl> |
|
<hr> |
Data descriptors defined here:<br> |
<dl><dt><strong>__dict__</strong></dt> |
<dd><tt>dictionary for instance variables (if defined)</tt></dd> |
</dl> |
<dl><dt><strong>__weakref__</strong></dt> |
<dd><tt>list of weak references to the object (if defined)</tt></dd> |
</dl> |
<hr> |
Methods inherited from <a href="__builtin__.html#dict">__builtin__.dict</a>:<br> |
<dl><dt><a name="packet-__cmp__"><strong>__cmp__</strong></a>(...)</dt><dd><tt>x.<a href="#packet-__cmp__">__cmp__</a>(y) <==> cmp(x,y)</tt></dd></dl> |
|
<dl><dt><a name="packet-__contains__"><strong>__contains__</strong></a>(...)</dt><dd><tt>D.<a href="#packet-__contains__">__contains__</a>(k) -> True if D has a key k, else False</tt></dd></dl> |
|
<dl><dt><a name="packet-__delitem__"><strong>__delitem__</strong></a>(...)</dt><dd><tt>x.<a href="#packet-__delitem__">__delitem__</a>(y) <==> del x[y]</tt></dd></dl> |
|
<dl><dt><a name="packet-__eq__"><strong>__eq__</strong></a>(...)</dt><dd><tt>x.<a href="#packet-__eq__">__eq__</a>(y) <==> x==y</tt></dd></dl> |
|
<dl><dt><a name="packet-__ge__"><strong>__ge__</strong></a>(...)</dt><dd><tt>x.<a href="#packet-__ge__">__ge__</a>(y) <==> x>=y</tt></dd></dl> |
|
<dl><dt><a name="packet-__getattribute__"><strong>__getattribute__</strong></a>(...)</dt><dd><tt>x.<a href="#packet-__getattribute__">__getattribute__</a>('name') <==> x.name</tt></dd></dl> |
|
<dl><dt><a name="packet-__getitem__"><strong>__getitem__</strong></a>(...)</dt><dd><tt>x.<a href="#packet-__getitem__">__getitem__</a>(y) <==> x[y]</tt></dd></dl> |
|
<dl><dt><a name="packet-__gt__"><strong>__gt__</strong></a>(...)</dt><dd><tt>x.<a href="#packet-__gt__">__gt__</a>(y) <==> x>y</tt></dd></dl> |
|
<dl><dt><a name="packet-__iter__"><strong>__iter__</strong></a>(...)</dt><dd><tt>x.<a href="#packet-__iter__">__iter__</a>() <==> iter(x)</tt></dd></dl> |
|
<dl><dt><a name="packet-__le__"><strong>__le__</strong></a>(...)</dt><dd><tt>x.<a href="#packet-__le__">__le__</a>(y) <==> x<=y</tt></dd></dl> |
|
<dl><dt><a name="packet-__len__"><strong>__len__</strong></a>(...)</dt><dd><tt>x.<a href="#packet-__len__">__len__</a>() <==> len(x)</tt></dd></dl> |
|
<dl><dt><a name="packet-__lt__"><strong>__lt__</strong></a>(...)</dt><dd><tt>x.<a href="#packet-__lt__">__lt__</a>(y) <==> x<y</tt></dd></dl> |
|
<dl><dt><a name="packet-__ne__"><strong>__ne__</strong></a>(...)</dt><dd><tt>x.<a href="#packet-__ne__">__ne__</a>(y) <==> x!=y</tt></dd></dl> |
|
<dl><dt><a name="packet-__repr__"><strong>__repr__</strong></a>(...)</dt><dd><tt>x.<a href="#packet-__repr__">__repr__</a>() <==> repr(x)</tt></dd></dl> |
|
<dl><dt><a name="packet-__setitem__"><strong>__setitem__</strong></a>(...)</dt><dd><tt>x.<a href="#packet-__setitem__">__setitem__</a>(i, y) <==> x[i]=y</tt></dd></dl> |
|
<dl><dt><a name="packet-__sizeof__"><strong>__sizeof__</strong></a>(...)</dt><dd><tt>D.<a href="#packet-__sizeof__">__sizeof__</a>() -> size of D in memory, in bytes</tt></dd></dl> |
|
<dl><dt><a name="packet-clear"><strong>clear</strong></a>(...)</dt><dd><tt>D.<a href="#packet-clear">clear</a>() -> None. Remove all items from D.</tt></dd></dl> |
|
<dl><dt><a name="packet-copy"><strong>copy</strong></a>(...)</dt><dd><tt>D.<a href="#packet-copy">copy</a>() -> a shallow copy of D</tt></dd></dl> |
|
<dl><dt><a name="packet-get"><strong>get</strong></a>(...)</dt><dd><tt>D.<a href="#packet-get">get</a>(k[,d]) -> D[k] if k in D, else d. d defaults to None.</tt></dd></dl> |
|
<dl><dt><a name="packet-has_key"><strong>has_key</strong></a>(...)</dt><dd><tt>D.<a href="#packet-has_key">has_key</a>(k) -> True if D has a key k, else False</tt></dd></dl> |
|
<dl><dt><a name="packet-items"><strong>items</strong></a>(...)</dt><dd><tt>D.<a href="#packet-items">items</a>() -> list of D's (key, value) pairs, as 2-tuples</tt></dd></dl> |
|
<dl><dt><a name="packet-iteritems"><strong>iteritems</strong></a>(...)</dt><dd><tt>D.<a href="#packet-iteritems">iteritems</a>() -> an iterator over the (key, value) items of D</tt></dd></dl> |
|
<dl><dt><a name="packet-iterkeys"><strong>iterkeys</strong></a>(...)</dt><dd><tt>D.<a href="#packet-iterkeys">iterkeys</a>() -> an iterator over the keys of D</tt></dd></dl> |
|
<dl><dt><a name="packet-itervalues"><strong>itervalues</strong></a>(...)</dt><dd><tt>D.<a href="#packet-itervalues">itervalues</a>() -> an iterator over the values of D</tt></dd></dl> |
|
<dl><dt><a name="packet-keys"><strong>keys</strong></a>(...)</dt><dd><tt>D.<a href="#packet-keys">keys</a>() -> list of D's keys</tt></dd></dl> |
|
<dl><dt><a name="packet-pop"><strong>pop</strong></a>(...)</dt><dd><tt>D.<a href="#packet-pop">pop</a>(k[,d]) -> v, remove specified key and return the corresponding value.<br> |
If key is not found, d is returned if given, otherwise KeyError is raised</tt></dd></dl> |
|
<dl><dt><a name="packet-popitem"><strong>popitem</strong></a>(...)</dt><dd><tt>D.<a href="#packet-popitem">popitem</a>() -> (k, v), remove and return some (key, value) pair as a<br> |
2-tuple; but raise KeyError if D is empty.</tt></dd></dl> |
|
<dl><dt><a name="packet-setdefault"><strong>setdefault</strong></a>(...)</dt><dd><tt>D.<a href="#packet-setdefault">setdefault</a>(k[,d]) -> D.<a href="#packet-get">get</a>(k,d), also set D[k]=d if k not in D</tt></dd></dl> |
|
<dl><dt><a name="packet-update"><strong>update</strong></a>(...)</dt><dd><tt>D.<a href="#packet-update">update</a>(E, **F) -> None. Update D from <a href="__builtin__.html#dict">dict</a>/iterable E and F.<br> |
If E has a .<a href="#packet-keys">keys</a>() method, does: for k in E: D[k] = E[k]<br> |
If E lacks .<a href="#packet-keys">keys</a>() method, does: for (k, v) in E: D[k] = v<br> |
In either case, this is followed by: for k in F: D[k] = F[k]</tt></dd></dl> |
|
<dl><dt><a name="packet-values"><strong>values</strong></a>(...)</dt><dd><tt>D.<a href="#packet-values">values</a>() -> list of D's values</tt></dd></dl> |
|
<hr> |
Data and other attributes inherited from <a href="__builtin__.html#dict">__builtin__.dict</a>:<br> |
<dl><dt><strong>__hash__</strong> = None</dl> |
|
<dl><dt><strong>__new__</strong> = <built-in method __new__ of type object><dd><tt>T.<a href="#packet-__new__">__new__</a>(S, ...) -> a new object with type S, a subtype of T</tt></dl> |
|
<dl><dt><strong>fromkeys</strong> = <built-in method fromkeys of type object><dd><tt><a href="__builtin__.html#dict">dict</a>.<a href="#packet-fromkeys">fromkeys</a>(S[,v]) -> New <a href="__builtin__.html#dict">dict</a> with keys from S and values equal to v.<br> |
v defaults to None.</tt></dl> |
|
</td></tr></table> <p> |
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
<tr bgcolor="#ffc8d8"> |
<td colspan=3 valign=bottom> <br> |
<font color="#000000" face="helvetica, arial"><a name="protocol">class <strong>protocol</strong></a>(<a href="nocmodel.noc_base.html#nocobject">nocobject</a>)</font></td></tr> |
|
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
<td colspan=2><tt>Protocol base object<br> |
<br> |
This object represents the <a href="#protocol">protocol</a> that the NoC objects use. This <br> |
object has attributes that define the <a href="#protocol">protocol</a> used, mainly it can be<br> |
used to generate, encode, decode or interpret packets on the NoC.<br> |
This base class can be either be inherited or extended by adding <br> |
other attributes.<br> |
<br> |
Relations with other objects:<br> |
* Each object on the NoC (routers, channels and ipcores) may have<br> |
one reference to a <a href="#protocol">protocol</a> object (object.protocol_ref)<br> |
* A NoC model may have a <a href="#protocol">protocol</a> object: in this case, all objects in<br> |
the model will use this <a href="#protocol">protocol</a> (nocmodel.protocol_ref)<br> |
* A <a href="#protocol">protocol</a> object is a generator of <a href="#packet">packet</a> objects<br> |
<br> |
Attributes:<br> |
* name<br> |
<br> |
Notes: <br> |
* Optional arguments "packet_format" and "packet_order" can be<br> |
added at object construction, but will not check its data consistency. <br> |
At the moment, we recommend using <a href="#protocol-update_packet_field">update_packet_field</a>() method to<br> |
fill this data structures.<br> </tt></td></tr> |
<tr><td> </td> |
<td width="100%">Methods defined here:<br> |
<dl><dt><a name="protocol-__init__"><strong>__init__</strong></a>(self, name<font color="#909090">=''</font>, **kwargs)</dt><dd><tt>Constructor<br> |
<br> |
Notes:<br> |
* Optional arguments will be added as object attributes.</tt></dd></dl> |
|
<dl><dt><a name="protocol-get_protocol_ref"><strong>get_protocol_ref</strong></a>(self)</dt></dl> |
|
<dl><dt><a name="protocol-newpacket"><strong>newpacket</strong></a>(self, zerodefault<font color="#909090">=True</font>, *args, **kwargs)</dt><dd><tt>Return a new <a href="#packet">packet</a> with all required fields.<br> |
<br> |
Arguments:<br> |
* zerodefault: If True, all missing fields will be zeroed by default.<br> |
If False, a missing value in arguments will throw an exception.<br> |
* args: Nameless arguments will add field values based on <a href="#packet">packet</a> field<br> |
order.<br> |
* kwargs: Key-based arguments will add specified field values based in <br> |
its keys<br> |
<br> |
Notes: <br> |
* kwargs takes precedence over args: i.e. named arguments can overwrite<br> |
nameless arguments.</tt></dd></dl> |
|
<dl><dt><a name="protocol-register_packet_generator"><strong>register_packet_generator</strong></a>(self, packet_class)</dt><dd><tt>Register a special <a href="#packet">packet</a> generator class.<br> |
<br> |
Must be a derived class of <a href="#packet">packet</a></tt></dd></dl> |
|
<dl><dt><a name="protocol-update_packet_field"><strong>update_packet_field</strong></a>(self, name, type, bitlen, description<font color="#909090">=''</font>)</dt><dd><tt>Add or update a <a href="#packet">packet</a> field.<br> |
<br> |
Arguments<br> |
* name<br> |
* type: string that can be "int", "fixed" or "float"<br> |
* bitlen: bit length of this field<br> |
* description: optional description of this field<br> |
<br> |
Notes: <br> |
* Each new field will be added at the end.</tt></dd></dl> |
|
</td></tr></table> <p> |
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
<tr bgcolor="#ffc8d8"> |
<td colspan=3 valign=bottom> <br> |
<font color="#000000" face="helvetica, arial"><a name="router">class <strong>router</strong></a>(<a href="nocmodel.noc_base.html#nocobject">nocobject</a>)</font></td></tr> |
|
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
<td colspan=2><tt>Router base object<br> |
<br> |
This object represents a <a href="#router">router</a> object and its properties. This base class<br> |
is meant to either be inherited or extended by adding other attributes.<br> |
<br> |
Relations with other objects:<br> |
* It should be related to one NoC model object (self.<strong>graph_ref</strong>)<br> |
* It should be one of the node attributes in the graph model <br> |
(node["router_ref"])<br> |
* It may have one reference to an <a href="#ipcore">ipcore</a> object (self.<strong>ipcore_ref</strong>)<br> |
* It has a port list with relations to other routers through <a href="#channel">channel</a> objects,<br> |
and only one relation to its <a href="#ipcore">ipcore</a> object through one <a href="#channel">channel</a>.<br> |
(self.<strong>ports</strong>). Note that this attribute must be updated after changing <br> |
the NoC model.<br> |
<br> |
Attributes:<br> |
* index: index on a <a href="#noc">noc</a> object. Essential to search for a <a href="#router">router</a> object<br> |
* name<br> |
* ipcore_ref: optional reference to its related <a href="#ipcore">ipcore</a><br> |
* graph_ref: optional reference to its graph model<br> </tt></td></tr> |
<tr><td> </td> |
<td width="100%">Methods defined here:<br> |
<dl><dt><a name="router-__init__"><strong>__init__</strong></a>(self, index, name, **kwargs)</dt></dl> |
|
<dl><dt><a name="router-update_ports_info"><strong>update_ports_info</strong></a>(self)</dt><dd><tt>Update the dictionary "ports": information about <a href="#router">router</a> neighbors,<br> |
the channels that connect them and its references.<br> |
<br> |
Ports dictionary has the following structure:<br> |
* key: address of the neighbor <a href="#router">router</a> that this port connects.<br> |
* value: dictionary with the following keys:<br> |
* "peer" (required): reference to the neighbor <a href="#router">router</a><br> |
* "<a href="#channel">channel</a>" (required): reference to the <a href="#channel">channel</a> that connects this <br> |
<a href="#router">router</a> and its neighbor <a href="#router">router</a>.<br> |
* Optional keys can be added to this dictionary.<br> |
* Also, the special key "local address" holds the port to <br> |
<a href="#router">router</a>'s <a href="#ipcore">ipcore</a>. Its values are:<br> |
* "peer" (required): reference to its <a href="#ipcore">ipcore</a><br> |
* "<a href="#channel">channel</a>" (required): reference to the <a href="#channel">channel</a> that connects this <br> |
<a href="#router">router</a> and its <a href="#ipcore">ipcore</a>.<br> |
* Optional keys can be added to this dictionary with the same <br> |
meaning as other ports.</tt></dd></dl> |
|
<dl><dt><a name="router-update_routes_info"><strong>update_routes_info</strong></a>(self)</dt><dd><tt>Update the dictionary "routes_info": it is a table with information <br> |
about how a package, starting from this <a href="#router">router</a>, can reach another one.<br> |
<br> |
routes_info dictionary has the following structure:<br> |
* keys : the address of all the routers in NoC<br> |
* values : an ordered list of dictionaries with <br> |
* "next" : address of the next <a href="#router">router</a><br> |
* "paths" : list of possible paths for key destination</tt></dd></dl> |
|
<hr> |
Methods inherited from <a href="nocmodel.noc_base.html#nocobject">nocobject</a>:<br> |
<dl><dt><a name="router-get_protocol_ref"><strong>get_protocol_ref</strong></a>(self)</dt><dd><tt>Get <a href="#protocol">protocol</a> object for this instance</tt></dd></dl> |
|
</td></tr></table></td></tr></table><p> |
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
<tr bgcolor="#eeaa77"> |
<td colspan=3 valign=bottom> <br> |
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr> |
|
<tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td> |
<td width="100%"><dl><dt><a name="-all_shortest_paths"><strong>all_shortest_paths</strong></a>(G, a, b)</dt><dd><tt>Return a list of all shortest paths in graph G between nodes a and b<br> |
This is a function not available in NetworkX (checked at 22-02-2011)<br> |
<br> |
Taken from: <br> |
<a href="http://groups.google.com/group/networkx-discuss/browse_thread/thread/55465e6bb9bae12e">http://groups.google.com/group/networkx-discuss/browse_thread/thread/55465e6bb9bae12e</a></tt></dd></dl> |
</td></tr></table> |
</body></html> |
/doc/nocmodel.noc_guilib.html
0,0 → 1,44
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
<html><head><title>Python: module nocmodel.noc_guilib</title> |
</head><body bgcolor="#f0f0f8"> |
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading"> |
<tr bgcolor="#7799ee"> |
<td valign=bottom> <br> |
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="nocmodel.html"><font color="#ffffff">nocmodel</font></a>.noc_guilib</strong></big></big></font></td |
><td align=right valign=bottom |
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/oscard/Documentos/proyectos/nocmodel-0.1/nocmodel/noc_guilib.py">/home/oscard/Documentos/proyectos/nocmodel-0.1/nocmodel/noc_guilib.py</a></font></td></tr></table> |
<p><tt>================<br> |
NoCmodel Graphic utilities<br> |
================<br> |
<br> |
This module declares functions to draw graphical representations of <br> |
NoCmodel objects.</tt></p> |
<p> |
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
<tr bgcolor="#aa55cc"> |
<td colspan=3 valign=bottom> <br> |
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr> |
|
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td> |
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="networkx.html">networkx</a><br> |
</td><td width="25%" valign=top><a href="matplotlib.pyplot.html">matplotlib.pyplot</a><br> |
</td><td width="25%" valign=top></td><td width="25%" valign=top></td></tr></table></td></tr></table><p> |
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
<tr bgcolor="#eeaa77"> |
<td colspan=3 valign=bottom> <br> |
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr> |
|
<tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td> |
<td width="100%"><dl><dt><a name="-draw_noc"><strong>draw_noc</strong></a>(noc, rectangular<font color="#909090">=True</font>, nodepos<font color="#909090">=None</font>)</dt><dd><tt>Draw a representation of a NoC<br> |
<br> |
Arguments:<br> |
* noc: Model to draw<br> |
* rectangular: If True assumes rectangular layout, with routers <br> |
having coord_x and coord_y attributes. If false, expect router's <br> |
positions in nodepos argument<br> |
* nodepos: Optional dictionary where keys are router's indexes and values <br> |
are tuples with x and y positions.</tt></dd></dl> |
</td></tr></table> |
</body></html> |
/doc/nocmodel.noc_tlm_utils.html
0,0 → 1,35
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
<html><head><title>Python: module nocmodel.noc_tlm_utils</title> |
</head><body bgcolor="#f0f0f8"> |
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading"> |
<tr bgcolor="#7799ee"> |
<td valign=bottom> <br> |
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="nocmodel.html"><font color="#ffffff">nocmodel</font></a>.noc_tlm_utils</strong></big></big></font></td |
><td align=right valign=bottom |
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/oscard/Documentos/proyectos/nocmodel-0.1/nocmodel/noc_tlm_utils.py">/home/oscard/Documentos/proyectos/nocmodel-0.1/nocmodel/noc_tlm_utils.py</a></font></td></tr></table> |
<p><tt># -*- coding: utf-8 -*-</tt></p> |
<p> |
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
<tr bgcolor="#aa55cc"> |
<td colspan=3 valign=bottom> <br> |
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr> |
|
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td> |
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="nocmodel.basicmodels.basic_channel.html">nocmodel.basicmodels.basic_channel</a><br> |
<a href="nocmodel.basicmodels.basic_ipcore.html">nocmodel.basicmodels.basic_ipcore</a><br> |
</td><td width="25%" valign=top><a href="nocmodel.basicmodels.basic_router.html">nocmodel.basicmodels.basic_router</a><br> |
<a href="logging.html">logging</a><br> |
</td><td width="25%" valign=top><a href="myhdl.html">myhdl</a><br> |
<a href="networkx.html">networkx</a><br> |
</td><td width="25%" valign=top></td></tr></table></td></tr></table><p> |
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
<tr bgcolor="#eeaa77"> |
<td colspan=3 valign=bottom> <br> |
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr> |
|
<tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td> |
<td width="100%"><dl><dt><a name="-add_tlm_basic_support"><strong>add_tlm_basic_support</strong></a>(instance, **kwargs)</dt><dd><tt>This function will add for every object in noc_instance a noc_tlm object</tt></dd></dl> |
</td></tr></table> |
</body></html> |
/CHANGELOG.txt
0,0 → 1,8
nocmodel (0.1) urgency=low |
|
* First release: |
- Basic model framework |
- Initial TLM simulation support |
- Basic set of NoC object models |
|
-- Oscar Diaz <dargor@opencores.org> Thr, 03 Mar 2011 23:05:45 +0100 |
/setup.py
0,0 → 1,59
#!/usr/bin/env python |
# -*- coding: utf-8 -*- |
|
# |
# NoCmodel - setup file |
# |
# Author: Oscar Diaz |
# Version: 0.1 |
# Date: 03-03-2011 |
|
# |
# This code is free software; you can redistribute it and/or |
# modify it under the terms of the GNU Lesser General Public |
# License as published by the Free Software Foundation; either |
# version 2.1 of the License, or (at your option) any later version. |
# |
# This code is distributed in the hope that it will be useful, |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
# Lesser General Public License for more details. |
# |
# You should have received a copy of the GNU Lesser General Public |
# License along with this library; if not, write to the |
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
# Boston, MA 02111-1307 USA |
# |
|
# |
# Changelog: |
# |
# 03-03-2011 : (OD) initial release |
# |
|
from distutils.core import setup |
|
classifiers = """\ |
Development Status :: 3 - Alpha |
Intended Audience :: Developers |
License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL) |
Operating System :: OS Independent |
Programming Language :: Python |
Topic :: Scientific/Engineering :: Electronic Design Automation (EDA) |
""" |
|
setup(name='nocmodel', |
version='0.1', |
description='Network-on-Chip modeling library', |
author='Oscar Diaz', |
author_email='dargor@opencores.org', |
url='http://opencores.org/project,nocmodel', |
license='LGPL', |
requires=['networkx', 'myhdl'], |
platforms=["Any"], |
keywords="HDL ASIC FPGA SoC NoC hardware design", |
classifiers=filter(None, classifiers.split("\n")), |
packages=[ |
'nocmodel', |
], |
) |
/README.txt
0,0 → 1,47
NoCmodel 0.1 |
============ |
|
What is NoCmodel? |
----------------- |
|
NoCmodel is a Python module for Network-on-Chip modeling, with add-ons for |
simulation (functional or RTL) and code generation (initially VHDL). |
|
Based on Python language, this module provides a framework for generic modeling |
of a NoC (IP Core nodes, routers, or channels), and provides some add-ons that |
extends the model to support design features like functional simulation, |
RTL simulation, VHDL code generation, etc. |
|
Requirements |
------------ |
|
* Python (version 2.6 or later) |
* NetworkX (version 1.4 or later) [http://networkx.lanl.gov] |
* MyHDL (version 0.6 or later) [http://www.myhdl.org] |
|
Installation |
------------ |
System-wide install: |
|
python setup.py install |
|
Like a normal Python package, it uses distutils for its installation. |
Check the distutils documentation in the standard Python library |
if necessary. |
|
Documentation |
------------- |
|
Documentation generated by pydoc is available on "src" directory. Also, there's |
basic examples in "examples" directory. |
|
License |
------- |
NoCmodel is available under the LGPL license version 2.1 . See LICENSE.txt. |
|
Authors |
------- |
|
* Oscar Diaz <dargor@opencores.org> |
|
Last update: Thu, 03 Mar 2011 18:00:20 +0100 |
/examples/basic_example.py
0,0 → 1,133
#!/usr/bin/env python |
# -*- coding: utf-8 -*- |
|
# |
# NoCmodel basic example |
# |
# Author: Oscar Diaz |
# Version: 0.1 |
# Date: 03-03-2011 |
|
# |
# This code is free software; you can redistribute it and/or |
# modify it under the terms of the GNU Lesser General Public |
# License as published by the Free Software Foundation; either |
# version 2.1 of the License, or (at your option) any later version. |
# |
# This code is distributed in the hope that it will be useful, |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
# Lesser General Public License for more details. |
# |
# You should have received a copy of the GNU Lesser General Public |
# License along with this library; if not, write to the |
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
# Boston, MA 02111-1307 USA |
# |
|
# |
# Changelog: |
# |
# 03-03-2011 : (OD) initial release |
# |
|
import matplotlib.pyplot as plt |
import myhdl |
import logging |
|
from nocmodel import * |
from nocmodel.basicmodels import * |
|
# Basic example model with TLM simulation |
|
# 1. Create the model |
|
basicnoc = noc(name="Basic 2x2 NoC example") |
|
# 1.1 create a rectangular 2x2 NoC, make its connections and add default protocol |
|
R11 = basicnoc.add_router("R11", with_ipcore=True, coord_x = 1, coord_y = 1) |
R12 = basicnoc.add_router("R12", with_ipcore=True, coord_x = 1, coord_y = 2) |
R21 = basicnoc.add_router("R21", with_ipcore=True, coord_x = 2, coord_y = 1) |
R22 = basicnoc.add_router("R22", with_ipcore=True, coord_x = 2, coord_y = 2) |
|
basicnoc.add_channel(R11,R12) |
basicnoc.add_channel(R11,R21) |
basicnoc.add_channel(R12,R22) |
basicnoc.add_channel(R21,R22) |
|
basicnoc.protocol_ref = basic_protocol() |
|
for r in basicnoc.router_list(): |
r.update_ports_info() |
r.update_routes_info() |
|
# 2. add tlm support, and configure logging |
add_tlm_basic_support(basicnoc, log_file="simulation.log", log_level=logging.DEBUG) |
|
# 3. Declare generators to put in the TLM simulation |
|
# set ip_cores functionality as myhdl generators |
def sourcegen(din, dout, tlm_ref, mydest, data=None, startdelay=100, period=100): |
# this generator only drives dout |
@myhdl.instance |
def putnewdata(): |
datacount = 0 |
protocol_ref = tlm_ref.ipcore_ref.get_protocol_ref() |
mysrc = tlm_ref.ipcore_ref.router_ref.address |
tlm_ref.debug("sourcegen: init dout is %s" % repr(dout.val)) |
yield myhdl.delay(startdelay) |
while True: |
if len(data) == datacount: |
tlm_ref.debug("sourcegen: end of data. waiting for %d steps" % (period*10)) |
yield myhdl.delay(period*10) |
raise myhdl.StopSimulation("data ended at time %d" % myhdl.now()) |
dout.next = protocol_ref.newpacket(False, mysrc, mydest, data[datacount]) |
tlm_ref.debug("sourcegen: data next element %d dout is %s datacount is %d" % (data[datacount], repr(dout.val), datacount)) |
yield myhdl.delay(period) |
datacount += 1 |
return putnewdata |
|
def checkgen(din, dout, tlm_ref, mysrc, data=None): |
# this generator only respond to din |
@myhdl.instance |
def checkdata(): |
datacount = 0 |
protocol_ref = tlm_ref.ipcore_ref.get_protocol_ref() |
mydest = tlm_ref.ipcore_ref.router_ref.address |
while True: |
yield din |
if len(data) > datacount: |
checkdata = din.val["data"] |
tlm_ref.debug("checkgen: assert checkdata != data[datacount] => %d != %d [%d]" % (checkdata, data[datacount], datacount)) |
if checkdata != data[datacount]: |
tlm_ref.error("checkgen: value != %d (%d)" % (data[datacount], checkdata)) |
tlm_ref.debug("checkgen: assert source address != mysrc => %d != %d " % (din.val["src"], mysrc)) |
if din.val["src"] != mysrc: |
tlm_ref.error("checkgen: source address != %d (%d)" % (mysrc, din.val["src"])) |
tlm_ref.debug("checkgen: assert destination address != mydest => %d != %d " % (din.val["dst"], mydest)) |
if din.val["dst"] != mydest: |
tlm_ref.error("checkgen: destination address != %d (%d)" % (mydest, din.val["dst"])) |
datacount += 1 |
return checkdata |
|
# 4. Set test vectors |
R11_testdata = [5, 12, 50, -11, 6, 9, 0, 3, 25] |
R12_testdata = [x*5 for x in R11_testdata] |
|
# 5. assign generators to ip cores (in TLM model !) |
# R11 will send to R22, R12 will send to R21 |
R11.ipcore_ref.tlm.register_generator(sourcegen, mydest=R22.address, data=R11_testdata, startdelay=10, period=20) |
R12.ipcore_ref.tlm.register_generator(sourcegen, mydest=R21.address, data=R12_testdata, startdelay=15, period=25) |
R21.ipcore_ref.tlm.register_generator(checkgen, mysrc=R12.address, data=R12_testdata) |
R22.ipcore_ref.tlm.register_generator(checkgen, mysrc=R11.address, data=R11_testdata) |
|
# 6. configure simulation and run! |
basicnoc.tlmsim.configure_simulation(max_time=1000) |
print "Starting simulation..." |
basicnoc.tlmsim.run() |
print "Simulation finished. Pick the results in log files." |
|
# 7. View graphical representation |
|
draw_noc(basicnoc) |