Beispiel #1
0
	def _initiate_schedule(self, node):
		cells = self.frames['mainstream'].get_cells_of(node)
		dag_neighbors = []
		parent = self.dodag.get_parent(node)
		if parent:
			dag_neighbors += [parent]
		#children = self.dodag.get_children(node)
		#if children:
		#	dag_neighbors += children
		q = BlockQueue()
		for neighbor in dag_neighbors:
			flags = 0
			for cell in cells:
				if cell.tna == neighbor:
					if cell.option & 1 == 1:
						flags |= 1
					elif cell.option & 2 == 2:
						flags |= 2
			if flags & 1 == 0:
				so,co = self.schedule(node, neighbor, self.frames["mainstream"])
				if so is not None and co is not None:
					q.push(self.post_link(so, co, self.frames["mainstream"], node, neighbor))
					self.reserved_cells.append(Cell(node,so,co,self.frames["mainstream"].get_alias_id(node),0,1,neighbor))
					self.reserved_cells.append(Cell(neighbor,so,co,self.frames["mainstream"].get_alias_id(neighbor),0,2,node))
				else:
					logg.critical("INSUFFICIENT SLOTS: node " + str(node) + " cannot use more cells")
			if flags & 2 == 0:
				so,co = self.schedule(neighbor, node, self.frames["mainstream"])
				if so is not None and co is not None:
					q.push(self.post_link(so, co, self.frames["mainstream"], neighbor, node))
					self.reserved_cells.append(Cell(node,so,co,self.frames["mainstream"].get_alias_id(node),0,2,neighbor))
					self.reserved_cells.append(Cell(neighbor,so,co,self.frames["mainstream"].get_alias_id(neighbor),0,1,node))
				else:
					logg.critical("INSUFFICIENT SLOTS: node " + str(neighbor) + " cannot use more cells")
		return q
Beispiel #2
0
 def rewired(self, node_id, old_parent, new_parent):
     q = BlockQueue()
     q = self.Schedule_Link(node_id, new_parent,
                            self.frames[self.rewireframe], q)
     q = self.Schedule_Link(new_parent, node_id,
                            self.frames[self.rewireframe], q)
     q.block()
     return [q]
Beispiel #3
0
 def framed(self, who, local_name, remote_alias, old_payload):
     q = BlockQueue()
     if who in self.pending_connects and self.metainfo[who][
             'pending_cells'] is not None and len(
                 self.metainfo[who]['pending_cells']) == 0:
         self.pending_connects.remove(who)
         q.push(self._initiate_schedule(who))
     return q
Beispiel #4
0
	def reported(self, node, resource, value):
		q = BlockQueue()
		if node in self.pending_connects:
			if str(resource) == terms.get_resource_uri('6TOP', 'SLOTFRAME') and \
					self.frames['mainstream'].get_alias_id(node) != 255:
				add = True
				for f in self.frames.values():
					parts = f.name.split('#')
					if len(parts) == 2 and parts[0] == node.eui_64_ip and int(parts[1]) == 255:
						self.frames['mainstream'].set_alias_id(node, 255)
						del self.frames[f.name]
						add = False
						break
				if add:
					q.push(self.post_slotframes(node, self.frames['mainstream']))
			elif str(resource) == terms.get_resource_uri('6TOP', 'CELLLIST', 'ID') and value is not None:
				self.metainfo[node]['pending_cells'] = value
			elif str(resource).startswith(terms.get_resource_uri('6TOP', 'CELLLIST',ID='')) and value is not None:
				self.metainfo[node]['pending_cells'].remove(value[terms.resources['6TOP']['CELLLIST']['ID']['LABEL']])
				if not self.metainfo[node]['pending_cells'] and self.frames['mainstream'].get_alias_id(node) is not None:
					self.pending_connects.remove(node)
					q.push(self._initiate_schedule(node))
		elif str(resource).startswith(terms.get_resource_uri('6TOP', 'NEIGHBORLIST')) and value is not None:
			if node != self.root_id and (not isinstance(value,dict) or "traffic" not in value):
				q.push(self._adapt(node))
			elif node != self.root_id and isinstance(value,dict) and "traffic" in value:
				logg.info("PLEXIFLEX,MESSAGE,"+ str(node)+","+str(value["traffic"]))
		elif str(resource).startswith(terms.get_resource_uri('6TOP', 'STATISTICS')) and value == coap.CHANGED:
			pass
		return q
