Skip to content

Commit

Permalink
Updated for latest dpservice-cli golang client
Browse files Browse the repository at this point in the history
  • Loading branch information
PlagueCZ committed Aug 2, 2023
1 parent d1db951 commit d63a588
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 55 deletions.
6 changes: 4 additions & 2 deletions src/grpc/dp_grpc_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -860,9 +860,11 @@ static int dp_process_get_version(struct dp_grpc_responder *responder)
struct dpgrpc_versions *reply = dp_grpc_single_reply(responder);

// currently, ignore client's versions and only report what the service supports
static_assert(sizeof(reply->proto) >= sizeof(DP_SERVICE_VERSION));
static_assert(sizeof(reply->proto) >= sizeof(DP_SERVICE_VERSION),
"gRPC protocol's proto version field is too large");
rte_memcpy(reply->proto, DP_SERVICE_VERSION, sizeof(DP_SERVICE_VERSION));
static_assert(sizeof(reply->app) >= sizeof(DP_SERVICE_VERSION));
static_assert(sizeof(reply->app) >= sizeof(DP_SERVICE_VERSION),
"gRPC protocol's app version field is too large");
rte_memcpy(reply->app, DP_SERVICE_VERSION, sizeof(DP_SERVICE_VERSION));
return DP_GRPC_OK;
}
Expand Down
44 changes: 23 additions & 21 deletions test/dp_grpc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def getinterface(self, vm_name):
if not output:
return None
match = re.search(r'(?:^|[\n\r])Interface with ipv4 ([0-9\.]+) ipv6 ([0-9a-fA-F:]+) vni ([0-9]+) pci ([^ ]+) underlayroute ([0-9a-fA-F:]+)', output)
return { 'vni': int(match.group(3)), 'device': match.group(4), 'ips': [ match.group(1), match.group(2) ], 'underlayRoute': match.group(5) }
return { 'vni': int(match.group(3)), 'device': match.group(4), 'primary_ipv4': match.group(1), 'primary_ipv6': match.group(2), 'underlay_route': match.group(5) }

def delinterface(self, vm_name):
self._call(f"--delmachine {vm_name}", "Interface deleted")
Expand All @@ -79,7 +79,7 @@ def listinterfaces(self):
return None
specs = []
for match in re.finditer(r'(?:^|[\n\r])Interface [a-zA-Z0-9_]+ ipv4 ([0-9\.]+) ipv6 ([0-9a-fA-F:]+) vni ([0-9]+) pci ([^ ]+) underlayroute ([0-9a-fA-F:]+)', output):
specs.append({ 'vni': int(match.group(3)), 'device': match.group(4), 'ips': [ match.group(1), match.group(2) ], 'underlayRoute': match.group(5) })
specs.append({ 'vni': int(match.group(3)), 'device': match.group(4), 'primary_ipv4': match.group(1), 'primary_ipv6': match.group(2), 'underlay_route': match.group(5) })
return specs

def addroute(self, vni, prefix, t_vni, t_ipv6):
Expand All @@ -103,7 +103,7 @@ def listroutes(self, vni):
return None
specs = []
for match in re.finditer(r'(?:^|[\n\r])Route prefix ([0-9\.]+) len ([0-9]+) target vni ([0-9]+) target ipv6 ([0-9a-fA-F:]+)', output):
specs.append({ "prefix": match.group(1)+'/'+match.group(2), "nextHop": { "vni": int(match.group(3)), "ip": match.group(4) } })
specs.append({ "prefix": match.group(1)+'/'+match.group(2), "next_hop": { "vni": int(match.group(3)), "address": match.group(4) } })
return specs

def addprefix(self, vm_name, prefix):
Expand All @@ -120,7 +120,7 @@ def listprefixes(self, vm_name):
return None
specs = []
for match in re.finditer(r'(?:^|[\n\r])Route prefix ([0-9\.]+) len ([0-9]+) underlayroute ([0-9a-fA-F:]+)', output):
specs.append({ "prefix": match.group(1)+'/'+match.group(2), "underlayRoute": match.group(3) })
specs.append({ "prefix": match.group(1)+'/'+match.group(2), "underlay_route": match.group(3) })
return specs

def createlb(self, name, vni, vip, portspecs):
Expand All @@ -144,7 +144,7 @@ def getlb(self, name):
elif proto.lower() == 'icmp':
proto = 1
lbports.append({ 'protocol': proto, 'port': int(port) })
return { "vni": int(match.group(1)), "lbVipIP": match.group(3), "lbports": lbports, "underlayRoute": match.group(2) }
return { "vni": int(match.group(1)), "loadbalanced_ip": match.group(3), "loadbalanced_ports": lbports, "underlay_route": match.group(2) }

