grpc: updated Interface proto fields to be more consistent with code, ip4mask to ip4_mask, ip6mask to ip6_mask, netid to net_id, flowid to flow_id

This commit is contained in:
Blake Harnden 2020-06-16 22:05:36 -07:00
parent 351b99aae0
commit a1734c3bc0
7 changed files with 40 additions and 35 deletions

View file

@ -127,9 +127,9 @@ class InterfaceHelper:
id=iface_id,
name=iface_data.name,
ip4=iface_data.ip4,
ip4mask=iface_data.ip4_mask,
ip4_mask=iface_data.ip4_mask,
ip6=iface_data.ip6,
ip6mask=iface_data.ip6_mask,
ip6_mask=iface_data.ip6_mask,
mac=iface_data.mac,
)

View file

@ -69,9 +69,9 @@ def link_iface(iface_proto: core_pb2.Interface) -> InterfaceData:
name=name,
mac=mac,
ip4=ip4,
ip4_mask=iface_proto.ip4mask,
ip4_mask=iface_proto.ip4_mask,
ip6=ip6,
ip6_mask=iface_proto.ip6mask,
ip6_mask=iface_proto.ip6_mask,
)
return iface_data
@ -313,9 +313,9 @@ def convert_iface(iface_data: InterfaceData) -> core_pb2.Interface:
name=iface_data.name,
mac=iface_data.mac,
ip4=iface_data.ip4,
ip4mask=iface_data.ip4_mask,
ip4_mask=iface_data.ip4_mask,
ip6=iface_data.ip6,
ip6mask=iface_data.ip6_mask,
ip6_mask=iface_data.ip6_mask,
)
@ -449,30 +449,30 @@ def iface_to_proto(iface: CoreInterface) -> core_pb2.Interface:
if iface.net:
net_id = iface.net.id
ip4 = None
ip4mask = None
ip4_mask = None
ip6 = None
ip6mask = None
ip6_mask = None
for addr in iface.addrlist:
network = netaddr.IPNetwork(addr)
mask = network.prefixlen
ip = str(network.ip)
if netaddr.valid_ipv4(ip) and not ip4:
ip4 = ip
ip4mask = mask
ip4_mask = mask
elif netaddr.valid_ipv6(ip) and not ip6:
ip6 = ip
ip6mask = mask
ip6_mask = mask
return core_pb2.Interface(
id=iface.node_id,
netid=net_id,
net_id=net_id,
name=iface.name,
mac=str(iface.hwaddr),
mac=iface.hwaddr,
mtu=iface.mtu,
flowid=iface.flow_id,
flow_id=iface.flow_id,
ip4=ip4,
ip4mask=ip4mask,
ip4_mask=ip4_mask,
ip6=ip6,
ip6mask=ip6mask,
ip6_mask=ip6_mask,
)

View file

@ -834,7 +834,12 @@ class CoreClient:
iface_id = canvas_node.next_iface_id()
name = f"eth{iface_id}"
iface = core_pb2.Interface(
id=iface_id, name=name, ip4=ip4, ip4mask=ip4_mask, ip6=ip6, ip6mask=ip6_mask
id=iface_id,
name=name,
ip4=ip4,
ip4_mask=ip4_mask,
ip6=ip6,
ip6_mask=ip6_mask,
)
logging.info(
"create node(%s) interface(%s) IPv4(%s) IPv6(%s)",

View file

@ -248,7 +248,7 @@ class NodeConfigDialog(Dialog):
label.grid(row=row, column=0, padx=PADX, pady=PADY)
ip4_net = ""
if iface.ip4:
ip4_net = f"{iface.ip4}/{iface.ip4mask}"
ip4_net = f"{iface.ip4}/{iface.ip4_mask}"
ip4 = tk.StringVar(value=ip4_net)
entry = ttk.Entry(tab, textvariable=ip4, state=state)
entry.grid(row=row, column=1, columnspan=2, sticky="ew")
@ -258,7 +258,7 @@ class NodeConfigDialog(Dialog):
label.grid(row=row, column=0, padx=PADX, pady=PADY)
ip6_net = ""
if iface.ip6:
ip6_net = f"{iface.ip6}/{iface.ip6mask}"
ip6_net = f"{iface.ip6}/{iface.ip6_mask}"
ip6 = tk.StringVar(value=ip6_net)
entry = ttk.Entry(tab, textvariable=ip6, state=state)
entry.grid(row=row, column=1, columnspan=2, sticky="ew")
@ -318,12 +318,12 @@ class NodeConfigDialog(Dialog):
error = True
break
if ip4_net:
ip4, ip4mask = ip4_net.split("/")
ip4mask = int(ip4mask)
ip4, ip4_mask = ip4_net.split("/")
ip4_mask = int(ip4_mask)
else:
ip4, ip4mask = "", 0
ip4, ip4_mask = "", 0
iface.ip4 = ip4
iface.ip4mask = ip4mask
iface.ip4_mask = ip4_mask
# validate ip6
ip6_net = data.ip6.get()
@ -331,12 +331,12 @@ class NodeConfigDialog(Dialog):
error = True
break
if ip6_net:
ip6, ip6mask = ip6_net.split("/")
ip6mask = int(ip6mask)
ip6, ip6_mask = ip6_net.split("/")
ip6_mask = int(ip6_mask)
else:
ip6, ip6mask = "", 0
ip6, ip6_mask = "", 0
iface.ip6 = ip6
iface.ip6mask = ip6mask
iface.ip6_mask = ip6_mask
mac = data.mac.get()
auto_mac = data.is_auto.get()

View file

@ -289,10 +289,10 @@ class CanvasEdge(Edge):
label = f"{iface.name}"
if iface.ip4 and self.canvas.show_ip4s.get():
label = f"{label}\n" if label else ""
label += f"{iface.ip4}/{iface.ip4mask}"
label += f"{iface.ip4}/{iface.ip4_mask}"
if iface.ip6 and self.canvas.show_ip6s.get():
label = f"{label}\n" if label else ""
label += f"{iface.ip6}/{iface.ip6mask}"
label += f"{iface.ip6}/{iface.ip6_mask}"
return label
def create_node_labels(self) -> Tuple[str, str]:

View file

@ -15,7 +15,7 @@ if TYPE_CHECKING:
def get_index(iface: "core_pb2.Interface") -> Optional[int]:
if not iface.ip4:
return None
net = netaddr.IPNetwork(f"{iface.ip4}/{iface.ip4mask}")
net = netaddr.IPNetwork(f"{iface.ip4}/{iface.ip4_mask}")
ip_value = net.value
cidr_value = net.cidr.value
return ip_value - cidr_value
@ -153,10 +153,10 @@ class InterfaceManager:
def get_subnets(self, iface: "core_pb2.Interface") -> Subnets:
ip4_subnet = self.ip4_subnets
if iface.ip4:
ip4_subnet = IPNetwork(f"{iface.ip4}/{iface.ip4mask}").cidr
ip4_subnet = IPNetwork(f"{iface.ip4}/{iface.ip4_mask}").cidr
ip6_subnet = self.ip6_subnets
if iface.ip6:
ip6_subnet = IPNetwork(f"{iface.ip6}/{iface.ip6mask}").cidr
ip6_subnet = IPNetwork(f"{iface.ip6}/{iface.ip6_mask}").cidr
subnets = Subnets(ip4_subnet, ip6_subnet)
return self.used_subnets.get(subnets.key(), subnets)

View file

@ -732,11 +732,11 @@ message Interface {
string name = 2;
string mac = 3;
string ip4 = 4;
int32 ip4mask = 5;
int32 ip4_mask = 5;
string ip6 = 6;
int32 ip6mask = 7;
int32 netid = 8;
int32 flowid = 9;
int32 ip6_mask = 7;
int32 net_id = 8;
int32 flow_id = 9;
int32 mtu = 10;
}