Beispiel #5
0
	def _adapt(self,node):
		q = BlockQueue()
		old_avg_timelag = self.metainfo[node]['latency_adwin'].getEstimation()
		old_avg_variance = self.metainfo[node]['variance_adwin'].getEstimation()
		last = self.metainfo[node]['timestamp']
		now = time()
		self.metainfo[node]['timestamp'] = now
		if last > 0:
			timelag = now - last
			trigger_avg = self.metainfo[node]['latency_adwin'].update(timelag)
			new_avg_timelag = self.metainfo[node]['latency_adwin'].getEstimation()
			new_var_timelag = self.metainfo[node]['latency_adwin'].getVariance()
			trigger_var = self.metainfo[node]['variance_adwin'].update(new_var_timelag)
			new_avg_variance = self.metainfo[node]['variance_adwin'].getEstimation()
			logg.info("PLEXIFLEX,PROBE,"+ str(node)+","+str(timelag)+","+ str(self.metainfo[node]['latency_adwin'].length())+","+str(new_avg_timelag)+","+ str(new_var_timelag)+","+ str(self.metainfo[node]['variance_adwin'].length())+","+str(new_avg_variance))
			tmp = ""
			for c in self.frames["mainstream"].get_cells_of(node):
				tmp += str(c.slot)+"#"+str(c.channel)+","
			logg.info("PLEXIFLEX,SCHEDULE,"+ str(node)+","+tmp)
			if trigger_avg:
				logg.info("PLEXIFLEX,INTERVAL,"+ str(node)+",CHANGE")
				if old_avg_timelag < new_avg_timelag:
					so,co = self.schedule(node, self.dodag.get_parent(node), self.frames["mainstream"])
					logg.info("PLEXIFLEX,INTERVAL,"+ str(node)+",ADD("+str(so)+","+str(co)+")")
					if so is not None and co is not None:
						q.push(self.post_link(so, co, self.frames["mainstream"], node, self.dodag.get_parent(node)))
				elif old_avg_timelag > new_avg_timelag:
					cells = self.frames['mainstream'].get_cells_similar_to(owner=node,tna=self.dodag.get_parent(node),link_option=1)
					if len(cells) > 1:
						logg.info("PLEXIFLEX,INTERVAL,"+ str(node)+",REMOVE")
						so,co = self.deschedule(node, self.dodag.get_parent(node),self.frames["maintenance"])
						if so is not None and co is not None:
							q.push(self.delete_link(node, self.frames["mainstream"], so, co))
			if trigger_var:
				logg.info("PLEXIFLEX,VARIANCE,"+ str(node)+",CHANGE")
				if old_avg_variance < new_avg_variance:
					so,co = self.schedule(node, self.dodag.get_parent(node), self.frames["mainstream"])
					logg.info("PLEXIFLEX,VARIANCE,"+ str(node)+",ADD("+str(so)+","+str(co)+")")
					if so is not None and co is not None:
						q.push(self.post_link(so, co, self.frames["mainstream"], node, self.dodag.get_parent(node)))
				elif old_avg_variance > new_avg_variance:
					cells = self.frames['mainstream'].get_cells_similar_to(owner=node,tna=self.dodag.get_parent(node),link_option=1)
					if len(cells) > 1:
						logg.info("PLEXIFLEX,VARIANCE,"+ str(node)+",REMOVE")
						self.deschedule(node, self.dodag.get_parent(node),self.frames["maintenance"])
						if so is not None and co is not None:
							q.push(self.delete_link(node, self.frames["mainstream"], so, co))
		return q
	def probed(self, node, resource, value):
		"""
		Install observer to node for statistics resource.

		Once a statistics resource has been defined, the node returns its identifier in value. This ensures an observer is
		set to node for the returned statistics resource.

		:param node: the node the statistics resource belongs to
		:type node: NodeID
		:param resource: the resource type the node has defined
		:type resource: str (practically the uri of the resource e.g. 6t/6/sm)
		:param value: the identifier of the statistics resource
		:type value: int (concatenating the resource and the value give the uri to the resource e.g. 6t/6/sm/0)
		:return: the set of commands needed to complete the installation of the observer to the resource
		:rtype: BlockQueue
		"""
		q = BlockQueue()
		q.push(Command('observe', node, terms.uri['6TP_SV'] + "/" + str(value)))
		q.block()
		return q
