def connect(self, io_master): if self.mode != "tcp": raise RuntimeError("only tcp (active) mode supported by now") socket = connect_socket_with_backoff(self.host, self.port) self.io_delegate = SyncIODelegate(io_master, socket) self.speaker = STSSyncProtocolSpeaker(controller=self.controller, state_master=self.state_master, io_delegate=self.io_delegate)
def wait_for_connect(self): log.info("waiting for sts_sync connection on %s:%d" % (self.host, self.port)) (socket, _) = self.listen_socket.accept() log.info("sts_sync connected") self.speaker = POXSyncProtocolSpeaker( SyncIODelegate(self.io_master, socket))
class STSSyncConnection(object): """ A connection to a controller with the sts sync protocol """ def __init__(self, controller, state_master, sync_uri): self.controller = controller (self.mode, self.host, self.port) = parse_openflow_uri(sync_uri) if state_master is None: raise ValueError("state_master is null") self.state_master = state_master self._on_disconnect = [] self.io_delegate = None self.speaker = None def on_disconnect(self, func): self._on_disconnect.append(func) def connect(self, io_master): if self.mode != "tcp": raise RuntimeError("only tcp (active) mode supported by now") socket = connect_socket_with_backoff(self.host, self.port) self.io_delegate = SyncIODelegate(io_master, socket) self.speaker = STSSyncProtocolSpeaker(controller=self.controller, state_master=self.state_master, io_delegate=self.io_delegate) def disconnect(self): self.io_delegate.close() for handler in self._on_disconnect: handler(self) def close(self): self.disconnect() def get_nom_snapshot(self): if self.speaker: return self.speaker.sync_request("NOMSnapshot", "", timeout=10) else: log.warn("STSSyncConnection: not connected. cannot handle requests") def send_link_notification(self, link_attrs): # Link attrs must be a list of the form: # [dpid1, port1, dpid2, port2] if self.speaker: msg = SyncMessage(type="ASYNC", messageClass="LinkDiscovery", value=link_attrs) return self.speaker.send(msg) else: log.warn("STSSyncConnection: not connected. cannot send link") def ack_sync_notification(self, messageClass, xid): if self.speaker: return self.speaker.ack_sync_notification(messageClass, xid) else: log.warn("STSSyncConnection: not connected. cannot ACK") def send_deterministic_value(self, xid, value): if self.speaker: msg = SyncMessage(type="RESPONSE", messageClass="DeterministicValue", time=value, xid=xid, value=value) return self.speaker.send(msg) else: log.warn("STSSyncConnection: not connected. cannot ACK")
class STSSyncConnection(object): """ A connection to a controller with the sts sync protocol """ def __init__(self, controller, state_master, sync_uri): self.controller = controller (self.mode, self.host, self.port) = parse_openflow_uri(sync_uri) if state_master is None: raise ValueError("state_master is null") self.state_master = state_master self._on_disconnect = [] self.io_delegate = None self.speaker = None def on_disconnect(self, func): self._on_disconnect.append(func) def connect(self, io_master): if self.mode != "tcp": raise RuntimeError("only tcp (active) mode supported by now") socket = connect_socket_with_backoff(self.host, self.port) self.io_delegate = SyncIODelegate(io_master, socket) self.speaker = STSSyncProtocolSpeaker(controller=self.controller, state_master=self.state_master, io_delegate=self.io_delegate) def disconnect(self): self.io_delegate.close() for handler in self._on_disconnect: handler(self) def close(self): self.disconnect() def get_nom_snapshot(self): if self.speaker: return self.speaker.sync_request("NOMSnapshot", "", timeout=10) else: log.warn( "STSSyncConnection: not connected. cannot handle requests") def send_link_notification(self, link_attrs): # Link attrs must be a list of the form: # [dpid1, port1, dpid2, port2] if self.speaker: msg = SyncMessage(type="ASYNC", messageClass="LinkDiscovery", value=link_attrs) return self.speaker.send(msg) else: log.warn("STSSyncConnection: not connected. cannot send link") def ack_sync_notification(self, messageClass, xid): if self.speaker: return self.speaker.ack_sync_notification(messageClass, xid) else: log.warn("STSSyncConnection: not connected. cannot ACK") def send_deterministic_value(self, xid, value): if self.speaker: msg = SyncMessage(type="RESPONSE", messageClass="DeterministicValue", time=value, xid=xid, value=value) return self.speaker.send(msg) else: log.warn("STSSyncConnection: not connected. cannot ACK")