def del_traffic_rule(self, match): """Delete a traffic rule from this tenant. Args: match, a Match object Returns: None Raises: None """ rule = Session().query(TblTrafficRule) \ .filter(TblTrafficRule.tenant_id == self.tenant_id, TblTrafficRule.match == match) \ .first() if not rule: raise KeyError(rule) # Send command to IBN from empower.ibnp.ibnpserver import IBNPServer ibnp_server = get_module(IBNPServer.__module__) if ibnp_server: ibnp_server.del_traffic_rule(self.tenant_id, match) session = Session() session.delete(rule) session.commit()
def _remove_intent(cls, uuid): """Remove intent.""" from empower.ibnp.ibnpserver import IBNPServer ibnp_server = get_module(IBNPServer.__module__) if ibnp_server and ibnp_server.connection: ibnp_server.connection.send_remove_endpoint(uuid)
def update_db(self, samples): """Update InfluxDB with the latest measurements""" from empower.statssender.statssender import StatsSender stats_sender = get_module(StatsSender.__module__) if stats_sender: stats_sender.send_stat(points=samples, database=self.MODULE_NAME, time_precision='u')
def __setitem__(self, key, value): """Set virtual port configuration.""" if value and not isinstance(value, VirtualPort): raise KeyError("Expected VirtualPort, got %s" % type(key)) # remove virtual link if self.__contains__(key): self.__delitem__(key) self.__uuids__[key] = None from empower.ibnp.ibnpserver import IBNPServer ibnp_server = get_module(IBNPServer.__module__) rule_uuid = uuid4() match = Match(key) self.my_virtual_port.network_port.add_match(match, rule_uuid) priority = None if 'priority' in match.match: priority = int(match.match['priority']) del match.match['priority'] # set/update intent intent = { 'version': '1.0', 'uuid': rule_uuid, 'ttp_uuid': value.endpoint.uuid, 'ttp_vport': value.virtual_port_id, 'stp_uuid': self.my_virtual_port.endpoint.uuid, 'stp_vport': self.my_virtual_port.virtual_port_id, 'match': match.match } # custom priorities start at 250 in Ryu, the priority value is summed if priority is not None: intent['priority'] = priority # add new virtual link if key in self.__uuids__: if ibnp_server.connection: ibnp_server.connection.send_add_rule(intent) else: LOG.warning('IBN not available') self.__uuids__[key] = rule_uuid # add entry dict.__setitem__(self, key, value)
def _update_intent(self): """Set/update intent.""" endpoint_ports = {} for vport_id, vport in self.items(): props = {'dont_learn': vport.dont_learn} endpoint_ports[vport_id] = {'port_no': vport.network_port.port_id, 'properties': props} intent = {'version': '1.0', 'uuid': self.endpoint.uuid, 'dpid': self.endpoint.datapath.dpid, 'ports': endpoint_ports} from empower.ibnp.ibnpserver import IBNPServer ibnp_server = get_module(IBNPServer.__module__) if ibnp_server and ibnp_server.connection: ibnp_server.connection.send_update_endpoint(intent)
def __delitem__(self, key): """Clear virtual port configuration.""" from empower.ibnp.ibnpserver import IBNPServer ibnp_server = get_module(IBNPServer.__module__) # remove virtual links if key in self.__uuids__: if ibnp_server.connection: ibnp_server.connection.send_remove_rule(self.__uuids__[key]) else: LOG.warning('IBN not available') self.my_virtual_port.network_port.remove_match(self.__uuids__[key]) del self.__uuids__[key] # remove old entry dict.__delitem__(self, key)
def initialize(self, server): self.server = server self.of_dpid = [] self.dpid2ep = {} self.of_rules = {} # map from dscp values to tos self.dscp2tos = { '0x00': '0x00', '0x01': '0x04', '0x02': '0x08', '0x03': '0x0C', '0x04': '0x10', '0x08': '0x20', '0x0A': '0x28', '0x0C': '0x30', '0x0E': '0x38', '0x10': '0x40', '0x12': '0x48', '0x14': '0x50', '0x16': '0x58', '0x18': '0x60', '0x1A': '0x68', '0x1C': '0x70', '0x1E': '0x78', '0x20': '0x80', '0x22': '0x88', '0x24': '0x90', '0x26': '0x98', '0x28': '0xA0', '0x2C': '0xB0', '0x2E': '0xB8', '0x30': '0xC0', '0x38': '0xE0' } lvapp_server = get_module(LVAPPServer.__module__) lvapp_server.register_message(PT_LVAP_JOIN, None, self._lvap_join) lvapp_server.register_message(PT_LVAP_LEAVE, None, self._lvap_leave) lvapp_server.register_message(PT_LVAP_HANDOVER, None, self._lvap_handover)
def add_traffic_rule(self, match, dscp, label, priority=0): """Add a new traffic rule to the Tenant. Args: match, a Match object dscp, a slice DSCP code label, a humand readable description of the rule Returns: None Raises: Nones """ trule = TrafficRule(tenant=self, match=match, dscp=dscp, priority=priority, label=label) # Send command to IBN from empower.ibnp.ibnpserver import IBNPServer ibnp_server = get_module(IBNPServer.__module__) if ibnp_server: ibnp_server.add_traffic_rule(trule) rule = TblTrafficRule(tenant_id=self.tenant_id, match=match, dscp=dscp, priority=priority, label=label) try: session = Session() session.add(rule) session.commit() except IntegrityError: session.rollback() raise ValueError("Duplicate (%s, %s)" % (self.tenant_id, match))