Beispiel #7
0
 def _initiate_schedule(self, node):
     cells = self.frames['mainstream'].get_cells_of(node)
     dag_neighbors = []
     parent = self.dodag.get_parent(node)
     if parent:
         dag_neighbors += [parent]
     #children = self.dodag.get_children(node)
     #if children:
     #	dag_neighbors += children
     q = BlockQueue()
     for neighbor in dag_neighbors:
         flags = 0
         for cell in cells:
             if cell.tna == neighbor:
                 if cell.option & 1 == 1:
                     flags |= 1
                 elif cell.option & 2 == 2:
                     flags |= 2
         if flags & 1 == 0:
             so, co = self.schedule(node, neighbor,
                                    self.frames["mainstream"])
             if so is not None and co is not None:
                 q.push(
                     self.post_link(so, co, self.frames["mainstream"], node,
                                    neighbor))
                 self.reserved_cells.append(
                     Cell(node, so, co,
                          self.frames["mainstream"].get_alias_id(node), 0,
                          1, neighbor))
                 self.reserved_cells.append(
                     Cell(neighbor, so, co,
                          self.frames["mainstream"].get_alias_id(neighbor),
                          0, 2, node))
             else:
                 logg.critical("INSUFFICIENT SLOTS: node " + str(node) +
                               " cannot use more cells")
         if flags & 2 == 0:
             so, co = self.schedule(neighbor, node,
                                    self.frames["mainstream"])
             if so is not None and co is not None:
                 q.push(
                     self.post_link(so, co, self.frames["mainstream"],
                                    neighbor, node))
                 self.reserved_cells.append(
                     Cell(node, so, co,
                          self.frames["mainstream"].get_alias_id(node), 0,
                          2, neighbor))
                 self.reserved_cells.append(
                     Cell(neighbor, so, co,
                          self.frames["mainstream"].get_alias_id(neighbor),
                          0, 1, node))
             else:
                 logg.critical("INSUFFICIENT SLOTS: node " + str(neighbor) +
                               " cannot use more cells")
     return q
Beispiel #8
0
 def CheckStatistic(self):
     # if self.statcheck:
     # 	return
     # self.statcheck = True
     logg.debug("Check Statistics")
     #iterate the statistics
     #TODO: check if bad link is not a lost child, in that case do nothing
     q = BlockQueue()
     for node, links in self.statistics.iteritems():
         #iterate through all links
         for link, stats in links.iteritems():
             ETX = stats["ETX"]
             if ETX < 0:
                 #data not collected yet
                 continue
             try:
                 PRR = self.statistics[link][node]["PRR"]
                 if PRR < 0:
                     #data not collected yet
                     continue
             except:
                 #data for receiving end not available
                 continue
             if ETX >= self.ETX_Ceil or PRR <= self.PRR_Floor:
                 #its within parameters for blacklisting, find the the link cells in the frames
                 logg.info("Detected bad link: " + str(node) + " -> " +
                           str(link))
                 for name, frame in self.frames.iteritems():
                     #build a set to prevent duplicates (due to multiple link_types) with items (owner,slot,channel)
                     s = Set()
                     for cell in frame.get_cells_similar_to(
                             tx_node="aaaa::" + node,
                             rx_node="aaaa::" + link):
                         s.add((cell.owner, cell.slot, cell.channel))
                     cells = []
                     #blacklist the cells
                     for c in s:
                         cells += self._blacklist(c[0], c[1], c[2], name,
                                                  -1)
                     #rescheduler the cells
                     for cl in cells:
                         # self.schedule(c.tx,c.rx,frame)
                         q = self.Schedule_Link(cl[0], cl[1], frame, q)
                     #send the changes to the network
                     self.communicate([q])
                 #only blacklist one link at a time to let the network adjust to the changes so break from loop
                 return
