def __init__(self): self.applications_cls = {} # 记录app self.applications = {} self.contexts_cls = {} self.contexts = {} self.close_sem = hub.Semaphore()
def __init__(self): self.applications_cls = {} self.applications = {} self.contexts_cls = {} self.contexts = {} self.close_sem = hub.Semaphore() #modify by hmily self.CONF = cfg.CONF if self.CONF.enable_debugger: LOG.setLevel(logging.DEBUG) # prevent accidental creation of instances of this class outside RyuApp class _EventThreadStop(event.EventBase): pass self._event_stop = _EventThreadStop() self.is_active = True
def init_node(self, datapath): """ 初始化交換機節點在拓樸 """ node_id = (datapath.id, None) if not GLOBAL_VALUE.G.has_node(node_id): GLOBAL_VALUE.G.add_node(node_id) GLOBAL_VALUE.G.nodes[node_id]["datapath"] = datapath GLOBAL_VALUE.G.nodes[node_id]["port"] = nested_dict() GLOBAL_VALUE.G.nodes[node_id]["all_port_duration_s_temp"] = 0 GLOBAL_VALUE.G.nodes[node_id]["all_port_duration_s"] = 0 GLOBAL_VALUE.G.nodes[node_id]["FLOW_TABLE"] = nested_dict() GLOBAL_VALUE.G.nodes[node_id]["now_max_group_id"] = 0 # 這個是在傳送openflow協定的時候標示的xid,當發生錯誤的時候交換機會回傳同個xid,讓我們知道剛剛哪個傳送的openflow發生錯誤 GLOBAL_VALUE.G.nodes[node_id]["now_max_xid"] = 0 GLOBAL_VALUE.G.nodes[(datapath.id, None) ]["GROUP_TABLE"] = nested_dict() GLOBAL_VALUE.barrier_lock[datapath.id]=hub.Semaphore(1)
def _compare_spec(self): # Take a snapshot of the current topology with hub.Semaphore(): graph = self.graph.copy() self.logger.info("---------------------------------------------------") types = nx.get_node_attributes(self.spec.graph, "typ") names = nx.get_node_attributes(self.spec.graph, "name") node_errors = [] for node in set(self.spec.graph) - set(graph): if types[node] == "switch": node_errors.append("Switch {0} not present".format( names[node])) elif types[node] == "host": node_errors.append("Host {0} not present".format(names[node])) edge_errors = [] for edge in self.spec.graph.edges(): if not graph.has_edge(*edge): edge_errors.append("Link {0} - {1} not present".format( names[edge[0]], names[edge[1]])) if not node_errors and not edge_errors: self.logger.info("Topology conforms to spec") else: self.logger.error("Topology does not conform to spec") self.logger.error("Switches/Hosts:") for error in node_errors: self.logger.error("\t{0}".format(error)) self.logger.error("\t{0} checked, {1} failures".format( nx.number_of_nodes(self.spec.graph), len(node_errors))) self.logger.error("Links:") for error in edge_errors: self.logger.error(" {0}".format(error)) self.logger.error("\t{0} checked, {1} failures".format( nx.number_of_edges(self.spec.graph), len(edge_errors)))
def _topology_updated(self): self.logger.debug("Topology change detected: waiting to converge") with hub.Semaphore(): self._thread.cancel() self._thread = hub.spawn_after(3, self._compare_spec)
from ryu.ofproto import ofproto_v1_5 # for RYU decorator doing catch Event from ryu.controller.handler import set_ev_cls from ryu.controller.handler import HANDSHAKE_DISPATCHER, CONFIG_DISPATCHER, MAIN_DISPATCHER, DEAD_DISPATCHER from ryu.controller import ofp_event from ryu.lib.packet import ethernet, arp, icmp, ipv4 from ryu.lib.packet import ether_types, in_proto, icmpv6 from ryu.lib.packet import lldp from ryu.lib.packet import packet from ryu.utils import hex_array from ryu.lib import hub from ryu import cfg from nested_dict import * """當你要自創權重名稱 需要在這裡註冊以便初始化""" weight_name_regist = ["weight", "ppinin"] route_control_sem = hub.Semaphore(1) active_route_run = False #是否需要主動模塊 active_rl_in_active_route = True #是否需要啟動強化學習 rl_accept_tos = [192, 111] #設定哪些tos需要強化學習優化 如果全部需要強化學習優化會導致啟動緩慢 因為action過大 """當從強化學習拿到策略才需要開始更新""" FLOW_ENTRY_IDLE_TIMEOUT = 0 #sec 0代表沒有TIMEOUT """當flow entry多久沒有流量就就可刪除""" MAX_K_SELECT_PATH = 4 #k shortest path最多選擇幾條多路徑 """計算reward需要先告訴公式範圍多少""" MAX_Loss_Percent = 0.2 MAX_Jitter_ms = 200 #ms 需要預設最大的jitter可能範圍 MAX_DELAY_ms = 50 #ms需要預設最大的jitter可能範圍 MAX_DELAY_TO_LOSS_ms = 1000 #ms