def serialize_ofp_phy_port(port): """ Serializes OpenFlow physical port to JSON Dict """ attrs = ['port_no', 'hw_addr', 'name', 'config', 'state', 'curr', 'advertised', 'supported', 'peer'] json_dict = {'__type__': object_fullname(port)} print class_fullname(ofp_phy_port) for attr in attrs: value = getattr(port, attr, None) if hasattr(value, 'toStr'): value = value.toStr() json_dict[attr] = value return json_dict
def serialize_ofp_phy_port(port): """ Serializes OpenFlow physical port to JSON Dict """ attrs = [ 'port_no', 'hw_addr', 'name', 'config', 'state', 'curr', 'advertised', 'supported', 'peer' ] json_dict = {'__type__': object_fullname(port)} print class_fullname(ofp_phy_port) for attr in attrs: value = getattr(port, attr, None) if hasattr(value, 'toStr'): value = value.toStr() json_dict[attr] = value return json_dict
def deserialize_ofp_phy_port(cls, json_dict): """ De-Serializes JSON Dict to OpenFlow physical port """ assert json_dict['__type__'] == class_fullname(cls) json_dict.pop('__type__') port = cls(**json_dict) return port
def from_json(cls, json_hash): """Create HostInterface Instance from JSON Dict""" assert class_fullname(cls) == json_hash['__type__'] name = json_hash['name'] ips = [] for ip in json_hash['ips']: ips.append(IPAddr(str(ip))) hw_addr = EthAddr(json_hash['hw_addr']) return cls(hw_addr, ip_or_ips=ips, name=name)
def from_json(cls, json_hash, interface_cls=None): name = json_hash['name'] hid = json_hash['hid'] interfaces = [] for iface in json_hash['interfaces']: if interface_cls is None: interface_cls = load_class(iface['__type__']) else: iface['__type__'] = class_fullname(interface_cls) interfaces.append(interface_cls.from_json(iface)) return cls(interfaces, name, hid)
def from_json(cls, json_dict): assert class_fullname(cls) == json_dict['__type__'] node1 = json_dict['node1'] port1 = json_dict['port1'] node2 = json_dict['node2'] port2 = json_dict['port2'] if isinstance(node1, dict) and node1.get('__type__', None): node1 = load_class(node1['__type__']).from_json(node1) if isinstance(port1, dict) and port1.get('__type__', None): port1 = load_class(port1['__type__']).from_json(port1) if isinstance(node2, dict) and node2.get('__type__', None): node2 = load_class(node2['__type__']).from_json(node2) if isinstance(port2, dict) and port2.get('__type__', None): port2 = load_class(port2['__type__']).from_json(port2) return cls(node1, port1, node2, port2)
def from_json(cls, json_dict): assert class_fullname(cls) == json_dict['__type__'] start_node = json_dict['start_node'] start_port = json_dict['start_port'] end_node = json_dict['end_node'] end_port = json_dict['end_port'] if isinstance(start_node, dict) and start_node.get('__type__', None): start_node = load_class(start_node['__type__']).from_json(start_node) if isinstance(start_port, dict) and start_port.get('__type__', None): start_port = load_class(start_port['__type__']).from_json(start_port) if isinstance(end_node, dict) and end_node.get('__type__', None): end_node = load_class(end_node['__type__']).from_json(end_node) if isinstance(end_port, dict) and end_port.get('__type__', None): end_port = load_class(end_port['__type__']).from_json(end_port) return cls(start_node, start_port, end_node, end_port)
def from_json(cls, json_dict): assert class_fullname(cls) == json_dict['__type__'] start_node = json_dict['start_node'] start_port = json_dict['start_port'] end_node = json_dict['end_node'] end_port = json_dict['end_port'] if isinstance(start_node, dict) and start_node.get('__type__', None): start_node = load_class( start_node['__type__']).from_json(start_node) if isinstance(start_port, dict) and start_port.get('__type__', None): start_port = load_class( start_port['__type__']).from_json(start_port) if isinstance(end_node, dict) and end_node.get('__type__', None): end_node = load_class(end_node['__type__']).from_json(end_node) if isinstance(end_port, dict) and end_port.get('__type__', None): end_port = load_class(end_port['__type__']).from_json(end_port) return cls(start_node, start_port, end_node, end_port)