Beispiel #9
0
 def reported(self, node, resource, value):
     q = BlockQueue()
     if node in self.pending_connects:
         if str(resource) == terms.get_resource_uri('6TOP', 'SLOTFRAME') and \
           self.frames['mainstream'].get_alias_id(node) != 255:
             add = True
             for f in self.frames.values():
                 parts = f.name.split('#')
                 if len(parts) == 2 and parts[0] == node.eui_64_ip and int(
                         parts[1]) == 255:
                     self.frames['mainstream'].set_alias_id(node, 255)
                     del self.frames[f.name]
                     add = False
                     break
             if add:
                 q.push(
                     self.post_slotframes(node, self.frames['mainstream']))
         elif str(resource) == terms.get_resource_uri(
                 '6TOP', 'CELLLIST', 'ID') and value is not None:
             self.metainfo[node]['pending_cells'] = value
         elif str(resource).startswith(
                 terms.get_resource_uri('6TOP', 'CELLLIST',
                                        ID='')) and value is not None:
             self.metainfo[node]['pending_cells'].remove(
                 value[terms.resources['6TOP']['CELLLIST']['ID']['LABEL']])
             if not self.metainfo[node]['pending_cells'] and self.frames[
                     'mainstream'].get_alias_id(node) is not None:
                 self.pending_connects.remove(node)
                 q.push(self._initiate_schedule(node))
     elif str(resource).startswith(
             terms.get_resource_uri('6TOP',
                                    'NEIGHBORLIST')) and value is not None:
         if node != self.root_id and (not isinstance(value, dict)
                                      or "traffic" not in value):
             q.push(self._adapt(node))
         elif node != self.root_id and isinstance(
                 value, dict) and "traffic" in value:
             logg.info("PLEXIFLEX,MESSAGE," + str(node) + "," +
                       str(value["traffic"]))
     elif str(resource).startswith(
             terms.get_resource_uri(
                 '6TOP', 'STATISTICS')) and value == coap.CHANGED:
         pass
     return q
Beispiel #10
0
 def celled(self, who, slotoffs, channeloffs, frame, linkoption, linktype,
            target, old_payload):
     for i in self.reserved_cells:
         if i.owner == who and i.slot == slotoffs and i.channel == channeloffs and i.slotframe == frame.get_alias_id(
                 who):
             self.reserved_cells.remove(i)
             break
     if linkoption & 1 == 1:
         q = BlockQueue()
         cells = frame.get_cells_similar_to(owner=who,
                                            tna=self.dodag.get_parent(who),
                                            slot=slotoffs,
                                            channel=channeloffs,
                                            link_option=1)
         # if len(cells) == 1:
         # 	q.push(self.set_remote_statistics(who, self.stats_ids, cells[0], terms.resources['6TOP']['STATISTICS']['ETX']['LABEL'], 5))
         # 	self.stats_ids += 1
         return q
     return None
Beispiel #11
0
    def probed(self, node, resource, value):
        """
		Install observer to node for statistics resource.

		Once a statistics resource has been defined, the node returns its identifier in value. This ensures an observer is
		set to node for the returned statistics resource.

		:param node: the node the statistics resource belongs to
		:type node: NodeID
		:param resource: the resource type the node has defined
		:type resource: str (practically the uri of the resource e.g. 6t/6/sm)
		:param value: the identifier of the statistics resource
		:type value: int (concatenating the resource and the value give the uri to the resource e.g. 6t/6/sm/0)
		:return: the set of commands needed to complete the installation of the observer to the resource
		:rtype: BlockQueue
		"""
        q = BlockQueue()
        q.push(Command('observe', node,
                       terms.uri['6TP_SV'] + "/" + str(value)))
        q.block()
        return q
	def rewired(self, node_id, old_parent, new_parent):
		q = BlockQueue()
		q = self.Schedule_Link(node_id,new_parent, self.frames[self.rewireframe],q)
		q = self.Schedule_Link(new_parent,node_id, self.frames[self.rewireframe],q)
		q.block()
		return [q]
