def test_dict_to_protobuf(self): pb = bess_msg.CreatePortResponse() pb.error.err = 1 pb.error.errmsg = 'bar' pb.error.details = '' pb.name = 'foo' msg_dict = { 'error': { 'err': 1, 'errmsg': 'bar', }, 'name': 'foo' } msg = proto_conv.dict_to_protobuf(msg_dict, bess_msg.CreatePortResponse) self.assertEqual(msg, pb) pb = bess_msg.CreateModuleRequest() pb.name = 'm1' pb.mclass = 'bpf' kv = { 'name': 'm1', 'mclass': 'bpf', } msg = proto_conv.dict_to_protobuf(kv, bess_msg.CreateModuleRequest) self.assertEqual(msg, pb)
def create_port(self, driver, name, arg): num_inc_q = arg.pop('num_inc_q', 0) num_out_q = arg.pop('num_out_q', 0) size_inc_q = arg.pop('size_inc_q', 0) size_out_q = arg.pop('size_out_q', 0) mac_addr = arg.pop('mac_addr', '') kv = { 'name': name, 'driver': driver, 'num_inc_q': num_inc_q, 'num_out_q': num_out_q, 'size_inc_q': size_inc_q, 'size_out_q': size_out_q, 'mac_addr': mac_addr, } request = proto_conv.dict_to_protobuf(kv, bess_msg.CreatePortRequest) message_map = { 'PCAPPort': port_msg.PCAPPortArg, 'PMDPort': port_msg.PMDPortArg, 'UnixSocketPort': port_msg.UnixSocketPortArg, 'ZeroCopyVPort': port_msg.ZeroCopyVPortArg, 'VPort': port_msg.VPortArg, } arg_msg = proto_conv.dict_to_protobuf(arg, message_map[driver]) request.arg.Pack(arg_msg) return self._request('CreatePort', request)
def create_port(self, driver, name, arg): if arg == None: arg = {} num_inc_q = arg.pop('num_inc_q', 0) num_out_q = arg.pop('num_out_q', 0) size_inc_q = arg.pop('size_inc_q', 0) size_out_q = arg.pop('size_out_q', 0) mac_addr = arg.pop('mac_addr', '') kv = { 'name': name, 'driver': driver, 'num_inc_q': num_inc_q, 'num_out_q': num_out_q, 'size_inc_q': size_inc_q, 'size_out_q': size_out_q, 'mac_addr': mac_addr, } request = proto_conv.dict_to_protobuf(kv, bess_msg.CreatePortRequest) message_type = getattr(port_msg, driver + 'Arg', bess_msg.EmptyArg) arg_msg = proto_conv.dict_to_protobuf(arg, message_type) request.arg.Pack(arg_msg) return self._request('CreatePort', request)
def create_port(self, driver, name, arg): num_inc_q = arg.pop('num_inc_q', 0) num_out_q = arg.pop('num_out_q', 0) size_inc_q = arg.pop('size_inc_q', 0) size_out_q = arg.pop('size_out_q', 0) mac_addr = arg.pop('mac_addr', '') kv = { 'name': name, 'driver': driver, 'num_inc_q': num_inc_q, 'num_out_q': num_out_q, 'size_inc_q': size_inc_q, 'size_out_q': size_out_q, 'mac_addr': mac_addr, } request = proto_conv.dict_to_protobuf(kv, bess_msg.CreatePortRequest) message_map = { 'PCAPPort': port_msg.PCAPPortArg, 'PMDPort': port_msg.PMDPortArg, 'UnixSocketPort': port_msg.UnixSocketPortArg, 'ZeroCopyVPort': port_msg.ZeroCopyVPortArg, 'VPort': port_msg.VPortArg, } arg_msg = proto_conv.dict_to_protobuf(arg, message_map[driver]) request.arg.Pack(arg_msg) return self._request(self.stub.CreatePort, request)
def create_module(self, mclass, name=None, arg=None): kv = { 'name': name, 'mclass': mclass, } request = proto_conv.dict_to_protobuf(kv, bess_msg.CreateModuleRequest) message_type = getattr(module_msg, mclass + 'Arg', bess_msg.EmptyArg) arg_msg = proto_conv.dict_to_protobuf(arg, message_type) request.arg.Pack(arg_msg) return self._request('CreateModule', request)
def create_module(self, mclass, name=None, arg=None): kv = { 'name': name, 'mclass': mclass, } request = proto_conv.dict_to_protobuf(kv, bess_msg.CreateModuleRequest) message_map = { 'ACL': module_msg.ACLArg, 'BPF': module_msg.BPFArg, 'Buffer': bess_msg.EmptyArg, 'Bypass': bess_msg.EmptyArg, 'Dump': module_msg.DumpArg, 'EtherEncap': bess_msg.EmptyArg, 'ExactMatch': module_msg.ExactMatchArg, 'FlowGen': module_msg.FlowGenArg, 'GenericDecap': module_msg.GenericDecapArg, 'GenericEncap': module_msg.GenericEncapArg, 'HashLB': module_msg.HashLBArg, 'IPChecksum': bess_msg.EmptyArg, 'IPEncap': bess_msg.EmptyArg, 'IPLookup': bess_msg.EmptyArg, 'IPSwap': bess_msg.EmptyArg, 'L2Forward': module_msg.L2ForwardArg, 'MACSwap': bess_msg.EmptyArg, 'Measure': module_msg.MeasureArg, 'Merge': bess_msg.EmptyArg, 'MetadataTest': module_msg.MetadataTestArg, 'NAT': module_msg.NATArg, 'NoOP': bess_msg.EmptyArg, 'PortInc': module_msg.PortIncArg, 'PortOut': module_msg.PortOutArg, 'QueueInc': module_msg.QueueIncArg, 'QueueOut': module_msg.QueueOutArg, 'Queue': module_msg.QueueArg, 'RandomUpdate': module_msg.RandomUpdateArg, 'Rewrite': module_msg.RewriteArg, 'RoundRobin': module_msg.RoundRobinArg, 'SetMetadata': module_msg.SetMetadataArg, 'Sink': bess_msg.EmptyArg, 'Source': module_msg.SourceArg, 'Split': module_msg.SplitArg, 'Timestamp': bess_msg.EmptyArg, 'Update': module_msg.UpdateArg, 'UrlFilter': module_msg.UrlFilterArg, 'VLANPop': bess_msg.EmptyArg, 'VLANPush': module_msg.VLANPushArg, 'VLANSplit': bess_msg.EmptyArg, 'VXLANDecap': bess_msg.EmptyArg, 'VXLANEncap': module_msg.VXLANEncapArg, 'WildcardMatch': module_msg.WildcardMatchArg, } arg_msg = proto_conv.dict_to_protobuf(arg, message_map[mclass]) request.arg.Pack(arg_msg) return self._request('CreateModule', request)
def create_module(self, mclass, name, arg): kv = { 'name': name, 'mclass': mclass, } request = proto_conv.dict_to_protobuf(kv, bess_msg.CreateModuleRequest) message_map = { 'BPF': module_msg.BPFArg, 'Buffer': bess_msg.EmptyArg, 'Bypass': bess_msg.EmptyArg, 'Dump': module_msg.DumpArg, 'EtherEncap': bess_msg.EmptyArg, 'ExactMatch': module_msg.ExactMatchArg, 'FlowGen': module_msg.FlowGenArg, 'GenericDecap': module_msg.GenericDecapArg, 'GenericEncap': module_msg.GenericEncapArg, 'HashLB': module_msg.HashLBArg, 'IPEncap': bess_msg.EmptyArg, 'IPLookup': bess_msg.EmptyArg, 'L2Forward': module_msg.L2ForwardArg, 'MACSwap': bess_msg.EmptyArg, 'Measure': module_msg.MeasureArg, 'Merge': bess_msg.EmptyArg, 'MetadataTest': module_msg.MetadataTestArg, 'NoOP': bess_msg.EmptyArg, 'PortInc': module_msg.PortIncArg, 'PortOut': module_msg.PortOutArg, 'QueueInc': module_msg.QueueIncArg, 'QueueOut': module_msg.QueueOutArg, 'Queue': module_msg.QueueArg, 'RandomUpdate': module_msg.RandomUpdateArg, 'Rewrite': module_msg.RewriteArg, 'RoundRobin': module_msg.RoundRobinArg, 'SetMetadata': module_msg.SetMetadataArg, 'Sink': bess_msg.EmptyArg, 'Source': module_msg.SourceArg, 'Split': module_msg.SplitArg, 'Timestamp': bess_msg.EmptyArg, 'Update': module_msg.UpdateArg, 'VLANPop': bess_msg.EmptyArg, 'VLANPush': module_msg.VLANPushArg, 'VLANSplit': bess_msg.EmptyArg, 'VXLANDecap': bess_msg.EmptyArg, 'VXLANEncap': module_msg.VXLANEncapArg, 'WildcardMatch': module_msg.WildcardMatchArg, } arg_msg = proto_conv.dict_to_protobuf(arg, message_map[mclass]) request.arg.Pack(arg_msg) return self._request(self.stub.CreateModule, request)
def run_module_command(self, name, cmd, arg_type, arg): request = bess_msg.ModuleCommandRequest() request.name = name request.cmd = cmd message_type = getattr(module_msg, arg_type, bess_msg.EmptyArg) arg_msg = proto_conv.dict_to_protobuf(arg, message_type) request.arg.Pack(arg_msg) response = self._request('ModuleCommand', request) if response.HasField('other'): response_type_str = response.other.type_url.split('.')[-1] response_type = getattr(module_msg, response_type_str, bess_msg.EmptyArg) result = response_type() response.other.Unpack(result) return result else: return response
def run_module_command(self, name, cmd, arg_type, arg): request = bess_msg.ModuleCommandRequest() request.name = name request.cmd = cmd all_classes = inspect.getmembers(module_msg, lambda c: inspect.isclass(c)) arg_classes = dict(all_classes) arg_classes['EmptyArg'] = bess_msg.EmptyArg arg_msg = proto_conv.dict_to_protobuf(arg, arg_classes[arg_type]) request.arg.Pack(arg_msg) response = self._request('ModuleCommand', request) if response.HasField('other'): type_str = response.other.type_url.split('.')[-1] type_class = arg_classes[type_str] result = type_class() response.other.Unpack(result) return result else: return response
def run_module_command(self, name, cmd, arg_type, arg): request = bess_msg.ModuleCommandRequest() request.name = name request.cmd = cmd all_classes = inspect.getmembers(module_msg, lambda c: inspect.isclass(c)) arg_classes = dict(all_classes) arg_classes['EmptyArg'] = bess_msg.EmptyArg arg_msg = proto_conv.dict_to_protobuf(arg, arg_classes[arg_type]) request.arg.Pack(arg_msg) response = self._request(self.stub.ModuleCommand, request) if response.HasField('other'): type_str = response.other.type_url.split('.')[-1] type_class = arg_classes[type_str] result = type_class() response.other.Unpack(result) return result else: return response