annotate tools/python-PE/CompactRouting/Routing.py @ 67:264123227f0d

large tuple case (suggestion)
author one
date Sat, 06 Jun 2009 14:33:59 +0900
parents 6c40056777be
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8
6c40056777be Initial revision
fuchita
parents:
diff changeset
1 import string
6c40056777be Initial revision
fuchita
parents:
diff changeset
2 import struct
6c40056777be Initial revision
fuchita
parents:
diff changeset
3 import time
6c40056777be Initial revision
fuchita
parents:
diff changeset
4
6c40056777be Initial revision
fuchita
parents:
diff changeset
5 import xml.dom.minidom
6c40056777be Initial revision
fuchita
parents:
diff changeset
6 import FederatedLinda
6c40056777be Initial revision
fuchita
parents:
diff changeset
7 import LinkConfiguration
6c40056777be Initial revision
fuchita
parents:
diff changeset
8
6c40056777be Initial revision
fuchita
parents:
diff changeset
9 TUPLE_ID_LINKCONFIG = 1
6c40056777be Initial revision
fuchita
parents:
diff changeset
10 TUPLE_ID_ROUTING = 2
6c40056777be Initial revision
fuchita
parents:
diff changeset
11
6c40056777be Initial revision
fuchita
parents:
diff changeset
12 ROUTING_HEADER_FORMAT = "!I"
6c40056777be Initial revision
fuchita
parents:
diff changeset
13
6c40056777be Initial revision
fuchita
parents:
diff changeset
14 ROUTING_COMMAND_CONNECT = 1
6c40056777be Initial revision
fuchita
parents:
diff changeset
15 ROUTING_COMMAND_DISCONNECT = 2
6c40056777be Initial revision
fuchita
parents:
diff changeset
16 ROUTING_COMMAND_TRANSFER = 3
6c40056777be Initial revision
fuchita
parents:
diff changeset
17 ROUTING_COMMAND_UPDATE_TABLE = 4
6c40056777be Initial revision
fuchita
parents:
diff changeset
18
6c40056777be Initial revision
fuchita
parents:
diff changeset
19 class TSInfo:
6c40056777be Initial revision
fuchita
parents:
diff changeset
20 def __init__(self, tsid, hopnum, ttl, nexthop):
6c40056777be Initial revision
fuchita
parents:
diff changeset
21 self.tsid = tsid # tuple space id, like 'host:port'
6c40056777be Initial revision
fuchita
parents:
diff changeset
22 self.hopnum = hopnum # hop number
6c40056777be Initial revision
fuchita
parents:
diff changeset
23 self.ttl = ttl #
6c40056777be Initial revision
fuchita
parents:
diff changeset
24 self.nexthop = nexthop # next hop (tuple space id)
6c40056777be Initial revision
fuchita
parents:
diff changeset
25
6c40056777be Initial revision
fuchita
parents:
diff changeset
26
6c40056777be Initial revision
fuchita
parents:
diff changeset
27 """ XML format is as follows
6c40056777be Initial revision
fuchita
parents:
diff changeset
28 <RoutingTable name="localhost:10000">
6c40056777be Initial revision
fuchita
parents:
diff changeset
29 <ts hopnum="1" tsid="localhost:10002" ttl="0"/>
6c40056777be Initial revision
fuchita
parents:
diff changeset
30 <ts hopnum="1" tsid="localhost:10001" ttl="256"/>
6c40056777be Initial revision
fuchita
parents:
diff changeset
31 <ts hopnum="0" tsid="localhost:10000" ttl="0"/>
6c40056777be Initial revision
fuchita
parents:
diff changeset
32 </RoutingTable>
6c40056777be Initial revision
fuchita
parents:
diff changeset
33 """
6c40056777be Initial revision
fuchita
parents:
diff changeset
34 class RoutingTable:
6c40056777be Initial revision
fuchita
parents:
diff changeset
35 def __init__(self, name):
6c40056777be Initial revision
fuchita
parents:
diff changeset
36 self.tslist = {}
6c40056777be Initial revision
fuchita
parents:
diff changeset
37 self.name = name
6c40056777be Initial revision
fuchita
parents:
diff changeset
38
6c40056777be Initial revision
fuchita
parents:
diff changeset
39 def register(self, tsid, hopnum, ttl, nexthop):
6c40056777be Initial revision
fuchita
parents:
diff changeset
40 if (self.tslist.has_key(tsid)):
6c40056777be Initial revision
fuchita
parents:
diff changeset
41 del self.tslist[tsid]
6c40056777be Initial revision
fuchita
parents:
diff changeset
42 self.tslist[tsid] = TSInfo(tsid, hopnum, ttl, nexthop)
6c40056777be Initial revision
fuchita
parents:
diff changeset
43
6c40056777be Initial revision
fuchita
parents:
diff changeset
44 def deregister(self, tsid):
6c40056777be Initial revision
fuchita
parents:
diff changeset
45 for t in self.tslist.keys():
6c40056777be Initial revision
fuchita
parents:
diff changeset
46 if self.tslist[t].nexthop == tsid:
6c40056777be Initial revision
fuchita
parents:
diff changeset
47 del self.tslist[t]
6c40056777be Initial revision
fuchita
parents:
diff changeset
48
6c40056777be Initial revision
fuchita
parents:
diff changeset
49 def update(self, xmldoc, ts):
6c40056777be Initial revision
fuchita
parents:
diff changeset
50 rt = xml.dom.minidom.parseString(xmldoc).childNodes[0]
6c40056777be Initial revision
fuchita
parents:
diff changeset
51 tslist = rt.childNodes
6c40056777be Initial revision
fuchita
parents:
diff changeset
52 updateflag = False
6c40056777be Initial revision
fuchita
parents:
diff changeset
53
6c40056777be Initial revision
fuchita
parents:
diff changeset
54 tmplist = []
6c40056777be Initial revision
fuchita
parents:
diff changeset
55
6c40056777be Initial revision
fuchita
parents:
diff changeset
56 # append tuplespace
6c40056777be Initial revision
fuchita
parents:
diff changeset
57 for t in tslist:
6c40056777be Initial revision
fuchita
parents:
diff changeset
58 if t.nodeType == t.ELEMENT_NODE and t.localName == 'ts':
6c40056777be Initial revision
fuchita
parents:
diff changeset
59 tsattr = t.attributes
6c40056777be Initial revision
fuchita
parents:
diff changeset
60 tsid = tsattr['tsid'].nodeValue
6c40056777be Initial revision
fuchita
parents:
diff changeset
61 hopnum = int( tsattr['hopnum'].nodeValue )
6c40056777be Initial revision
fuchita
parents:
diff changeset
62 ttl = int( tsattr['ttl'].nodeValue )
6c40056777be Initial revision
fuchita
parents:
diff changeset
63 nexthop = ts
6c40056777be Initial revision
fuchita
parents:
diff changeset
64
6c40056777be Initial revision
fuchita
parents:
diff changeset
65 tmplist.append(tsid)
6c40056777be Initial revision
fuchita
parents:
diff changeset
66
6c40056777be Initial revision
fuchita
parents:
diff changeset
67 if ((not self.tslist.has_key(tsid)) or
6c40056777be Initial revision
fuchita
parents:
diff changeset
68 (self.tslist[tsid].hopnum > hopnum+1)):
6c40056777be Initial revision
fuchita
parents:
diff changeset
69 self.register(tsid, hopnum+1, ttl, nexthop)
6c40056777be Initial revision
fuchita
parents:
diff changeset
70 updateflag = True
6c40056777be Initial revision
fuchita
parents:
diff changeset
71
6c40056777be Initial revision
fuchita
parents:
diff changeset
72 # delete tuplespace
6c40056777be Initial revision
fuchita
parents:
diff changeset
73 for t in self.tslist.values():
6c40056777be Initial revision
fuchita
parents:
diff changeset
74 if ( not t.tsid in tmplist ):
6c40056777be Initial revision
fuchita
parents:
diff changeset
75 updateflag = True
6c40056777be Initial revision
fuchita
parents:
diff changeset
76 if (t.nexthop == ts):
6c40056777be Initial revision
fuchita
parents:
diff changeset
77 del self.tslist[t.tsid]
6c40056777be Initial revision
fuchita
parents:
diff changeset
78
6c40056777be Initial revision
fuchita
parents:
diff changeset
79 return updateflag
6c40056777be Initial revision
fuchita
parents:
diff changeset
80
6c40056777be Initial revision
fuchita
parents:
diff changeset
81 def getxmldoc(self):
6c40056777be Initial revision
fuchita
parents:
diff changeset
82 doc = xml.dom.minidom.Document()
6c40056777be Initial revision
fuchita
parents:
diff changeset
83 rt = doc.createElement('RoutingTable')
6c40056777be Initial revision
fuchita
parents:
diff changeset
84 rt.setAttribute('name', self.name)
6c40056777be Initial revision
fuchita
parents:
diff changeset
85 for tskey in self.tslist.keys():
6c40056777be Initial revision
fuchita
parents:
diff changeset
86 elem = doc.createElement('ts')
6c40056777be Initial revision
fuchita
parents:
diff changeset
87 elem.setAttribute('tsid', self.tslist[tskey].tsid)
6c40056777be Initial revision
fuchita
parents:
diff changeset
88 elem.setAttribute('hopnum', str(self.tslist[tskey].hopnum))
6c40056777be Initial revision
fuchita
parents:
diff changeset
89 elem.setAttribute('ttl', str(self.tslist[tskey].ttl))
6c40056777be Initial revision
fuchita
parents:
diff changeset
90 rt.appendChild(elem)
6c40056777be Initial revision
fuchita
parents:
diff changeset
91
6c40056777be Initial revision
fuchita
parents:
diff changeset
92 return rt
6c40056777be Initial revision
fuchita
parents:
diff changeset
93
6c40056777be Initial revision
fuchita
parents:
diff changeset
94 def getxml(self):
6c40056777be Initial revision
fuchita
parents:
diff changeset
95 rt = self.getxmldoc()
6c40056777be Initial revision
fuchita
parents:
diff changeset
96 return rt.toxml()
6c40056777be Initial revision
fuchita
parents:
diff changeset
97
6c40056777be Initial revision
fuchita
parents:
diff changeset
98 def printxml(self):
6c40056777be Initial revision
fuchita
parents:
diff changeset
99 rt = self.getxmldoc()
6c40056777be Initial revision
fuchita
parents:
diff changeset
100 print rt.toprettyxml()
6c40056777be Initial revision
fuchita
parents:
diff changeset
101 end = time.time()
6c40056777be Initial revision
fuchita
parents:
diff changeset
102 print "passed time ",end
6c40056777be Initial revision
fuchita
parents:
diff changeset
103
6c40056777be Initial revision
fuchita
parents:
diff changeset
104 def getdstname(self, xmltext):
6c40056777be Initial revision
fuchita
parents:
diff changeset
105 rt = xml.dom.minidom.parseString(xmltext).childNodes[0]
6c40056777be Initial revision
fuchita
parents:
diff changeset
106 return rt.attributes['name'].nodeValue
6c40056777be Initial revision
fuchita
parents:
diff changeset
107
6c40056777be Initial revision
fuchita
parents:
diff changeset
108 class Routing:
6c40056777be Initial revision
fuchita
parents:
diff changeset
109 def __init__(self, headerFormat = ROUTING_HEADER_FORMAT):
6c40056777be Initial revision
fuchita
parents:
diff changeset
110 self.flinda = FederatedLinda.FederatedLinda()
6c40056777be Initial revision
fuchita
parents:
diff changeset
111 self.linda = None
6c40056777be Initial revision
fuchita
parents:
diff changeset
112 self.tsid = None
6c40056777be Initial revision
fuchita
parents:
diff changeset
113 self.neighbors = {} # key is tsid ("host:port"), value is Linda object
6c40056777be Initial revision
fuchita
parents:
diff changeset
114 self.headerFormat = headerFormat # struct.pack's format
6c40056777be Initial revision
fuchita
parents:
diff changeset
115 self.rt = None
6c40056777be Initial revision
fuchita
parents:
diff changeset
116
6c40056777be Initial revision
fuchita
parents:
diff changeset
117 def __del__(self):
6c40056777be Initial revision
fuchita
parents:
diff changeset
118 self.linda.close()
6c40056777be Initial revision
fuchita
parents:
diff changeset
119 for ts in self.neighbors.values():
6c40056777be Initial revision
fuchita
parents:
diff changeset
120 ts.close()
6c40056777be Initial revision
fuchita
parents:
diff changeset
121
6c40056777be Initial revision
fuchita
parents:
diff changeset
122 def connect(self, tsid):
6c40056777be Initial revision
fuchita
parents:
diff changeset
123 host, port = string.split(tsid, ':', 1)
6c40056777be Initial revision
fuchita
parents:
diff changeset
124 ts = self.flinda.open(host, int(port))
6c40056777be Initial revision
fuchita
parents:
diff changeset
125 if not ts:
6c40056777be Initial revision
fuchita
parents:
diff changeset
126 return None
6c40056777be Initial revision
fuchita
parents:
diff changeset
127
6c40056777be Initial revision
fuchita
parents:
diff changeset
128 ts.getid()
6c40056777be Initial revision
fuchita
parents:
diff changeset
129 self.addNeighbor(ts, tsid)
6c40056777be Initial revision
fuchita
parents:
diff changeset
130
6c40056777be Initial revision
fuchita
parents:
diff changeset
131 return ts
6c40056777be Initial revision
fuchita
parents:
diff changeset
132
6c40056777be Initial revision
fuchita
parents:
diff changeset
133 def disconnect(self, tsid):
6c40056777be Initial revision
fuchita
parents:
diff changeset
134 if ( self.neighbors.has_key(tsid) ):
6c40056777be Initial revision
fuchita
parents:
diff changeset
135 self.delNeighbor(tsid)
6c40056777be Initial revision
fuchita
parents:
diff changeset
136
6c40056777be Initial revision
fuchita
parents:
diff changeset
137 def addNeighbor(self, ts, tsid):
6c40056777be Initial revision
fuchita
parents:
diff changeset
138 self.neighbors[tsid] = ts
6c40056777be Initial revision
fuchita
parents:
diff changeset
139 return ts
6c40056777be Initial revision
fuchita
parents:
diff changeset
140
6c40056777be Initial revision
fuchita
parents:
diff changeset
141 def delNeighbor(self, tsid):
6c40056777be Initial revision
fuchita
parents:
diff changeset
142 del self.neighbors[tsid]
6c40056777be Initial revision
fuchita
parents:
diff changeset
143
6c40056777be Initial revision
fuchita
parents:
diff changeset
144 def pack(self, data, cmd):
6c40056777be Initial revision
fuchita
parents:
diff changeset
145 return struct.pack(self.headerFormat, cmd) + data
6c40056777be Initial revision
fuchita
parents:
diff changeset
146
6c40056777be Initial revision
fuchita
parents:
diff changeset
147 def unpack(self, packet):
6c40056777be Initial revision
fuchita
parents:
diff changeset
148 r = struct.unpack(self.headerFormat +
6c40056777be Initial revision
fuchita
parents:
diff changeset
149 str(len(packet)-struct.calcsize(self.headerFormat)) +
6c40056777be Initial revision
fuchita
parents:
diff changeset
150 "s", packet)
6c40056777be Initial revision
fuchita
parents:
diff changeset
151 return r
6c40056777be Initial revision
fuchita
parents:
diff changeset
152
6c40056777be Initial revision
fuchita
parents:
diff changeset
153 def LinkConfig(self, mytsid, packet):
6c40056777be Initial revision
fuchita
parents:
diff changeset
154 self.tsid = mytsid
6c40056777be Initial revision
fuchita
parents:
diff changeset
155 lcparser = LinkConfiguration.LinkConfigParser()
6c40056777be Initial revision
fuchita
parents:
diff changeset
156 linkConfig = lcparser.parseLinkConfig(self.tsid, packet)
6c40056777be Initial revision
fuchita
parents:
diff changeset
157 mydstlist = linkConfig.getDstlist(linkConfig.label)
6c40056777be Initial revision
fuchita
parents:
diff changeset
158
6c40056777be Initial revision
fuchita
parents:
diff changeset
159 for n in mydstlist:
6c40056777be Initial revision
fuchita
parents:
diff changeset
160 tsid = linkConfig.linklist[n].tsid
6c40056777be Initial revision
fuchita
parents:
diff changeset
161 if ( tsid and not self.neighbors.has_key(tsid) ):
6c40056777be Initial revision
fuchita
parents:
diff changeset
162 ts = self.connect(tsid)
6c40056777be Initial revision
fuchita
parents:
diff changeset
163 ts.Out(TUPLE_ID_LINKCONFIG, packet)
6c40056777be Initial revision
fuchita
parents:
diff changeset
164 ts.Out(TUPLE_ID_ROUTING, self.pack(self.tsid, ROUTING_COMMAND_CONNECT))
6c40056777be Initial revision
fuchita
parents:
diff changeset
165 pass
6c40056777be Initial revision
fuchita
parents:
diff changeset
166
6c40056777be Initial revision
fuchita
parents:
diff changeset
167 def RoutingConnect(self, data):
6c40056777be Initial revision
fuchita
parents:
diff changeset
168 print "connect"
6c40056777be Initial revision
fuchita
parents:
diff changeset
169 if ( not self.neighbors.has_key(data) ):
6c40056777be Initial revision
fuchita
parents:
diff changeset
170 ts = self.connect(data)
6c40056777be Initial revision
fuchita
parents:
diff changeset
171 ts.Out(TUPLE_ID_ROUTING, self.pack(self.tsid, ROUTING_COMMAND_CONNECT))
6c40056777be Initial revision
fuchita
parents:
diff changeset
172
6c40056777be Initial revision
fuchita
parents:
diff changeset
173 self.rt.register(data, 1, 16, data)
6c40056777be Initial revision
fuchita
parents:
diff changeset
174 upedxml = self.rt.getxml()
6c40056777be Initial revision
fuchita
parents:
diff changeset
175 # print "Gen XML ",upedxml
6c40056777be Initial revision
fuchita
parents:
diff changeset
176 # print "Neighbors ",self.neighbors
6c40056777be Initial revision
fuchita
parents:
diff changeset
177 for nts in self.neighbors.values():
6c40056777be Initial revision
fuchita
parents:
diff changeset
178 nts.Out(TUPLE_ID_ROUTING, self.pack(upedxml, ROUTING_COMMAND_UPDATE_TABLE))
6c40056777be Initial revision
fuchita
parents:
diff changeset
179 pass
6c40056777be Initial revision
fuchita
parents:
diff changeset
180
6c40056777be Initial revision
fuchita
parents:
diff changeset
181 def RoutingDisconnect(self, data):
6c40056777be Initial revision
fuchita
parents:
diff changeset
182 print "disconnect"
6c40056777be Initial revision
fuchita
parents:
diff changeset
183 if ( self.neighbors.has_key(data) ):
6c40056777be Initial revision
fuchita
parents:
diff changeset
184 ts = self.neighbors[data]
6c40056777be Initial revision
fuchita
parents:
diff changeset
185 ts.Out(TUPLE_ID_ROUTING, self.pack(self.tsid, ROUTING_COMMAND_DISCONNECT))
6c40056777be Initial revision
fuchita
parents:
diff changeset
186 self.disconnect(data)
6c40056777be Initial revision
fuchita
parents:
diff changeset
187
6c40056777be Initial revision
fuchita
parents:
diff changeset
188 self.rt.deregister(data)
6c40056777be Initial revision
fuchita
parents:
diff changeset
189 upedxml = self.rt.getxml()
6c40056777be Initial revision
fuchita
parents:
diff changeset
190 for nts in self.neighbors.values():
6c40056777be Initial revision
fuchita
parents:
diff changeset
191 nts.Out(TUPLE_ID_ROUTING, self.pack(upedxml, ROUTING_COMMAND_UPDATE_TABLE))
6c40056777be Initial revision
fuchita
parents:
diff changeset
192 pass
6c40056777be Initial revision
fuchita
parents:
diff changeset
193
6c40056777be Initial revision
fuchita
parents:
diff changeset
194 def RoutingTransfer(self, data):
6c40056777be Initial revision
fuchita
parents:
diff changeset
195 #print "transfer"
6c40056777be Initial revision
fuchita
parents:
diff changeset
196 # ReplyTuple is "DstTSID,TupleID,SrcTSID,DATA"
6c40056777be Initial revision
fuchita
parents:
diff changeset
197 # Src/DstTSID is "hostname:portnum"
6c40056777be Initial revision
fuchita
parents:
diff changeset
198
6c40056777be Initial revision
fuchita
parents:
diff changeset
199 dsttsid, tid, srctsid, pdata = string.split(data,',',3)
6c40056777be Initial revision
fuchita
parents:
diff changeset
200 print "transfer tuple:"
6c40056777be Initial revision
fuchita
parents:
diff changeset
201 print "dsttsid=>",dsttsid, "tid=>",tid, "srctsid=>",srctsid, "data=>",pdata
6c40056777be Initial revision
fuchita
parents:
diff changeset
202 if ( dsttsid == self.rt.name ):
6c40056777be Initial revision
fuchita
parents:
diff changeset
203 self.linda.Out(int(tid), data)
6c40056777be Initial revision
fuchita
parents:
diff changeset
204 else:
6c40056777be Initial revision
fuchita
parents:
diff changeset
205 dstts = self.neighbors[self.rt.tslist[dsttsid].nexthop]
6c40056777be Initial revision
fuchita
parents:
diff changeset
206 dstts.Out(TUPLE_ID_ROUTING, self.pack(data, ROUTING_COMMAND_TRANSFER))
6c40056777be Initial revision
fuchita
parents:
diff changeset
207 pass
6c40056777be Initial revision
fuchita
parents:
diff changeset
208
6c40056777be Initial revision
fuchita
parents:
diff changeset
209 def RoutingTableUpdate(self, data):
6c40056777be Initial revision
fuchita
parents:
diff changeset
210 print "update"
6c40056777be Initial revision
fuchita
parents:
diff changeset
211 srcname = self.rt.getdstname(data)
6c40056777be Initial revision
fuchita
parents:
diff changeset
212
6c40056777be Initial revision
fuchita
parents:
diff changeset
213 if ( self.rt.update(data, srcname) ):
6c40056777be Initial revision
fuchita
parents:
diff changeset
214 # Send Update Info to Neighbors
6c40056777be Initial revision
fuchita
parents:
diff changeset
215 upedxml = self.rt.getxml()
6c40056777be Initial revision
fuchita
parents:
diff changeset
216 for n in self.neighbors.values():
6c40056777be Initial revision
fuchita
parents:
diff changeset
217 n.Out(TUPLE_ID_ROUTING, self.pack(upedxml, ROUTING_COMMAND_UPDATE_TABLE))
6c40056777be Initial revision
fuchita
parents:
diff changeset
218
6c40056777be Initial revision
fuchita
parents:
diff changeset
219 pass
6c40056777be Initial revision
fuchita
parents:
diff changeset
220
6c40056777be Initial revision
fuchita
parents:
diff changeset
221 def run(self, mytsid):
6c40056777be Initial revision
fuchita
parents:
diff changeset
222 self.tsid = mytsid
6c40056777be Initial revision
fuchita
parents:
diff changeset
223 hostname, port = string.split(mytsid, ':', 1)
6c40056777be Initial revision
fuchita
parents:
diff changeset
224 self.linda = self.flinda.open(hostname, int(port))
6c40056777be Initial revision
fuchita
parents:
diff changeset
225 if not self.linda:
6c40056777be Initial revision
fuchita
parents:
diff changeset
226 return
6c40056777be Initial revision
fuchita
parents:
diff changeset
227
6c40056777be Initial revision
fuchita
parents:
diff changeset
228 self.rt = RoutingTable(mytsid)
6c40056777be Initial revision
fuchita
parents:
diff changeset
229 self.rt.register(self.rt.name, 0, 0, None)
6c40056777be Initial revision
fuchita
parents:
diff changeset
230
6c40056777be Initial revision
fuchita
parents:
diff changeset
231 self.linda.getid() # get client id from Tuple Space (ldserv)
6c40056777be Initial revision
fuchita
parents:
diff changeset
232
6c40056777be Initial revision
fuchita
parents:
diff changeset
233 linkConfigReply = self.linda.In(TUPLE_ID_LINKCONFIG)
6c40056777be Initial revision
fuchita
parents:
diff changeset
234 routingReply = self.linda.In(TUPLE_ID_ROUTING)
6c40056777be Initial revision
fuchita
parents:
diff changeset
235
6c40056777be Initial revision
fuchita
parents:
diff changeset
236 self.flinda.sync()
6c40056777be Initial revision
fuchita
parents:
diff changeset
237
6c40056777be Initial revision
fuchita
parents:
diff changeset
238 while (True):
6c40056777be Initial revision
fuchita
parents:
diff changeset
239 # Link Configuration
6c40056777be Initial revision
fuchita
parents:
diff changeset
240 rep = linkConfigReply.reply()
6c40056777be Initial revision
fuchita
parents:
diff changeset
241 if (rep):
6c40056777be Initial revision
fuchita
parents:
diff changeset
242 linkConfigReply = self.linda.In(TUPLE_ID_LINKCONFIG)
6c40056777be Initial revision
fuchita
parents:
diff changeset
243
6c40056777be Initial revision
fuchita
parents:
diff changeset
244 # Link Configuration main
6c40056777be Initial revision
fuchita
parents:
diff changeset
245 self.LinkConfig(self.tsid, rep)
6c40056777be Initial revision
fuchita
parents:
diff changeset
246
6c40056777be Initial revision
fuchita
parents:
diff changeset
247 # Routing Protocol
6c40056777be Initial revision
fuchita
parents:
diff changeset
248 rep = routingReply.reply()
6c40056777be Initial revision
fuchita
parents:
diff changeset
249 if (rep):
6c40056777be Initial revision
fuchita
parents:
diff changeset
250 routingReply = self.linda.In(TUPLE_ID_ROUTING)
6c40056777be Initial revision
fuchita
parents:
diff changeset
251 cmd , data = self.unpack(rep)
6c40056777be Initial revision
fuchita
parents:
diff changeset
252
6c40056777be Initial revision
fuchita
parents:
diff changeset
253 # connect to other tuplespace
6c40056777be Initial revision
fuchita
parents:
diff changeset
254 if (cmd == ROUTING_COMMAND_CONNECT):
6c40056777be Initial revision
fuchita
parents:
diff changeset
255 # connect main
6c40056777be Initial revision
fuchita
parents:
diff changeset
256 self.RoutingConnect(data)
6c40056777be Initial revision
fuchita
parents:
diff changeset
257
6c40056777be Initial revision
fuchita
parents:
diff changeset
258 # disconnect other tuplespace
6c40056777be Initial revision
fuchita
parents:
diff changeset
259 elif (cmd == ROUTING_COMMAND_DISCONNECT):
6c40056777be Initial revision
fuchita
parents:
diff changeset
260 # disconnect main
6c40056777be Initial revision
fuchita
parents:
diff changeset
261 self.RoutingDisconnect(data)
6c40056777be Initial revision
fuchita
parents:
diff changeset
262
6c40056777be Initial revision
fuchita
parents:
diff changeset
263 # transfer tuple
6c40056777be Initial revision
fuchita
parents:
diff changeset
264 elif (cmd == ROUTING_COMMAND_TRANSFER):
6c40056777be Initial revision
fuchita
parents:
diff changeset
265 # transfer main
6c40056777be Initial revision
fuchita
parents:
diff changeset
266 self.RoutingTransfer(data)
6c40056777be Initial revision
fuchita
parents:
diff changeset
267
6c40056777be Initial revision
fuchita
parents:
diff changeset
268 # update own routing table
6c40056777be Initial revision
fuchita
parents:
diff changeset
269 elif (cmd == ROUTING_COMMAND_UPDATE_TABLE):
6c40056777be Initial revision
fuchita
parents:
diff changeset
270 #routing table main
6c40056777be Initial revision
fuchita
parents:
diff changeset
271 self.RoutingTableUpdate(data)
6c40056777be Initial revision
fuchita
parents:
diff changeset
272 else:
6c40056777be Initial revision
fuchita
parents:
diff changeset
273 pass
6c40056777be Initial revision
fuchita
parents:
diff changeset
274
6c40056777be Initial revision
fuchita
parents:
diff changeset
275 print self.rt.printxml()
6c40056777be Initial revision
fuchita
parents:
diff changeset
276
6c40056777be Initial revision
fuchita
parents:
diff changeset
277 self.flinda.sync()
6c40056777be Initial revision
fuchita
parents:
diff changeset
278 # end while
6c40056777be Initial revision
fuchita
parents:
diff changeset
279
6c40056777be Initial revision
fuchita
parents:
diff changeset
280 if __name__ == '__main__':
6c40056777be Initial revision
fuchita
parents:
diff changeset
281 import sys
6c40056777be Initial revision
fuchita
parents:
diff changeset
282 if (len(sys.argv) != 2) :
6c40056777be Initial revision
fuchita
parents:
diff changeset
283 print "Usage : %s <hostname:portnum>" % sys.argv[0]
6c40056777be Initial revision
fuchita
parents:
diff changeset
284 sys.exit(1)
6c40056777be Initial revision
fuchita
parents:
diff changeset
285
6c40056777be Initial revision
fuchita
parents:
diff changeset
286 mytsid = sys.argv[1]
6c40056777be Initial revision
fuchita
parents:
diff changeset
287
6c40056777be Initial revision
fuchita
parents:
diff changeset
288 routing = Routing()
6c40056777be Initial revision
fuchita
parents:
diff changeset
289 routing.run(mytsid)
6c40056777be Initial revision
fuchita
parents:
diff changeset
290