Beispiel #13
0
 def _adapt(self, node):
     q = BlockQueue()
     old_avg_timelag = self.metainfo[node]['latency_adwin'].getEstimation()
     old_avg_variance = self.metainfo[node]['variance_adwin'].getEstimation(
     )
     last = self.metainfo[node]['timestamp']
     now = time()
     self.metainfo[node]['timestamp'] = now
     if last > 0:
         timelag = now - last
         trigger_avg = self.metainfo[node]['latency_adwin'].update(timelag)
         new_avg_timelag = self.metainfo[node][
             'latency_adwin'].getEstimation()
         new_var_timelag = self.metainfo[node]['latency_adwin'].getVariance(
         )
         trigger_var = self.metainfo[node]['variance_adwin'].update(
             new_var_timelag)
         new_avg_variance = self.metainfo[node][
             'variance_adwin'].getEstimation()
         logg.info("PLEXIFLEX,PROBE," + str(node) + "," + str(timelag) +
                   "," +
                   str(self.metainfo[node]['latency_adwin'].length()) +
                   "," + str(new_avg_timelag) + "," + str(new_var_timelag) +
                   "," +
                   str(self.metainfo[node]['variance_adwin'].length()) +
                   "," + str(new_avg_variance))
         tmp = ""
         for c in self.frames["mainstream"].get_cells_of(node):
             tmp += str(c.slot) + "#" + str(c.channel) + ","
         logg.info("PLEXIFLEX,SCHEDULE," + str(node) + "," + tmp)
         if trigger_avg:
             logg.info("PLEXIFLEX,INTERVAL," + str(node) + ",CHANGE")
             if old_avg_timelag < new_avg_timelag:
                 so, co = self.schedule(node, self.dodag.get_parent(node),
                                        self.frames["mainstream"])
                 logg.info("PLEXIFLEX,INTERVAL," + str(node) + ",ADD(" +
                           str(so) + "," + str(co) + ")")
                 if so is not None and co is not None:
                     q.push(
                         self.post_link(so, co, self.frames["mainstream"],
                                        node, self.dodag.get_parent(node)))
             elif old_avg_timelag > new_avg_timelag:
                 cells = self.frames['mainstream'].get_cells_similar_to(
                     owner=node,
                     tna=self.dodag.get_parent(node),
                     link_option=1)
                 if len(cells) > 1:
                     logg.info("PLEXIFLEX,INTERVAL," + str(node) +
                               ",REMOVE")
                     so, co = self.deschedule(node,
                                              self.dodag.get_parent(node),
                                              self.frames["maintenance"])
                     if so is not None and co is not None:
                         q.push(
                             self.delete_link(node,
                                              self.frames["mainstream"], so,
                                              co))
         if trigger_var:
             logg.info("PLEXIFLEX,VARIANCE," + str(node) + ",CHANGE")
             if old_avg_variance < new_avg_variance:
                 so, co = self.schedule(node, self.dodag.get_parent(node),
                                        self.frames["mainstream"])
                 logg.info("PLEXIFLEX,VARIANCE," + str(node) + ",ADD(" +
                           str(so) + "," + str(co) + ")")
                 if so is not None and co is not None:
                     q.push(
                         self.post_link(so, co, self.frames["mainstream"],
                                        node, self.dodag.get_parent(node)))
             elif old_avg_variance > new_avg_variance:
                 cells = self.frames['mainstream'].get_cells_similar_to(
                     owner=node,
                     tna=self.dodag.get_parent(node),
                     link_option=1)
                 if len(cells) > 1:
                     logg.info("PLEXIFLEX,VARIANCE," + str(node) +
                               ",REMOVE")
                     self.deschedule(node, self.dodag.get_parent(node),
                                     self.frames["maintenance"])
                     if so is not None and co is not None:
                         q.push(
                             self.delete_link(node,
                                              self.frames["mainstream"], so,
                                              co))
     return q
Beispiel #14
0
	def framed(self, who, local_name, remote_alias, old_payload):
		q = BlockQueue()
		if who in self.pending_connects and self.metainfo[who]['pending_cells'] is not None and len(self.metainfo[who]['pending_cells']) == 0:
			self.pending_connects.remove(who)
			q.push(self._initiate_schedule(who))
		return q