def dellb(self, name):
self._call(f"--dellb {name}", "LB deleted")
Expand All @@ -161,7 +161,7 @@ def listlbtargets(self, lb_name):
return None
specs = []
for match in re.finditer(r'(?:^|[\n\r])Backend ip ([0-9a-fA-F:]+)', output):
specs.append({ 'targetIP': match.group(1) })
specs.append({ 'target_ip': match.group(1) })
return specs

def addlbprefix(self, vm_name, vip):
Expand All @@ -178,7 +178,7 @@ def listlbprefixes(self, vm_name):
return None
specs = []
for match in re.finditer(r'(?:^|[\n\r])LB Route prefix ([0-9\.]+) len ([0-9]+) underlayroute ([0-9a-fA-F:]+)', output):
specs.append({ "prefix": match.group(1)+'/'+match.group(2), "underlayRoute": match.group(3) })
specs.append({ "prefix": match.group(1)+'/'+match.group(2), "underlay_route": match.group(3) })
return specs

def addvip(self, vm_name, vip):
Expand All @@ -190,7 +190,7 @@ def getvip(self, vm_name):
if not output:
return None
match = re.search(r'Received VIP ([0-9\.]+) underlayroute ([a-f0-9:]+)', output)
return { 'ip': match.group(1), 'underlayRoute': match.group(2) }
return { 'vip_ip': match.group(1), 'underlay_route': match.group(2) }

def delvip(self, vm_name):
self._call(f"--delvip {vm_name}", "VIP deleted")
Expand All @@ -204,7 +204,7 @@ def getnat(self, vm_name):
if not output:
return None
match = re.search(r'Received NAT IP ([0-9\.]+) with min port: ([0-9]+) and max port: ([0-9]+) underlay ([a-f0-9:]+)', output)
return { 'natVIPIP': match.group(1), 'underlayRoute': match.group(4), 'minPort': int(match.group(2)), 'maxPort': int(match.group(3)) }
return { 'nat_ip': match.group(1), 'underlay_route': match.group(4), 'min_port': int(match.group(2)), 'max_port': int(match.group(3)) }

def delnat(self, vm_name):
self._call(f"--delnat {vm_name}", "NAT deleted")
Expand All @@ -215,7 +215,7 @@ def listneighnats(self, nat_vip):
return None
specs = []
for match in re.finditer(r'(?:^|[\n\r]) *[0-9]+: min_port ([0-9]+), max_port ([0-9]+), vni ([0-9]+) --> Underlay IPv6 ([a-f0-9:]+)(?:$|[\n\r])', output):
specs.append({ 'underlayRoute': match.group(4), 'minPort': int(match.group(1)), 'maxPort': int(match.group(2)), 'vni': int(match.group(3)) })
specs.append({ 'underlay_route': match.group(4), 'min_port': int(match.group(1)), 'max_port': int(match.group(2)), 'vni': int(match.group(3)) })
return specs

