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:
parent
351b99aae0
commit
a1734c3bc0
7 changed files with 40 additions and 35 deletions
|
@ -127,9 +127,9 @@ class InterfaceHelper:
|
||||||
id=iface_id,
|
id=iface_id,
|
||||||
name=iface_data.name,
|
name=iface_data.name,
|
||||||
ip4=iface_data.ip4,
|
ip4=iface_data.ip4,
|
||||||
ip4mask=iface_data.ip4_mask,
|
ip4_mask=iface_data.ip4_mask,
|
||||||
ip6=iface_data.ip6,
|
ip6=iface_data.ip6,
|
||||||
ip6mask=iface_data.ip6_mask,
|
ip6_mask=iface_data.ip6_mask,
|
||||||
mac=iface_data.mac,
|
mac=iface_data.mac,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -69,9 +69,9 @@ def link_iface(iface_proto: core_pb2.Interface) -> InterfaceData:
|
||||||
name=name,
|
name=name,
|
||||||
mac=mac,
|
mac=mac,
|
||||||
ip4=ip4,
|
ip4=ip4,
|
||||||
ip4_mask=iface_proto.ip4mask,
|
ip4_mask=iface_proto.ip4_mask,
|
||||||
ip6=ip6,
|
ip6=ip6,
|
||||||
ip6_mask=iface_proto.ip6mask,
|
ip6_mask=iface_proto.ip6_mask,
|
||||||
)
|
)
|
||||||
return iface_data
|
return iface_data
|
||||||
|
|
||||||
|
@ -313,9 +313,9 @@ def convert_iface(iface_data: InterfaceData) -> core_pb2.Interface:
|
||||||
name=iface_data.name,
|
name=iface_data.name,
|
||||||
mac=iface_data.mac,
|
mac=iface_data.mac,
|
||||||
ip4=iface_data.ip4,
|
ip4=iface_data.ip4,
|
||||||
ip4mask=iface_data.ip4_mask,
|
ip4_mask=iface_data.ip4_mask,
|
||||||
ip6=iface_data.ip6,
|
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:
|
if iface.net:
|
||||||
net_id = iface.net.id
|
net_id = iface.net.id
|
||||||
ip4 = None
|
ip4 = None
|
||||||
ip4mask = None
|
ip4_mask = None
|
||||||
ip6 = None
|
ip6 = None
|
||||||
ip6mask = None
|
ip6_mask = None
|
||||||
for addr in iface.addrlist:
|
for addr in iface.addrlist:
|
||||||
network = netaddr.IPNetwork(addr)
|
network = netaddr.IPNetwork(addr)
|
||||||
mask = network.prefixlen
|
mask = network.prefixlen
|
||||||
ip = str(network.ip)
|
ip = str(network.ip)
|
||||||
if netaddr.valid_ipv4(ip) and not ip4:
|
if netaddr.valid_ipv4(ip) and not ip4:
|
||||||
ip4 = ip
|
ip4 = ip
|
||||||
ip4mask = mask
|
ip4_mask = mask
|
||||||
elif netaddr.valid_ipv6(ip) and not ip6:
|
elif netaddr.valid_ipv6(ip) and not ip6:
|
||||||
ip6 = ip
|
ip6 = ip
|
||||||
ip6mask = mask
|
ip6_mask = mask
|
||||||
return core_pb2.Interface(
|
return core_pb2.Interface(
|
||||||
id=iface.node_id,
|
id=iface.node_id,
|
||||||
netid=net_id,
|
net_id=net_id,
|
||||||
name=iface.name,
|
name=iface.name,
|
||||||
mac=str(iface.hwaddr),
|
mac=iface.hwaddr,
|
||||||
mtu=iface.mtu,
|
mtu=iface.mtu,
|
||||||
flowid=iface.flow_id,
|
flow_id=iface.flow_id,
|
||||||
ip4=ip4,
|
ip4=ip4,
|
||||||
ip4mask=ip4mask,
|
ip4_mask=ip4_mask,
|
||||||
ip6=ip6,
|
ip6=ip6,
|
||||||
ip6mask=ip6mask,
|
ip6_mask=ip6_mask,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -834,7 +834,12 @@ class CoreClient:
|
||||||
iface_id = canvas_node.next_iface_id()
|
iface_id = canvas_node.next_iface_id()
|
||||||
name = f"eth{iface_id}"
|
name = f"eth{iface_id}"
|
||||||
iface = core_pb2.Interface(
|
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(
|
logging.info(
|
||||||
"create node(%s) interface(%s) IPv4(%s) IPv6(%s)",
|
"create node(%s) interface(%s) IPv4(%s) IPv6(%s)",
|
||||||
|
|
|
@ -248,7 +248,7 @@ class NodeConfigDialog(Dialog):
|
||||||
label.grid(row=row, column=0, padx=PADX, pady=PADY)
|
label.grid(row=row, column=0, padx=PADX, pady=PADY)
|
||||||
ip4_net = ""
|
ip4_net = ""
|
||||||
if iface.ip4:
|
if iface.ip4:
|
||||||
ip4_net = f"{iface.ip4}/{iface.ip4mask}"
|
ip4_net = f"{iface.ip4}/{iface.ip4_mask}"
|
||||||
ip4 = tk.StringVar(value=ip4_net)
|
ip4 = tk.StringVar(value=ip4_net)
|
||||||
entry = ttk.Entry(tab, textvariable=ip4, state=state)
|
entry = ttk.Entry(tab, textvariable=ip4, state=state)
|
||||||
entry.grid(row=row, column=1, columnspan=2, sticky="ew")
|
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)
|
label.grid(row=row, column=0, padx=PADX, pady=PADY)
|
||||||
ip6_net = ""
|
ip6_net = ""
|
||||||
if iface.ip6:
|
if iface.ip6:
|
||||||
ip6_net = f"{iface.ip6}/{iface.ip6mask}"
|
ip6_net = f"{iface.ip6}/{iface.ip6_mask}"
|
||||||
ip6 = tk.StringVar(value=ip6_net)
|
ip6 = tk.StringVar(value=ip6_net)
|
||||||
entry = ttk.Entry(tab, textvariable=ip6, state=state)
|
entry = ttk.Entry(tab, textvariable=ip6, state=state)
|
||||||
entry.grid(row=row, column=1, columnspan=2, sticky="ew")
|
entry.grid(row=row, column=1, columnspan=2, sticky="ew")
|
||||||
|
@ -318,12 +318,12 @@ class NodeConfigDialog(Dialog):
|
||||||
error = True
|
error = True
|
||||||
break
|
break
|
||||||
if ip4_net:
|
if ip4_net:
|
||||||
ip4, ip4mask = ip4_net.split("/")
|
ip4, ip4_mask = ip4_net.split("/")
|
||||||
ip4mask = int(ip4mask)
|
ip4_mask = int(ip4_mask)
|
||||||
else:
|
else:
|
||||||
ip4, ip4mask = "", 0
|
ip4, ip4_mask = "", 0
|
||||||
iface.ip4 = ip4
|
iface.ip4 = ip4
|
||||||
iface.ip4mask = ip4mask
|
iface.ip4_mask = ip4_mask
|
||||||
|
|
||||||
# validate ip6
|
# validate ip6
|
||||||
ip6_net = data.ip6.get()
|
ip6_net = data.ip6.get()
|
||||||
|
@ -331,12 +331,12 @@ class NodeConfigDialog(Dialog):
|
||||||
error = True
|
error = True
|
||||||
break
|
break
|
||||||
if ip6_net:
|
if ip6_net:
|
||||||
ip6, ip6mask = ip6_net.split("/")
|
ip6, ip6_mask = ip6_net.split("/")
|
||||||
ip6mask = int(ip6mask)
|
ip6_mask = int(ip6_mask)
|
||||||
else:
|
else:
|
||||||
ip6, ip6mask = "", 0
|
ip6, ip6_mask = "", 0
|
||||||
iface.ip6 = ip6
|
iface.ip6 = ip6
|
||||||
iface.ip6mask = ip6mask
|
iface.ip6_mask = ip6_mask
|
||||||
|
|
||||||
mac = data.mac.get()
|
mac = data.mac.get()
|
||||||
auto_mac = data.is_auto.get()
|
auto_mac = data.is_auto.get()
|
||||||
|
|
|
@ -289,10 +289,10 @@ class CanvasEdge(Edge):
|
||||||
label = f"{iface.name}"
|
label = f"{iface.name}"
|
||||||
if iface.ip4 and self.canvas.show_ip4s.get():
|
if iface.ip4 and self.canvas.show_ip4s.get():
|
||||||
label = f"{label}\n" if label else ""
|
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():
|
if iface.ip6 and self.canvas.show_ip6s.get():
|
||||||
label = f"{label}\n" if label else ""
|
label = f"{label}\n" if label else ""
|
||||||
label += f"{iface.ip6}/{iface.ip6mask}"
|
label += f"{iface.ip6}/{iface.ip6_mask}"
|
||||||
return label
|
return label
|
||||||
|
|
||||||
def create_node_labels(self) -> Tuple[str, str]:
|
def create_node_labels(self) -> Tuple[str, str]:
|
||||||
|
|
|
@ -15,7 +15,7 @@ if TYPE_CHECKING:
|
||||||
def get_index(iface: "core_pb2.Interface") -> Optional[int]:
|
def get_index(iface: "core_pb2.Interface") -> Optional[int]:
|
||||||
if not iface.ip4:
|
if not iface.ip4:
|
||||||
return None
|
return None
|
||||||
net = netaddr.IPNetwork(f"{iface.ip4}/{iface.ip4mask}")
|
net = netaddr.IPNetwork(f"{iface.ip4}/{iface.ip4_mask}")
|
||||||
ip_value = net.value
|
ip_value = net.value
|
||||||
cidr_value = net.cidr.value
|
cidr_value = net.cidr.value
|
||||||
return ip_value - cidr_value
|
return ip_value - cidr_value
|
||||||
|
@ -153,10 +153,10 @@ class InterfaceManager:
|
||||||
def get_subnets(self, iface: "core_pb2.Interface") -> Subnets:
|
def get_subnets(self, iface: "core_pb2.Interface") -> Subnets:
|
||||||
ip4_subnet = self.ip4_subnets
|
ip4_subnet = self.ip4_subnets
|
||||||
if iface.ip4:
|
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
|
ip6_subnet = self.ip6_subnets
|
||||||
if iface.ip6:
|
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)
|
subnets = Subnets(ip4_subnet, ip6_subnet)
|
||||||
return self.used_subnets.get(subnets.key(), subnets)
|
return self.used_subnets.get(subnets.key(), subnets)
|
||||||
|
|
||||||
|
|
|
@ -732,11 +732,11 @@ message Interface {
|
||||||
string name = 2;
|
string name = 2;
|
||||||
string mac = 3;
|
string mac = 3;
|
||||||
string ip4 = 4;
|
string ip4 = 4;
|
||||||
int32 ip4mask = 5;
|
int32 ip4_mask = 5;
|
||||||
string ip6 = 6;
|
string ip6 = 6;
|
||||||
int32 ip6mask = 7;
|
int32 ip6_mask = 7;
|
||||||
int32 netid = 8;
|
int32 net_id = 8;
|
||||||
int32 flowid = 9;
|
int32 flow_id = 9;
|
||||||
int32 mtu = 10;
|
int32 mtu = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue