def reset(self): self.metric = infinity # P = prob. that will retransmit and use self path # total = metric * (1-P) [this part is additive!] # totalP = { rate : [total, P] } self.totalP = {} for rate in self.links.keys(): self.totalP[rate] = [wifi.packetTime(Node.PACKETSIZE, rate), 1.0] self.rate = 0 # = Madwifi 802.11 bit-rate self.totalP[0] = [0.0, 1.0] self.P = 1.0 # = totalP[rate][1] [for load distribution] self.usedlinks = None self.loads = {} # = x_ik self.load = 0.0 # = sumk x_ik self.tx = -1.0 # = load / (1-P) self.tt = 0.0 # = tx * packetTime(rate) self.next = self # = argmax_k x_ik | next hop in ett self.rx = 0.0 # = E[number of packets heard from teachers]
def computeLoadOpp(self, src): """ Compute opportunistic load and best hop. Process nodes in topological order and distribute loads. Expected packet rate is computed by sending a flow from src and forwarding at all those who receive and have better metric. Complexity: O(n^2) """ nodes = self.nodes for n in nodes: n.load = n.tx = n.rx = 0.0 n.loads = {} if(len(nodes) == 1): return # degenerate case srcnode = nodes[-1] assert(srcnode.id == src) if(srcnode.rate == 0): return raise Exception("No route!") if(srcnode.P == 1.0): # need to compute P self.computeP() srcnode.load = 1.0 # Expected rate is computed by sending a flow from src # and forwarding at all those who receive and have STRICTLY better metric for i in range(len(nodes)-1, 0, -1): ni = nodes[i] if(ni.load == 0.0): continue P = ni.P assert P < 1.0 pt = ni.usedlinks # compute actual #tx from the load ni.tx = ni.load / (1 - P) P = 1.0 bestp = 0.0 # for next for j in range(0, i): if(nodes[j].metric == ni.metric): # we don't want equal metrics break puv = pt.get(nodes[j].id, 0) if(puv == 0.0): continue # compute the load on (u,v) ld = ni.tx * puv * P ni.loads[nodes[j].id] = ld # add to total load of v nodes[j].load += ld if(P * puv > bestp): bestp = P * puv ni.next = nodes[j] P *= (1 - puv) #if(P == 0.0): # no point continuing # break # we have to continue to compute rx nodes[j].rx += ni.tx * puv # used in unicast only assert(P == ni.P) # compute this node's tx time ni.tt = ni.tx * wifi.packetTime(Node.PACKETSIZE, ni.rate)