def addneighnat(self, nat_vip, vni, min_port, max_port, t_ipv6):
Expand Down Expand Up @@ -246,11 +246,12 @@ def getfwallrule(self, vm_name, rule_id):
match = re.search(rule_id + r' / src_ip: ([0-9\.]+) / src_ip pfx length: ([0-9]+) / dst_ip: ([0-9\.]+) / dst_ip pfx length: ([0-9]+) \n'
r'protocol: ([a-z]+) / src_port_min: (\-?[0-9]+) / src_port_max: (\-?[0-9]+) / dst_port_min: (\-?[0-9]+) / dst_port_max: (\-?[0-9]+) \n'
r'direction: ([a-z]+) / action: ([a-z]+)', output)
return { "ruleID": rule_id,
"trafficDirection": match.group(10).capitalize(), "firewallAction": match.group(11).capitalize(), "priority": 1000, "ipVersion": "IPv4",
"sourcePrefix": match.group(1)+'/'+match.group(2), "destinationPrefix": match.group(3)+'/'+match.group(4),
"protocolFilter": { "Filter": { match.group(5).capitalize(): {
"srcPortLower": int(match.group(6)), "srcPortUpper": int(match.group(7)), "dstPortLower": int(match.group(8)), "dstPortUpper": int(match.group(9))
return { "id": rule_id,
"direction": match.group(10).capitalize(), "action": match.group(11).capitalize(), "priority": 1000,
"source_prefix": match.group(1)+'/'+match.group(2), "destination_prefix": match.group(3)+'/'+match.group(4),
"protocol_filter": { "Filter": { match.group(5).capitalize(): {
"src_port_lower": int(match.group(6)), "src_port_upper": int(match.group(7)),
"dst_port_lower": int(match.group(8)), "dst_port_upper": int(match.group(9))
} } } }

def delfwallrule(self, vm_name, rule_id):
Expand All @@ -265,11 +266,12 @@ def listfwallrules(self, vm_name):
for match in re.finditer(r'([a-zA-Z0-9\-_]*) / src_ip: ([0-9\.]+) / src_ip pfx length: ([0-9]+) / dst_ip: ([0-9\.]+) / dst_ip pfx length: ([0-9]+) \n'
r'protocol: ([a-z]+) / src_port_min: (\-?[0-9]+) / src_port_max: (\-?[0-9]+) / dst_port_min: (\-?[0-9]+) / dst_port_max: (\-?[0-9]+) \n'
r'direction: ([a-z]+) / action: ([a-z]+)', output):
specs.append({ "ruleID": match.group(1),
"trafficDirection": match.group(11).capitalize(), "firewallAction": match.group(12).capitalize(), "priority": 1000, "ipVersion": "IPv4",
"sourcePrefix": match.group(2)+'/'+match.group(3), "destinationPrefix": match.group(4)+'/'+match.group(5),
"protocolFilter": { "Filter": { match.group(6).capitalize(): {
"srcPortLower": int(match.group(7)), "srcPortUpper": int(match.group(8)), "dstPortLower": int(match.group(9)), "dstPortUpper": int(match.group(10))
specs.append({ "id": match.group(1),
"direction": match.group(11).capitalize(), "action": match.group(12).capitalize(), "priority": 1000,
"source_prefix": match.group(2)+'/'+match.group(3), "destination_prefix": match.group(4)+'/'+match.group(5),
"protocol_filter": { "Filter": { match.group(6).capitalize(): {
"src_port_lower": int(match.group(7)), "src_port_upper": int(match.group(8)),
"dst_port_lower": int(match.group(9)), "dst_port_upper": int(match.group(10))
} } } })
return specs

Expand All @@ -285,7 +287,7 @@ def resetvni(self, vni):

def getvni(self, vni):
inuse = self.vniinuse(vni)
return { 'inUse': inuse }
return { 'in_use': inuse }


@staticmethod
Expand Down
10 changes: 5 additions & 5 deletions test/grpc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def _call(self, args):
print(" >", output.replace("\n", "\n > "))
response = json.loads(output)
status = response['status']
errcode = status['error']
errcode = status['code']
if errcode != 0:
assert p.returncode == 2, \
"Grpc client process returned invalid error value"
Expand Down Expand Up @@ -89,13 +89,13 @@ def _getSpecList(self, args):

def _getUnderlayRoute(self, args):
spec = self._getSpec(args)
return spec['underlayRoute'] if spec else None
return spec['underlay_route'] if spec else None

def init(self):
self._call("init")

def addinterface(self, vm_name, pci, vni, ipv4, ipv6):
return self._getUnderlayRoute(f"add interface --id={vm_name} --device={pci} --vni={vni} --ip={ipv4} --ip={ipv6}")
return self._getUnderlayRoute(f"add interface --id={vm_name} --device={pci} --vni={vni} --ipv4={ipv4} --ipv6={ipv6}")

def getinterface(self, vm_name):
return self._getSpec(f"get interface --id={vm_name}")
Expand Down Expand Up @@ -170,7 +170,7 @@ def delnat(self, vm_name):
self._call(f"del nat --interface-id={vm_name}")

def listneighnats(self, nat_vip):
return self._getSpecList(f"get natinfo --nat-ip={nat_vip} --info-type=neigh")
return self._getSpecList(f"list nats --nat-ip={nat_vip} --nat-type=neigh")

def addneighnat(self, nat_vip, vni, min_port, max_port, t_ipv6):
self._call(f"add neighnat --nat-ip={nat_vip} --vni={vni} --minport={min_port} --maxport={max_port} --underlayroute={t_ipv6}")
Expand All @@ -184,7 +184,7 @@ def addfwallrule(self, vm_name, rule_id,
action="accept", direction="ingress", priority=None):
protospec = "" if proto is None else f"--protocol={proto}"
priospec = "" if priority is None else f"--priority={priority}"
self._call(f"add fwrule --interface-id={vm_name} --rule-id={rule_id} --ipver=ipv4 --src={src_prefix} --dst={dst_prefix} {protospec}"
self._call(f"add fwrule --interface-id={vm_name} --rule-id={rule_id} --src={src_prefix} --dst={dst_prefix} {protospec}"
f" --src-port-min={src_port_min} --src-port-max={src_port_max} --dst-port-min={dst_port_min} --dst-port-max={dst_port_max}"
f" --action={action} --direction={direction} {priospec}")

Expand Down
8 changes: 4 additions & 4 deletions test/test_nat.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ def test_network_nat_pkt_relay(prepare_ifaces, grpc_client):
assert dst_ip == neigh_vni1_ul_ipv6 and dport == 510, \
f"Wrong network-nat relayed packet (outer dst ipv6: {dst_ip}, dport: {dport})"

localspec = { 'natVIPIP': nat_vip, 'underlayRoute': nat_ul_ipv6, 'minPort': nat_local_min_port, 'maxPort': nat_local_max_port }
localspec = { 'nat_ip': nat_vip, 'underlay_route': nat_ul_ipv6, 'min_port': nat_local_min_port, 'max_port': nat_local_max_port }
spec = grpc_client.getnat(VM1.name)
assert spec == localspec, \
"Failed to add NAT properly"

neighspec = { 'underlayRoute': neigh_vni1_ul_ipv6, 'minPort': nat_neigh_min_port, 'maxPort': nat_neigh_max_port, 'vni': vni1 }
neighspec = { 'underlay_route': neigh_vni1_ul_ipv6, 'min_port': nat_neigh_min_port, 'max_port': nat_neigh_max_port, 'vni': vni1 }
specs = grpc_client.listneighnats(nat_vip)
assert specs == [neighspec], \
"Invalid neighboring NAT list"
Expand Down Expand Up @@ -96,12 +96,12 @@ def test_network_nat_vip_co_existence_on_same_vm(prepare_ifaces, grpc_client):
vip_ul_ipv6 = grpc_client.addvip(VM1.name, vip_vip)
nat_ul_ipv6 = grpc_client.addnat(VM1.name, nat_vip, nat_local_min_port, nat_local_max_port)

natspec = { 'natVIPIP': nat_vip, 'underlayRoute': nat_ul_ipv6, 'minPort': nat_local_min_port, 'maxPort': nat_local_max_port }
natspec = { 'nat_ip': nat_vip, 'underlay_route': nat_ul_ipv6, 'min_port': nat_local_min_port, 'max_port': nat_local_max_port }
spec = grpc_client.getnat(VM1.name)
assert spec == natspec, \
"Failed to add NAT properly"

vipspec = { 'ip': vip_vip, 'underlayRoute': vip_ul_ipv6 }
vipspec = { 'vip_ip': vip_vip, 'underlay_route': vip_ul_ipv6 }
spec = grpc_client.getvip(VM1.name)
assert spec == vipspec, \
"Failed to add VIP properly"
Expand Down
10 changes: 5 additions & 5 deletions test/test_vni.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@

def test_vni_existence(prepare_ipv4, grpc_client):
lb_ul_ipv6 = grpc_client.createlb(lb_name, vni3, lb_ip, "tcp/80")
assert grpc_client.getvni(vni3)['inUse'], \
assert grpc_client.getvni(vni3)['in_use'], \
f"VNI {vni3} should be in use"

grpc_client.addinterface(VM4.name, VM4.pci, vni3, VM4.ip, VM4.ipv6)
assert grpc_client.getvni(vni3)['inUse'], \
assert grpc_client.getvni(vni3)['in_use'], \
f"VNI {vni3} should be in use"

grpc_client.delinterface(VM4.name)
assert grpc_client.getvni(vni3)['inUse'], \
assert grpc_client.getvni(vni3)['in_use'], \
f"VNI {vni3} should be in use"

grpc_client.dellb(lb_name)
assert not grpc_client.getvni(vni3)['inUse'], \
assert not grpc_client.getvni(vni3)['in_use'], \
f"VNI {vni3} should not be in use anymore"


Expand All @@ -27,7 +27,7 @@ def test_vni_reset(prepare_ipv4, grpc_client):
grpc_client.resetvni(999)

# This is intentionally the same as in VNI1 (see the last test)
routespec = { "prefix": neigh_vni1_ov_ip_route, "nextHop": { "vni": 0, "ip": neigh_vni1_ul_ipv6 } }
routespec = { "prefix": neigh_vni1_ov_ip_route, "next_hop": { "vni": 0, "address": neigh_vni1_ul_ipv6 } }
routes = grpc_client.listroutes(vni3)
assert routespec in routes, \
"List of routes does not contain the added route"
Expand Down
Loading

0 comments on commit d63a588

Please sign in to comment.