diff --git a/app/src/main/java/io/vproxy/app/app/cmd/HelpCommand.java b/app/src/main/java/io/vproxy/app/app/cmd/HelpCommand.java index 9abbadfd3..03d89f28f 100644 --- a/app/src/main/java/io/vproxy/app/app/cmd/HelpCommand.java +++ b/app/src/main/java/io/vproxy/app/app/cmd/HelpCommand.java @@ -427,7 +427,7 @@ public enum ParamMan { pass("password", "pass", "password"), mac("mac", null, "mac address"), routing("routing", null, "routing functions"), - vni("vni", null, "vni number"), + vrf("vrf", null, "vrf id number"), postscript("post-script", null, "the script to run after added"), mtu("mtu", null, "max transmission unit"), flood("flood", null, "flooding traffic"), @@ -1172,33 +1172,33 @@ public enum ResMan { ) )) )), - vpc("vpc", null, "a private network", + vrf("vrf", null, "a private network", Arrays.asList( - new ResActMan(ActMan.addto, "create a vpc in a switch. the name should be vni of the vpc", Arrays.asList( - new ResActParamMan(ParamMan.v4network, "the ipv4 network allowed in this vpc"), - new ResActParamMan(ParamMan.v6network, "the ipv6 network allowed in this vpc", "not allowed"), - new ResActParamMan(ParamMan.annotations, "annotations of the vpc", "{}") + new ResActMan(ActMan.addto, "create a vrf in a switch. the name should be a numeric id of the vrf", Arrays.asList( + new ResActParamMan(ParamMan.v4network, "the ipv4 network allowed in this vrf"), + new ResActParamMan(ParamMan.v6network, "the ipv6 network allowed in this vrf", "not allowed"), + new ResActParamMan(ParamMan.annotations, "annotations of the vrf", "{}") ), Collections.singletonList( new Tuple<>( - "add vpc 1314 to switch sw0 v4network 172.16.0.0/16", + "add vrf 1314 to switch sw0 v4network 172.16.0.0/16", "\"OK\"" ) )), - new ResActMan(ActMan.list, "list existing vpcs in a switch", Collections.emptyList(), Collections.singletonList( + new ResActMan(ActMan.list, "list existing vrfs in a switch", Collections.emptyList(), Collections.singletonList( new Tuple<>( - "list vpc in switch sw0", + "list vrf in switch sw0", "1) (integer) 1314" ) )), - new ResActMan(ActMan.listdetail, "list detailed info about vpcs in a switch", Collections.emptyList(), Collections.singletonList( + new ResActMan(ActMan.listdetail, "list detailed info about vrfs in a switch", Collections.emptyList(), Collections.singletonList( new Tuple<>( - "list-detail vpc in switch sw0", + "list-detail vrf in switch sw0", "1) \"1314 -> v4network 172.16.0.0/16\"" ) )), - new ResActMan(ActMan.removefrom, "remove a vpc from a switch", Collections.emptyList(), Collections.singletonList( + new ResActMan(ActMan.removefrom, "remove a vrf from a switch", Collections.emptyList(), Collections.singletonList( new Tuple<>( - "remote vpc 1314 from switch sw0", + "remote vrf 1314 from switch sw0", "\"OK\"" ) )) @@ -1265,40 +1265,40 @@ public enum ResMan { new ResActParamMan(ParamMan.iface, "create mac entry with the specified iface", "") ), Collections.singletonList( new Tuple<>( - "add arp 11:22:33:44:55:66 to vpc 1 in switch sw0 iface xdp:b1 ip 9.8.7.6", + "add arp 11:22:33:44:55:66 to vrf 1 in switch sw0 iface xdp:b1 ip 9.8.7.6", "\"OK\"" ) )), - new ResActMan(ActMan.list, "count entries in a vpc", Collections.emptyList(), Collections.singletonList( + new ResActMan(ActMan.list, "count entries in a vrf", Collections.emptyList(), Collections.singletonList( new Tuple<>( - "list arp in vpc 1314 in switch sw0", + "list arp in vrf 1314 in switch sw0", "(integer) 2" ) )), - new ResActMan(ActMan.listdetail, "list arp and mac table entries in a vpc", Collections.emptyList(), Collections.singletonList( + new ResActMan(ActMan.listdetail, "list arp and mac table entries in a vrf", Collections.emptyList(), Collections.singletonList( new Tuple<>( - "list-detail arp in vpc 1314 in switch sw0", + "list-detail arp in vrf 1314 in switch sw0", "1) \"aa:92:96:2f:3b:7d 10.213.0.1 Iface(127.0.0.1:54042) ARP-TTL:14390 MAC-TTL:299\"\n" + "2) \"fa:e8:aa:6c:45:f4 10.213.0.2 Iface(127.0.0.1:57374) ARP-TTL:14390 MAC-TTL:299\"" ) )), - new ResActMan(ActMan.removefrom, "remove arp and mac table entries from a vpc", Collections.emptyList(), Collections.singletonList( + new ResActMan(ActMan.removefrom, "remove arp and mac table entries from a vrf", Collections.emptyList(), Collections.singletonList( new Tuple<>( - "remove arp 11:22:33:44:55:66 from vpc 1 in switch sw0", + "remove arp 11:22:33:44:55:66 from vrf 1 in switch sw0", "\"OK\"" ) )) )), conntrack("conntrack", "ct", "connection tracking table entries", Arrays.asList( - new ResActMan(ActMan.list, "count entries in a vpc", Collections.emptyList(), Collections.singletonList( + new ResActMan(ActMan.list, "count entries in a vrf", Collections.emptyList(), Collections.singletonList( new Tuple<>( - "list conntrack in vpc 1314 in switch sw0", + "list conntrack in vrf 1314 in switch sw0", "(integer) 2" ) )), - new ResActMan(ActMan.listdetail, "list connection tracking table entries in a vpc", Collections.emptyList(), Collections.singletonList( + new ResActMan(ActMan.listdetail, "list connection tracking table entries in a vrf", Collections.emptyList(), Collections.singletonList( new Tuple<>( - "list-detail conntrack in vpc 1314 in switch sw0", + "list-detail conntrack in vrf 1314 in switch sw0", "1) \"TCP ESTABLISHED remote=10.100.0.2:80 local=10.100.0.1:50014 --nat-> local=123.123.123.123:1234 remote=10.100.0.1:50014 TTL:431993\"\n" + "2) \"TCP ESTABLISHED remote=10.100.0.1:50014 local=123.123.123.123:1234 --nat-> local=10.100.0.1:50014 remote=10.100.0.2:80 TTL:43199\"" ) @@ -1308,11 +1308,11 @@ public enum ResMan { "Note: should set -Dvfd=posix or -Dvfd=windows", Collections.singletonList( new ResActMan(ActMan.addto, "add a tap to a switch. Note: the result string is the name of the tap device because might be generated", Arrays.asList( - new ResActParamMan(ParamMan.vni, "vni of the vpc which the tap device is attached to"), - new ResActParamMan(ParamMan.postscript, "post script. the vproxy will give env variables: VNI, DEV (the generated device name), SWITCH (name of the switch)", "(empty)") + new ResActParamMan(ParamMan.vrf, "id of the vrf which the tap device is attached to"), + new ResActParamMan(ParamMan.postscript, "post script. the vproxy will give env variables: VRF, DEV (the generated device name), SWITCH (name of the switch)", "(empty)") ), Collections.singletonList( new Tuple<>( - "add tap tap0 to switch sw0 vni 1314", + "add tap tap0 to switch sw0 vrf 1314", "\"OK\"" ) )) @@ -1321,16 +1321,16 @@ public enum ResMan { "Note: should set -Dvfd=posix", Collections.singletonList( new ResActMan(ActMan.addto, "add a tun to a switch. Note: the result string is the name of the tun device because might be generated", Arrays.asList( - new ResActParamMan(ParamMan.vni, "vni of the vpc which the tun device is attached to"), + new ResActParamMan(ParamMan.vrf, "id of the vrf which the tun device is attached to"), new ResActParamMan(ParamMan.mac, "mac address of this tun device. the switch requires l2 layer frames for handling packets"), - new ResActParamMan(ParamMan.postscript, "post script. the vproxy will give env variables: VNI, DEV (the generated device name), SWITCH (name of the switch)", "(empty)") + new ResActParamMan(ParamMan.postscript, "post script. the vproxy will give env variables: VRF, DEV (the generated device name), SWITCH (name of the switch)", "(empty)") ), Arrays.asList( new Tuple<>( - "add tun tun0 to switch sw0 vni 1314 mac 00:11:22:33:44:55", + "add tun tun0 to switch sw0 vrf 1314 mac 00:11:22:33:44:55", "\"OK\"" ), new Tuple<>( - "add tun utun9 to switch sw0 vni 1314 mac 00:11:22:33:44:55", + "add tun utun9 to switch sw0 vrf 1314 mac 00:11:22:33:44:55", "\"OK\"" ) )) @@ -1339,13 +1339,13 @@ public enum ResMan { Collections.singletonList( new ResActMan(ActMan.addto, "add fubuki netif to a switch", Arrays.asList( new ResActParamMan(ParamMan.pass, "password (key) for fubuki config"), - new ResActParamMan(ParamMan.vni, "vni which the netif is assigned to"), + new ResActParamMan(ParamMan.vrf, "vrf which the netif is assigned to"), new ResActParamMan(ParamMan.mac, "mac address of this tun device. the switch requires l2 layer frames for handling packets"), new ResActParamMan(ParamMan.address, "server address to connect to"), new ResActParamMan(ParamMan.ip, "use the specified ip/mask as tun ip") ), Collections.singletonList( new Tuple<>( - "add fubuki hello to switch sw0 password p@sSw0rD vni 1314 mac 00:11:22:33:44:55 address 192.168.77.1:18472", + "add fubuki hello to switch sw0 password p@sSw0rD vrf 1314 mac 00:11:22:33:44:55 address 192.168.77.1:18472", "\"OK\"" ) )) @@ -1354,11 +1354,11 @@ public enum ResMan { "Note: the ifname should be name of the fubuki netif to attach to.", Collections.singletonList( new ResActMan(ActMan.addto, "add fubuki-etherip sub-netif to a switch", Arrays.asList( - new ResActParamMan(ParamMan.vni, "vni which the netif is assigned to"), + new ResActParamMan(ParamMan.vrf, "vrf which the netif is assigned to"), new ResActParamMan(ParamMan.ip, "the target ip to send the packet to") ), Collections.singletonList( new Tuple<>( - "add fubuki-etherip hello to switch sw0 vni 1314 ip 10.99.88.2", + "add fubuki-etherip hello to switch sw0 vrf 1314 ip 10.99.88.2", "\"OK\"" ) )) @@ -1376,18 +1376,18 @@ public enum ResMan { new ResActParamMan(ParamMan.txringsize, "tx ring size", "" + SwitchUtils.RX_TX_CHUNKS), new ResActParamMan(ParamMan.mode, "mode of the xsk, enum: {SKB, DRIVER}, see doc for more info", "" + BPFMode.SKB), new ResActParamMan(ParamMan.busypoll, "whether to enable busy poll, and set SO_BUSY_POLL_BUDGET. Set this option to 0 to disable busy poll", "0"), - new ResActParamMan(ParamMan.vni, "vni which the iface is assigned to") + new ResActParamMan(ParamMan.vrf, "vrf which the iface is assigned to") ), Arrays.asList( new ResActFlagMan(FlagMan.zerocopy, "allow kernel to use zerocopy machanism", false), new ResActFlagMan(FlagMan.rxgencsum, "generate checksum in native code before receiving the packet in java", false), new ResActFlagMan(FlagMan.offload, "offload mac switching to xdp program", false) ), Arrays.asList( new Tuple<>( - "add xdp xdptut-4667 to switch sw0 umem umem0 queue 0 rx-ring-size 2048 tx-ring-size 2048 mode SKB vni 1 zerocopy", + "add xdp xdptut-4667 to switch sw0 umem umem0 queue 0 rx-ring-size 2048 tx-ring-size 2048 mode SKB vrf 1 zerocopy", "\"OK\"" ), new Tuple<>( - "add xdp xdptut-4667 to switch sw0 umem umem0 queue 0 vni 1", + "add xdp xdptut-4667 to switch sw0 umem umem0 queue 0 vrf 1", "\"OK\"" ) )) @@ -1395,91 +1395,91 @@ public enum ResMan { vlanadaptor("vlan-adaptor", "vlan", "vlan adaptor which adds or removes 802.1q tag", Collections.singletonList( new ResActMan(ActMan.addto, "add vlan adaptor into the switch", Collections.singletonList( - new ResActParamMan(ParamMan.vni, "vni which the iface is assigned to", "same as vlan id") + new ResActParamMan(ParamMan.vrf, "vrf which the iface is assigned to", "same as vlan id") ), Arrays.asList( new Tuple<>( "add vlan 101@xdp:veth0 to switch sw0", "\"OK\"" ), new Tuple<>( - "add vlan 102@tap:tap1 to switch sw0 vni 202", + "add vlan 102@tap:tap1 to switch sw0 vrf 202", "\"OK\"" ) )) )), - ip("ip", null, "synthetic ip in a vpc of a switch", + ip("ip", null, "synthetic ip in a vrf of a switch", Arrays.asList( - new ResActMan(ActMan.addto, "add a synthetic ip to a vpc of a switch", Arrays.asList( + new ResActMan(ActMan.addto, "add a synthetic ip to a vrf of a switch", Arrays.asList( new ResActParamMan(ParamMan.mac, "mac address that the ip assigned on"), new ResActParamMan(ParamMan.routing, "enable or disable routing functions on this ip, set to on/off", "on") ), Collections.singletonList( new Tuple<>( - "add ip 172.16.0.21 to vpc 1314 in switch sw0 mac e2:8b:11:00:00:22", + "add ip 172.16.0.21 to vrf 1314 in switch sw0 mac e2:8b:11:00:00:22", "\"OK\"" ) )), - new ResActMan(ActMan.list, "show synthetic ips in a vpc of a switch", Collections.emptyList(), Collections.singletonList( + new ResActMan(ActMan.list, "show synthetic ips in a vrf of a switch", Collections.emptyList(), Collections.singletonList( new Tuple<>( - "list ip in vpc 1314 in switch sw0", + "list ip in vrf 1314 in switch sw0", "1) \"172.16.0.21\"\n" + "2) \"[2001:0db8:0000:f101:0000:0000:0000:0002]\"" ) )), - new ResActMan(ActMan.listdetail, "show detailed info about synthetic ips in a vpc of a switch", Collections.emptyList(), Collections.singletonList( + new ResActMan(ActMan.listdetail, "show detailed info about synthetic ips in a vrf of a switch", Collections.emptyList(), Collections.singletonList( new Tuple<>( - "list-detail ip in vpc 1314 in switch sw0", + "list-detail ip in vrf 1314 in switch sw0", "1) \"172.16.0.21 -> mac e2:8b:11:00:00:22\"\n" + "2) \"[2001:0db8:0000:f101:0000:0000:0000:0002] -> mac e2:8b:11:00:00:33\"" ) )), - new ResActMan(ActMan.update, "modify a synthetic ip in a vpc of a switch", List.of( + new ResActMan(ActMan.update, "modify a synthetic ip in a vrf of a switch", List.of( new ResActParamMan(ParamMan.routing, "enable or disable routing functions on this ip, set to on/off", "not changed") ), Collections.singletonList( new Tuple<>( - "update ip 172.16.0.21 in vpc 1314 in switch sw0 routing off", + "update ip 172.16.0.21 in vrf 1314 in switch sw0 routing off", "\"OK\"" ) )), - new ResActMan(ActMan.removefrom, "remove a synthetic ip from a vpc of a switch", Collections.emptyList(), Collections.singletonList( + new ResActMan(ActMan.removefrom, "remove a synthetic ip from a vrf of a switch", Collections.emptyList(), Collections.singletonList( new Tuple<>( - "remove ip 172.16.0.21 from vpc 1314 in switch sw0", + "remove ip 172.16.0.21 from vrf 1314 in switch sw0", "\"OK\"" ) )) )), - route("route", null, "route rules in a vpc of a switch", + route("route", null, "route rules in a vrf of a switch", Arrays.asList( - new ResActMan(ActMan.addto, "add a route to a vpc of a switch", Arrays.asList( + new ResActMan(ActMan.addto, "add a route to a vrf of a switch", Arrays.asList( new ResActParamMan(ParamMan.network, "network to be matched"), - new ResActParamMan(ParamMan.vni, "the vni to send packet to. only one of vni|via can be used"), - new ResActParamMan(ParamMan.via, "the address to forward the packet to. only one of via|vni can be used") + new ResActParamMan(ParamMan.vrf, "the vrf to send packet to. only one of vrf|via can be used"), + new ResActParamMan(ParamMan.via, "the address to forward the packet to. only one of via|vrf can be used") ), Arrays.asList( new Tuple<>( - "add route to172.17 to vpc 1314 in switch sw0 network 172.17.0.0/24 vni 1315", + "add route to172.17 to vrf 1314 in switch sw0 network 172.17.0.0/24 vrf 1315", "\"OK\"" ), new Tuple<>( - "add route to172.17 to vpc 1314 in switch sw0 network 172.17.0.0/24 via 172.16.0.1", + "add route to172.17 to vrf 1314 in switch sw0 network 172.17.0.0/24 via 172.16.0.1", "\"OK\"" ) )), - new ResActMan(ActMan.list, "show route rule names in a vpc of a switch", Collections.emptyList(), Collections.singletonList( + new ResActMan(ActMan.list, "show route rule names in a vrf of a switch", Collections.emptyList(), Collections.singletonList( new Tuple<>( - "list route in vpc 1314 in switch sw0", + "list route in vrf 1314 in switch sw0", "1) \"to172.17\"\n" + "2) \"to2001:0db8:0000:f102\"" ) )), - new ResActMan(ActMan.listdetail, "show detailed info about route rules in a vpc of a switch", Collections.emptyList(), Collections.singletonList( + new ResActMan(ActMan.listdetail, "show detailed info about route rules in a vrf of a switch", Collections.emptyList(), Collections.singletonList( new Tuple<>( - "list-detail route in vpc 1314 in switch sw0", - "1) \"to172.17 -> network 172.17.0.0/24 vni 1315\"\n" + - "2) \"to2001:0db8:0000:f102 -> network [2001:0db8:0000:f102:0000:0000:0000:0000]/64 vni 1315\"" + "list-detail route in vrf 1314 in switch sw0", + "1) \"to172.17 -> network 172.17.0.0/24 vrf 1315\"\n" + + "2) \"to2001:0db8:0000:f102 -> network [2001:0db8:0000:f102:0000:0000:0000:0000]/64 vrf 1315\"" ) )), - new ResActMan(ActMan.removefrom, "remove a route rule from a vpc of a switch", Collections.emptyList(), Collections.singletonList( + new ResActMan(ActMan.removefrom, "remove a route rule from a vrf of a switch", Collections.emptyList(), Collections.singletonList( new Tuple<>( - "remove route to172.17 from vpc 1314 in switch sw0", + "remove route to172.17 from vrf 1314 in switch sw0", "\"OK\"" ) )) diff --git a/app/src/main/java/io/vproxy/app/app/cmd/ModuleCommands.kt b/app/src/main/java/io/vproxy/app/app/cmd/ModuleCommands.kt index e2127eecc..a70363cec 100644 --- a/app/src/main/java/io/vproxy/app/app/cmd/ModuleCommands.kt +++ b/app/src/main/java/io/vproxy/app/app/cmd/ModuleCommands.kt @@ -642,9 +642,9 @@ class ModuleCommands private constructor() : Commands() { exec = execUpdate { TraceHandle.remove(it) } ) } - it + Res(ResourceType.vpc) { + it + Res(ResourceType.vrf) { it + ResAct( - relation = ResourceType.vpc, + relation = ResourceType.vrf, action = ActType.addto, targetRelation = ResRelation(ResourceType.sw), params = { @@ -664,33 +664,33 @@ class ModuleCommands private constructor() : Commands() { } it + ResActParam(Param.anno) { AnnotationsHandle.check(it) } }, - check = { VpcHandle.checkVpcName(it.resource) }, - exec = execUpdate { VpcHandle.add(it) } + check = { VrfHandle.checkVrfName(it.resource) }, + exec = execUpdate { VrfHandle.add(it) } ) it + ResAct( - relation = ResRelation(ResourceType.vpc, ResRelation(ResourceType.sw)), + relation = ResRelation(ResourceType.vrf, ResRelation(ResourceType.sw)), action = ActType.list, exec = { - val vpcLs = VpcHandle.list(it.resource.parentResource) - val ls = vpcLs.stream().map { it.vpc }.collect(Collectors.toList()) - CmdResult(vpcLs, ls, utilJoinList(ls)) + val vrfLs = VrfHandle.list(it.resource.parentResource) + val ls = vrfLs.stream().map { it.vrf }.collect(Collectors.toList()) + CmdResult(vrfLs, ls, utilJoinList(ls)) } ) it + ResAct( - relation = ResRelation(ResourceType.vpc, ResRelation(ResourceType.sw)), + relation = ResRelation(ResourceType.vrf, ResRelation(ResourceType.sw)), action = ActType.listdetail, exec = { - val vpcLs = VpcHandle.list(it.resource.parentResource) - val ls = vpcLs.stream().map { it.toString() }.collect(Collectors.toList()) - CmdResult(vpcLs, ls, utilJoinList(ls)) + val vrfLs = VrfHandle.list(it.resource.parentResource) + val ls = vrfLs.stream().map { it.toString() }.collect(Collectors.toList()) + CmdResult(vrfLs, ls, utilJoinList(ls)) } ) it + ResAct( - relation = ResourceType.vpc, + relation = ResourceType.vrf, action = ActType.removefrom, targetRelation = ResRelation(ResourceType.sw), - check = { VpcHandle.checkVpcName(it.resource) }, - exec = execUpdate { VpcHandle.remove(it) } + check = { VrfHandle.checkVrfName(it.resource) }, + exec = execUpdate { VrfHandle.remove(it) } ) } it + Res(ResourceType.iface) { @@ -746,7 +746,7 @@ class ModuleCommands private constructor() : Commands() { it + ResAct( relation = ResourceType.arp, action = ActType.addto, - targetRelation = ResRelation(ResourceType.vpc, ResRelation(ResourceType.sw)), + targetRelation = ResRelation(ResourceType.vrf, ResRelation(ResourceType.sw)), params = { it + ResActParam(Param.ip) { IpParamHandle.check(it) } it + ResActParam(Param.iface) @@ -756,7 +756,7 @@ class ModuleCommands private constructor() : Commands() { if (!it.args.containsKey(Param.ip) && !(it.args.containsKey(Param.iface))) { throw io.vproxy.base.util.exception.XException("at lease one of ip|iface should be specified") } - VpcHandle.checkVpcName(it.prepositionResource) + VrfHandle.checkVrfName(it.prepositionResource) }, exec = { ArpHandle.add(it) @@ -766,13 +766,13 @@ class ModuleCommands private constructor() : Commands() { it + ResAct( relation = ResRelation( ResourceType.arp, ResRelation( - ResourceType.vpc, ResRelation( + ResourceType.vrf, ResRelation( ResourceType.sw ) ) ), action = ActType.list, - check = { VpcHandle.checkVpcName(it.resource.parentResource) }, + check = { VrfHandle.checkVrfName(it.resource.parentResource) }, exec = { val cnt = ArpHandle.count(it.resource.parentResource) CmdResult(cnt, cnt, "" + cnt) @@ -781,13 +781,13 @@ class ModuleCommands private constructor() : Commands() { it + ResAct( relation = ResRelation( ResourceType.arp, ResRelation( - ResourceType.vpc, ResRelation( + ResourceType.vrf, ResRelation( ResourceType.sw ) ) ), action = ActType.listdetail, - check = { VpcHandle.checkVpcName(it.resource.parentResource) }, + check = { VrfHandle.checkVrfName(it.resource.parentResource) }, exec = { val arpLs = ArpHandle.list(it.resource.parentResource) val ls = arpLs.stream().map { it.toString(arpLs) }.collect(Collectors.toList()) @@ -797,7 +797,7 @@ class ModuleCommands private constructor() : Commands() { it + ResAct( relation = ResourceType.arp, action = ActType.removefrom, - targetRelation = ResRelation(ResourceType.vpc, ResRelation(ResourceType.sw)), + targetRelation = ResRelation(ResourceType.vrf, ResRelation(ResourceType.sw)), check = { ArpHandle.checkMacName(it.resource) }, exec = { ArpHandle.remove(it) @@ -809,13 +809,13 @@ class ModuleCommands private constructor() : Commands() { it + ResAct( relation = ResRelation( ResourceType.conntrack, ResRelation( - ResourceType.vpc, ResRelation( + ResourceType.vrf, ResRelation( ResourceType.sw ) ) ), action = ActType.list, - check = { VpcHandle.checkVpcName(it.resource.parentResource) }, + check = { VrfHandle.checkVrfName(it.resource.parentResource) }, exec = { val cnt = ConntrackHandle.count(it.resource.parentResource) CmdResult(cnt, cnt, "" + cnt) @@ -824,13 +824,13 @@ class ModuleCommands private constructor() : Commands() { it + ResAct( relation = ResRelation( ResourceType.conntrack, ResRelation( - ResourceType.vpc, ResRelation( + ResourceType.vrf, ResRelation( ResourceType.sw ) ) ), action = ActType.listdetail, - check = { VpcHandle.checkVpcName(it.resource.parentResource) }, + check = { VrfHandle.checkVrfName(it.resource.parentResource) }, exec = { val ctLs = ConntrackHandle.list(it.resource.parentResource) val tb = TableBuilder() @@ -850,7 +850,7 @@ class ModuleCommands private constructor() : Commands() { action = ActType.addto, targetRelation = ResRelation(ResourceType.sw), params = { - it + ResActParam(Param.vni, required) { VniHandle.check(it) } + it + ResActParam(Param.vrf, required) { VrfParamHandle.check(it) } it + ResActParam(Param.postscript) }, check = { @@ -867,7 +867,7 @@ class ModuleCommands private constructor() : Commands() { action = ActType.addto, targetRelation = ResRelation(ResourceType.sw), params = { - it + ResActParam(Param.vni, required) { VniHandle.check(it) } + it + ResActParam(Param.vrf, required) { VrfParamHandle.check(it) } it + ResActParam(Param.mac, required) { MacHandle.check(it) } it + ResActParam(Param.postscript) }, @@ -886,7 +886,7 @@ class ModuleCommands private constructor() : Commands() { targetRelation = ResRelation(ResourceType.sw), params = { it + ResActParam(Param.pass, required) - it + ResActParam(Param.vni, required) { VniHandle.check(it) } + it + ResActParam(Param.vrf, required) { VrfParamHandle.check(it) } it + ResActParam(Param.mac, required) { MacHandle.check(it) } it + ResActParam(Param.addr, required) { AddrHandle.check(it) } it + ResActParam(Param.ip) { IpParamHandle.check(it, true) } @@ -900,7 +900,7 @@ class ModuleCommands private constructor() : Commands() { action = ActType.addto, targetRelation = ResRelation(ResourceType.sw), params = { - it + ResActParam(Param.vni, required) { VniHandle.check(it) } + it + ResActParam(Param.vrf, required) { VrfParamHandle.check(it) } it + ResActParam(Param.ip) { IpParamHandle.check(it) } }, exec = execUpdate { FubukiEtherIPHandle.add(it) } @@ -918,7 +918,7 @@ class ModuleCommands private constructor() : Commands() { it + ResActParam(Param.txringsize) { RingSizeHandle.check(it, Param.txringsize) } it + ResActParam(Param.mode) { BPFModeHandle.check(it) } it + ResActParam(Param.busypoll) { BusyPollHandle.check(it) } - it + ResActParam(Param.vni, required) { VniHandle.check(it) } + it + ResActParam(Param.vrf, required) { VrfParamHandle.check(it) } }, flags = { it + ResActFlag(Flag.zerocopy) @@ -934,7 +934,7 @@ class ModuleCommands private constructor() : Commands() { action = ActType.addto, targetRelation = ResRelation(ResourceType.sw), params = { - it + ResActParam(Param.vni, required) { VniHandle.check(it) } + it + ResActParam(Param.vrf, required) { VrfParamHandle.check(it) } }, exec = execUpdate { VLanAdaptorHandle.add(it) } ) @@ -943,7 +943,7 @@ class ModuleCommands private constructor() : Commands() { it + ResAct( relation = ResourceType.ip, action = ActType.addto, - targetRelation = ResRelation(ResourceType.vpc, ResRelation(ResourceType.sw)), + targetRelation = ResRelation(ResourceType.vrf, ResRelation(ResourceType.sw)), params = { it + ResActParam(Param.mac, required) { MacHandle.check(it) } it + ResActParam(Param.anno) { AnnotationsHandle.check(it) } @@ -951,21 +951,21 @@ class ModuleCommands private constructor() : Commands() { }, check = { IpHandle.checkIpName(it.resource) - VpcHandle.checkVpcName(it.prepositionResource) + VrfHandle.checkVrfName(it.prepositionResource) }, exec = execUpdate { IpHandle.add(it) } ) it + ResAct( relation = ResRelation( ResourceType.ip, ResRelation( - ResourceType.vpc, ResRelation( + ResourceType.vrf, ResRelation( ResourceType.sw ) ) ), action = ActType.list, check = { - VpcHandle.checkVpcName(it.resource.parentResource) + VrfHandle.checkVrfName(it.resource.parentResource) }, exec = { val names = IpHandle.names(it.resource.parentResource) @@ -976,14 +976,14 @@ class ModuleCommands private constructor() : Commands() { it + ResAct( relation = ResRelation( ResourceType.ip, ResRelation( - ResourceType.vpc, ResRelation( + ResourceType.vrf, ResRelation( ResourceType.sw ) ) ), action = ActType.listdetail, check = { - VpcHandle.checkVpcName(it.resource.parentResource) + VrfHandle.checkVrfName(it.resource.parentResource) }, exec = { val tuples = IpHandle.list(it.resource.parentResource) @@ -1001,7 +1001,7 @@ class ModuleCommands private constructor() : Commands() { it + ResAct( relation = ResRelation( ResourceType.ip, ResRelation( - ResourceType.vpc, ResRelation( + ResourceType.vrf, ResRelation( ResourceType.sw ) ) @@ -1012,7 +1012,7 @@ class ModuleCommands private constructor() : Commands() { }, check = { IpHandle.checkIpName(it.resource) - VpcHandle.checkVpcName(it.resource.parentResource) + VrfHandle.checkVrfName(it.resource.parentResource) }, exec = { IpHandle.update(it) @@ -1022,10 +1022,10 @@ class ModuleCommands private constructor() : Commands() { it + ResAct( relation = ResourceType.ip, action = ActType.removefrom, - targetRelation = ResRelation(ResourceType.vpc, ResRelation(ResourceType.sw)), + targetRelation = ResRelation(ResourceType.vrf, ResRelation(ResourceType.sw)), check = { IpHandle.checkIpName(it.resource) - VpcHandle.checkVpcName(it.prepositionResource) + VrfHandle.checkVrfName(it.prepositionResource) }, exec = execUpdate { IpHandle.remove(it) } ) @@ -1034,14 +1034,14 @@ class ModuleCommands private constructor() : Commands() { it + ResAct( relation = ResourceType.route, action = ActType.addto, - targetRelation = ResRelation(ResourceType.vpc, ResRelation(ResourceType.sw)), + targetRelation = ResRelation(ResourceType.vrf, ResRelation(ResourceType.sw)), params = { it + ResActParam(Param.net, required) { NetworkHandle.check(it) } - it + ResActParam(Param.vni) { NetworkHandle.check(it) } + it + ResActParam(Param.vrf) { NetworkHandle.check(it) } it + ResActParam(Param.via) { NetworkHandle.check(it) } }, check = { - VpcHandle.checkVpcName(it.prepositionResource) + VrfHandle.checkVrfName(it.prepositionResource) RouteHandle.checkCreateRoute(it) }, exec = execUpdate { RouteHandle.add(it) } @@ -1049,13 +1049,13 @@ class ModuleCommands private constructor() : Commands() { it + ResAct( relation = ResRelation( ResourceType.route, ResRelation( - ResourceType.vpc, ResRelation( + ResourceType.vrf, ResRelation( ResourceType.sw ) ) ), action = ActType.list, - check = { VpcHandle.checkVpcName(it.resource.parentResource) }, + check = { VrfHandle.checkVrfName(it.resource.parentResource) }, exec = { val names = RouteHandle.names(it.resource.parentResource) CmdResult(names, names, utilJoinList(names)) @@ -1064,13 +1064,13 @@ class ModuleCommands private constructor() : Commands() { it + ResAct( relation = ResRelation( ResourceType.route, ResRelation( - ResourceType.vpc, ResRelation( + ResourceType.vrf, ResRelation( ResourceType.sw ) ) ), action = ActType.listdetail, - check = { VpcHandle.checkVpcName(it.resource.parentResource) }, + check = { VrfHandle.checkVrfName(it.resource.parentResource) }, exec = { val routes = RouteHandle.list(it.resource.parentResource) val strTuples = routes.stream().map { it.toString() }.collect(Collectors.toList()) @@ -1080,8 +1080,8 @@ class ModuleCommands private constructor() : Commands() { it + ResAct( relation = ResourceType.route, action = ActType.removefrom, - targetRelation = ResRelation(ResourceType.vpc, ResRelation(ResourceType.sw)), - check = { VpcHandle.checkVpcName(it.prepositionResource) }, + targetRelation = ResRelation(ResourceType.vrf, ResRelation(ResourceType.sw)), + check = { VrfHandle.checkVrfName(it.prepositionResource) }, exec = execUpdate { RouteHandle.remove(it) } ) } diff --git a/app/src/main/java/io/vproxy/app/app/cmd/Param.java b/app/src/main/java/io/vproxy/app/app/cmd/Param.java index ab4411eda..54ec4d1b6 100644 --- a/app/src/main/java/io/vproxy/app/app/cmd/Param.java +++ b/app/src/main/java/io/vproxy/app/app/cmd/Param.java @@ -36,7 +36,7 @@ public enum Param { mactabletimeout("mac-table-timeout"), arptabletimeout("arp-table-timeout"), mac("mac"), - vni("vni"), + vrf("vrf"), iface("iface"), postscript("post-script"), routing("routing"), diff --git a/app/src/main/java/io/vproxy/app/app/cmd/ResourceType.java b/app/src/main/java/io/vproxy/app/app/cmd/ResourceType.java index a051543e1..c02ea48d1 100644 --- a/app/src/main/java/io/vproxy/app/app/cmd/ResourceType.java +++ b/app/src/main/java/io/vproxy/app/app/cmd/ResourceType.java @@ -22,7 +22,7 @@ public enum ResourceType { ck("cert-key"), sw("switch"), - vpc("vpc"), + vrf("vrf"), arp("arp"), conntrack("ct"), trace("trace"), diff --git a/app/src/main/java/io/vproxy/app/app/cmd/handle/param/VniHandle.java b/app/src/main/java/io/vproxy/app/app/cmd/handle/param/VrfParamHandle.java similarity index 56% rename from app/src/main/java/io/vproxy/app/app/cmd/handle/param/VniHandle.java rename to app/src/main/java/io/vproxy/app/app/cmd/handle/param/VrfParamHandle.java index aa01ce88d..6e3ea5eca 100644 --- a/app/src/main/java/io/vproxy/app/app/cmd/handle/param/VniHandle.java +++ b/app/src/main/java/io/vproxy/app/app/cmd/handle/param/VrfParamHandle.java @@ -4,26 +4,26 @@ import io.vproxy.app.app.cmd.Param; import io.vproxy.base.util.exception.XException; -public class VniHandle { - private VniHandle() { +public class VrfParamHandle { + private VrfParamHandle() { } public static int get(Command cmd) throws Exception { - String vniStr = cmd.args.get(Param.vni); - int vni; + String vrfStr = cmd.args.get(Param.vrf); + int vrf; try { - vni = Integer.parseInt(vniStr); + vrf = Integer.parseInt(vrfStr); } catch (NumberFormatException e) { - throw new Exception("vni not a valid integer"); + throw new Exception("vrf not a valid integer"); } - return vni; + return vrf; } public static void check(Command cmd) throws Exception { try { get(cmd); } catch (Exception e) { - throw new XException("invalid value for " + Param.vni.fullname + ": " + e.getMessage()); + throw new XException("invalid value for " + Param.vrf.fullname + ": " + e.getMessage()); } } } diff --git a/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/ArpHandle.java b/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/ArpHandle.java index d07916b18..8182a58b0 100644 --- a/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/ArpHandle.java +++ b/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/ArpHandle.java @@ -32,7 +32,7 @@ public static void checkMacName(Resource self) throws Exception { public static void add(Command cmd) throws Exception { MacAddress mac = new MacAddress(cmd.resource.alias); - VirtualNetwork net = VpcHandle.get(cmd.prepositionResource); + VirtualNetwork net = VrfHandle.get(cmd.prepositionResource); IP ip = null; if (cmd.args.containsKey(Param.ip)) { @@ -55,20 +55,20 @@ public static int count(Resource parent) throws Exception { } public static List list(Resource parent) throws Exception { - String vpcStr = parent.alias; - int vpc = Integer.parseInt(vpcStr); + String vrfStr = parent.alias; + int vrf = Integer.parseInt(vrfStr); Switch sw = Application.get().switchHolder.get(parent.parentResource.alias); var networks = sw.getNetworks().values(); VirtualNetwork network = null; for (var net : networks) { - if (net.vni == vpc) { + if (net.vrf == vrf) { network = net; break; } } if (network == null) { - throw new NotFoundException("vpc", vpcStr); + throw new NotFoundException("vrf", vrfStr); } var macInArpEntries = new HashSet(); @@ -139,7 +139,7 @@ public static List list(Resource parent) throws Exception { public static void remove(Command cmd) throws Exception { MacAddress mac = new MacAddress(cmd.resource.alias); - VirtualNetwork net = VpcHandle.get(cmd.prepositionResource); + VirtualNetwork net = VrfHandle.get(cmd.prepositionResource); net.macTable.remove(mac); net.arpTable.remove(mac); } diff --git a/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/ConnectionHandle.java b/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/ConnectionHandle.java index 0b7754d78..14f61a963 100644 --- a/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/ConnectionHandle.java +++ b/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/ConnectionHandle.java @@ -50,9 +50,9 @@ public static int count(Resource parent) throws Exception { ServerGroup.ServerHandle h = ServerHandle.get(parent); return h.connectionCount(); - } else if (parent.type == ResourceType.vpc) { + } else if (parent.type == ResourceType.vrf) { - VirtualNetwork t = VpcHandle.get(parent); + VirtualNetwork t = VrfHandle.get(parent); return t.conntrack.countTcpEntries(); } else @@ -96,10 +96,10 @@ public static List list(Resource parent) throws Exception { connections.add(new Conn(c)); } - } else if (parent.type == ResourceType.vpc) { + } else if (parent.type == ResourceType.vrf) { // try to get connections from switch-network - VirtualNetwork network = VpcHandle.get(parent); + VirtualNetwork network = VrfHandle.get(parent); Collection entries = network.conntrack.listTcpEntries(); connections = new ArrayList<>(entries.size()); for (var t : entries) { diff --git a/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/ConntrackHandle.java b/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/ConntrackHandle.java index 40214018f..17fb961e3 100644 --- a/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/ConntrackHandle.java +++ b/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/ConntrackHandle.java @@ -28,20 +28,20 @@ public static int count(Resource parent) throws Exception { } private static VirtualNetwork getNetwork(Resource parent) throws Exception { - String vpcStr = parent.alias; - int vpc = Integer.parseInt(vpcStr); + String vrfStr = parent.alias; + int vrf = Integer.parseInt(vrfStr); Switch sw = Application.get().switchHolder.get(parent.parentResource.alias); var networks = sw.getNetworks().values(); VirtualNetwork network = null; for (var net : networks) { - if (net.vni == vpc) { + if (net.vrf == vrf) { network = net; break; } } if (network == null) { - throw new NotFoundException("vpc", vpcStr); + throw new NotFoundException("vrf", vrfStr); } return network; } diff --git a/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/FubukiEtherIPHandle.java b/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/FubukiEtherIPHandle.java index c56c490b2..7aea02be7 100644 --- a/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/FubukiEtherIPHandle.java +++ b/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/FubukiEtherIPHandle.java @@ -15,13 +15,13 @@ private FubukiEtherIPHandle() { public static void add(Command cmd) throws Exception { var name = cmd.resource.alias; - var vni = Integer.parseInt(cmd.args.get(Param.vni)); + var vrf = Integer.parseInt(cmd.args.get(Param.vrf)); var ip = IpParamHandle.get(cmd); if (!(ip instanceof IPv4)) { throw new XException(ip + " is not valid ipv4"); } Switch sw = Application.get().switchHolder.get(cmd.prepositionResource.alias); - sw.addFubukiEtherIP(name, vni, (IPv4) ip); + sw.addFubukiEtherIP(name, vrf, (IPv4) ip); } } diff --git a/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/FubukiHandle.java b/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/FubukiHandle.java index 1f906aa1c..4e295dc97 100644 --- a/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/FubukiHandle.java +++ b/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/FubukiHandle.java @@ -16,7 +16,7 @@ private FubukiHandle() { public static void add(Command cmd) throws Exception { var node = cmd.resource.alias; var pass = cmd.args.get(Param.pass); - var vni = Integer.parseInt(cmd.args.get(Param.vni)); + var vrf = Integer.parseInt(cmd.args.get(Param.vrf)); var mac = MacHandle.get(cmd); var addr = AddrHandle.get(cmd); IPMask localAddr = null; @@ -24,6 +24,6 @@ public static void add(Command cmd) throws Exception { localAddr = IpParamHandle.getIPMask(cmd); } Switch sw = Application.get().switchHolder.get(cmd.prepositionResource.alias); - sw.addFubuki(node, pass, vni, mac, addr, localAddr); + sw.addFubuki(node, pass, vrf, mac, addr, localAddr); } } diff --git a/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/IpHandle.java b/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/IpHandle.java index be33921b2..dfffb02f5 100644 --- a/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/IpHandle.java +++ b/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/IpHandle.java @@ -28,12 +28,12 @@ public static void checkIpName(Resource resource) throws XException { } public static Collection names(Resource parent) throws Exception { - VirtualNetwork net = VpcHandle.get(parent); + VirtualNetwork net = VrfHandle.get(parent); return net.ips.allIps(); } public static Collection list(Resource parent) throws Exception { - VirtualNetwork net = VpcHandle.get(parent); + VirtualNetwork net = VrfHandle.get(parent); return net.ips.entries(); } @@ -54,7 +54,7 @@ public static void add(Command cmd) throws Exception { anno = AnnotationsHandle.get(cmd); } - IPMac info = VpcHandle.get(cmd.prepositionResource).addIp(inet, macO, anno); + IPMac info = VrfHandle.get(cmd.prepositionResource).addIp(inet, macO, anno); if (cmd.args.containsKey(Param.routing)) { info.routing = RoutingHandle.get(cmd); } else { @@ -64,7 +64,7 @@ public static void add(Command cmd) throws Exception { public static void update(Command cmd) throws Exception { IP ip = IP.from(cmd.resource.alias); - VirtualNetwork net = VpcHandle.get(cmd.resource.parentResource); + VirtualNetwork net = VrfHandle.get(cmd.resource.parentResource); var opt = net.ips.entries().stream().filter(ipmac -> ipmac.ip.equals(ip)).findFirst(); if (opt.isEmpty()) { throw new NotFoundException(ResourceType.ip.fullname, cmd.resource.alias); @@ -84,6 +84,6 @@ public static void remove(Command cmd) throws Exception { } IP inet = IP.from(ipBytes); - VpcHandle.get(cmd.prepositionResource).ips.del(inet); + VrfHandle.get(cmd.prepositionResource).ips.del(inet); } } diff --git a/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/RouteHandle.java b/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/RouteHandle.java index a4015362f..a56798077 100644 --- a/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/RouteHandle.java +++ b/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/RouteHandle.java @@ -18,12 +18,12 @@ private RouteHandle() { } public static List names(Resource parent) throws Exception { - VirtualNetwork net = VpcHandle.get(parent); + VirtualNetwork net = VrfHandle.get(parent); return net.routeTable.getRules().stream().map(r -> r.alias).collect(Collectors.toList()); } public static List list(Resource parent) throws Exception { - VirtualNetwork net = VpcHandle.get(parent); + VirtualNetwork net = VrfHandle.get(parent); return net.routeTable.getRules(); } @@ -33,16 +33,16 @@ public static void checkCreateRoute(Command cmd) throws Exception { throw new Exception("missing " + Param.net.fullname); } NetworkHandle.check(cmd); - String vni = cmd.args.get(Param.vni); + String vrf = cmd.args.get(Param.vrf); String ip = cmd.args.get(Param.via); - if (vni == null && ip == null) { - throw new Exception("missing " + Param.vni.fullname + " or " + Param.via.fullname); + if (vrf == null && ip == null) { + throw new Exception("missing " + Param.vrf.fullname + " or " + Param.via.fullname); } - if (vni != null && ip != null) { - throw new Exception("cannot specify " + Param.vni.fullname + " and " + Param.via.fullname + " at the same time"); + if (vrf != null && ip != null) { + throw new Exception("cannot specify " + Param.vrf.fullname + " and " + Param.via.fullname + " at the same time"); } - if (vni != null && !Utils.isInteger(vni)) { - throw new Exception("invalid argument for " + Param.vni + ": should be an integer"); + if (vrf != null && !Utils.isInteger(vrf)) { + throw new Exception("invalid argument for " + Param.vrf + ": should be an integer"); } if (ip != null && !IP.isIpLiteral(ip)) { throw new Exception("invalid argument for " + Param.via.fullname); @@ -54,22 +54,22 @@ public static void add(Command cmd) throws Exception { Network net = NetworkHandle.get(cmd); RouteTable.RouteRule rule; - if (cmd.args.containsKey(Param.vni)) { - int vni = Integer.parseInt(cmd.args.get(Param.vni)); - rule = new RouteTable.RouteRule(alias, net, vni); + if (cmd.args.containsKey(Param.vrf)) { + int vrf = Integer.parseInt(cmd.args.get(Param.vrf)); + rule = new RouteTable.RouteRule(alias, net, vrf); } else { IP ip = IP.from(cmd.args.get(Param.via)); rule = new RouteTable.RouteRule(alias, net, ip); } - VirtualNetwork vnet = VpcHandle.get(cmd.prepositionResource); + VirtualNetwork vnet = VrfHandle.get(cmd.prepositionResource); vnet.routeTable.addRule(rule); } public static void remove(Command cmd) throws Exception { String alias = cmd.resource.alias; - VirtualNetwork net = VpcHandle.get(cmd.prepositionResource); + VirtualNetwork net = VrfHandle.get(cmd.prepositionResource); net.routeTable.delRule(alias); } } diff --git a/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/ServerSockHandle.java b/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/ServerSockHandle.java index 0aa8f0304..4d797507b 100644 --- a/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/ServerSockHandle.java +++ b/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/ServerSockHandle.java @@ -33,8 +33,8 @@ public static int count(Resource parent) throws Exception { } else if (parent.type == ResourceType.socks5) { return Socks5ServerHandle.get(parent).acceptorGroup.list().size(); } else { - assert parent.type == ResourceType.vpc; - return VpcHandle.get(parent).conntrack.countTcpListenEntry(); + assert parent.type == ResourceType.vrf; + return VrfHandle.get(parent).conntrack.countTcpListenEntry(); } } @@ -60,8 +60,8 @@ public static List list(Resource parent) throws Exception { servers.add(new ServerSock2(e)); } } else { - assert parent.type == ResourceType.vpc; - var ls = VpcHandle.get(parent).conntrack.listTcpListenEntries(); + assert parent.type == ResourceType.vrf; + var ls = VrfHandle.get(parent).conntrack.listTcpListenEntries(); servers = new ArrayList<>(ls.size()); for (var e : ls) { servers.add(new ServerSock2(e)); diff --git a/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/TapHandle.java b/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/TapHandle.java index 374e80469..a88916592 100644 --- a/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/TapHandle.java +++ b/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/TapHandle.java @@ -15,9 +15,9 @@ public static void add(Command cmd) throws Exception { if (dev.contains("%")) { throw new XException("wildcard % in tap dev is forbidden"); } - int vni = Integer.parseInt(cmd.args.get(Param.vni)); + int vrf = Integer.parseInt(cmd.args.get(Param.vrf)); String postScript = cmd.args.get(Param.postscript); Switch sw = Application.get().switchHolder.get(cmd.prepositionResource.alias); - sw.addTap(dev, vni, postScript); + sw.addTap(dev, vrf, postScript); } } diff --git a/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/TunHandle.java b/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/TunHandle.java index ca5f7d0ab..158136ba1 100644 --- a/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/TunHandle.java +++ b/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/TunHandle.java @@ -17,10 +17,10 @@ public static void add(Command cmd) throws Exception { if (dev.contains("%")) { throw new XException("wildcard % in tun dev is forbidden"); } - int vni = Integer.parseInt(cmd.args.get(Param.vni)); + int vrf = Integer.parseInt(cmd.args.get(Param.vrf)); MacAddress mac = MacHandle.get(cmd); String postScript = cmd.args.get(Param.postscript); Switch sw = Application.get().switchHolder.get(cmd.prepositionResource.alias); - sw.addTun(dev, vni, mac, postScript); + sw.addTun(dev, vrf, mac, postScript); } } diff --git a/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/VLanAdaptorHandle.java b/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/VLanAdaptorHandle.java index 367a345e9..379c875b2 100644 --- a/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/VLanAdaptorHandle.java +++ b/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/VLanAdaptorHandle.java @@ -3,7 +3,7 @@ import io.vproxy.app.app.Application; import io.vproxy.app.app.cmd.Command; import io.vproxy.app.app.cmd.Param; -import io.vproxy.app.app.cmd.handle.param.VniHandle; +import io.vproxy.app.app.cmd.handle.param.VrfParamHandle; import io.vproxy.base.util.Utils; import io.vproxy.base.util.exception.XException; import io.vproxy.vswitch.Switch; @@ -28,13 +28,13 @@ public static void add(Command cmd) throws Exception { throw new XException(vlan + " out of range: expecting [0, 4095]"); } - int vni = vlan; - if (cmd.args.containsKey(Param.vni)) { - vni = VniHandle.get(cmd); + int vrf = vlan; + if (cmd.args.containsKey(Param.vrf)) { + vrf = VrfParamHandle.get(cmd); } Switch sw = Application.get().switchHolder.get(cmd.prepositionResource.alias); - sw.addVLanAdaptor(parent, vlan, vni); + sw.addVLanAdaptor(parent, vlan, vrf); } } diff --git a/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/VpcHandle.java b/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/VrfHandle.java similarity index 69% rename from app/src/main/java/io/vproxy/app/app/cmd/handle/resource/VpcHandle.java rename to app/src/main/java/io/vproxy/app/app/cmd/handle/resource/VrfHandle.java index 0c063a25c..176b96fc1 100644 --- a/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/VpcHandle.java +++ b/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/VrfHandle.java @@ -15,23 +15,23 @@ import java.util.Comparator; import java.util.List; -public class VpcHandle { - private VpcHandle() { +public class VrfHandle { + private VrfHandle() { } - public static void checkVpcName(Resource resource) throws Exception { - String vpc = resource.alias; + public static void checkVrfName(Resource resource) throws Exception { + String vrf = resource.alias; try { - Integer.parseInt(vpc); + Integer.parseInt(vrf); } catch (NumberFormatException e) { - throw new Exception("vpc name should be an integer representing the vni"); + throw new Exception("vrf name should be an integer"); } } public static VirtualNetwork get(Resource self) throws Exception { - int vpc = Integer.parseInt(self.alias); + int vrf = Integer.parseInt(self.alias); Switch sw = SwitchHandle.get(self.parentResource); - return sw.getNetwork(vpc); + return sw.getNetwork(vrf); } public static void add(Command cmd) throws Exception { @@ -53,26 +53,26 @@ public static void remove(Command cmd) throws Exception { sw.delNetwork(Integer.parseInt(cmd.resource.alias)); } - public static List list(Resource parentResource) throws Exception { + public static List list(Resource parentResource) throws Exception { Switch sw = Application.get().switchHolder.get(parentResource.alias); var networks = sw.getNetworks().values(); - List ls = new ArrayList<>(); + List ls = new ArrayList<>(); for (var net : networks) { - ls.add(new VpcEntry(net.vni, net.v4network, net.v6network, net.getAnnotations())); + ls.add(new VrfEntry(net.vrf, net.v4network, net.v6network, net.getAnnotations())); } - ls.sort(Comparator.comparingInt(a -> a.vpc)); + ls.sort(Comparator.comparingInt(a -> a.vrf)); return ls; } - public static class VpcEntry { - public final int vpc; + public static class VrfEntry { + public final int vrf; public final Network v4network; public final Network v6network; public final Annotations annotations; - public VpcEntry(int vpc, Network v4network, Network v6network, Annotations annotations) { - this.vpc = vpc; + public VrfEntry(int vrf, Network v4network, Network v6network, Annotations annotations) { + this.vrf = vrf; this.v4network = v4network; this.v6network = v6network; this.annotations = annotations; @@ -80,9 +80,9 @@ public VpcEntry(int vpc, Network v4network, Network v6network, Annotations annot @Override public String toString() { - return vpc + " -> v4network " + v4network - + (v6network != null ? (" v6network " + v6network) : "") - + (!annotations.isEmpty() ? (" annotations " + annotations) : ""); + return vrf + " -> v4network " + v4network + + (v6network != null ? (" v6network " + v6network) : "") + + (!annotations.isEmpty() ? (" annotations " + annotations) : ""); } } } diff --git a/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/XDPHandle.java b/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/XDPHandle.java index eff27a262..8acf924f4 100644 --- a/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/XDPHandle.java +++ b/app/src/main/java/io/vproxy/app/app/cmd/handle/resource/XDPHandle.java @@ -29,13 +29,13 @@ public static void add(Command cmd) throws Exception { busyPollBudget = BusyPollHandle.get(cmd); } boolean rxGenChecksum = cmd.flags.contains(Flag.rxgencsum); - int vni = VniHandle.get(cmd); + int vrf = VrfParamHandle.get(cmd); boolean offload = cmd.flags.contains(Flag.offload); var nic = cmd.resource.alias; var mode = BPFModeHandle.get(cmd, BPFMode.SKB); var createResult = SwitchUtils.createBPFObjectWithReusedMaps( - sw, vni, (reuseMap) -> BPFObject.loadAndAttachToNic(nic, reuseMap, mode, true) + sw, vrf, (reuseMap) -> BPFObject.loadAndAttachToNic(nic, reuseMap, mode, true) ); var bpfobj = createResult.object(); @@ -44,7 +44,7 @@ public static void add(Command cmd) throws Exception { var macMap = createResult.map(); var srcmac2countMap = bpfobj.getMap(Prebuilt.DEFAULT_SRC_MAC_TO_COUNT_MAP_NAME); - sw.addXDP(nic, vni, umem, new XDPIface.XDPParams( + sw.addXDP(nic, vrf, umem, new XDPIface.XDPParams( queueId, rxRingSize, txRingSize, mode, zeroCopy, busyPollBudget, rxGenChecksum, offload, new XDPIface.BPFInfo(bpfobj, xskMap, macMap, srcmac2countMap, createResult.groupName()))); } catch (Exception e) { diff --git a/app/src/main/java/io/vproxy/app/controller/DockerNetworkDriver.java b/app/src/main/java/io/vproxy/app/controller/DockerNetworkDriver.java index 8e1e19e8a..677a309e9 100644 --- a/app/src/main/java/io/vproxy/app/controller/DockerNetworkDriver.java +++ b/app/src/main/java/io/vproxy/app/controller/DockerNetworkDriver.java @@ -9,7 +9,7 @@ public interface DockerNetworkDriver { String PERSISTENT_CONFIG_FILE = "/x-etc/docker/.vproxy/vproxy.last"; String PERSISTENT_SCRIPT = "/x-etc/docker/.vproxy/setup.sh"; - String VNI_OPTION = "docker-plugin.vproxy.io/network-vni"; + String VRF_OPTION = "docker-plugin.vproxy.io/network-vrf"; String SUBNET4_OPTION = "docker-plugin.vproxy.io/network-subnet-v4"; String SUBNET6_OPTION = "docker-plugin.vproxy.io/network-subnet-v6"; diff --git a/app/src/main/java/io/vproxy/app/controller/DockerNetworkDriverImpl.java b/app/src/main/java/io/vproxy/app/controller/DockerNetworkDriverImpl.java index 9386a3098..a6824a3ce 100644 --- a/app/src/main/java/io/vproxy/app/controller/DockerNetworkDriverImpl.java +++ b/app/src/main/java/io/vproxy/app/controller/DockerNetworkDriverImpl.java @@ -36,21 +36,21 @@ public class DockerNetworkDriverImpl implements DockerNetworkDriver { private static final String NETWORK_ENTRY_VETH_PREFIX = "vproxy"; private static final String NETWORK_ENTRY_VETH_PEER_SUFFIX = "sw"; private static final String POD_VETH_PREFIX = "veth"; - private static final int NETWORK_ENTRY_VNI = 15999999; - private static final int VNI_MAX = 9999999; + private static final int NETWORK_ENTRY_VRF = 15999999; + private static final int VRF_MAX = 9999999; @Override public synchronized void createNetwork(CreateNetworkRequest req) throws Exception { // validate options - int optionVNI = 0; - if (req.optionsDockerNetworkGeneric.containsKey(VNI_OPTION)) { - String vniStr = req.optionsDockerNetworkGeneric.get(VNI_OPTION); - if (!Utils.isInteger(vniStr)) { - throw new Exception(VNI_OPTION + ": " + vniStr + " is not an integer"); + int optionVRF = 0; + if (req.optionsDockerNetworkGeneric.containsKey(VRF_OPTION)) { + String vrfStr = req.optionsDockerNetworkGeneric.get(VRF_OPTION); + if (!Utils.isInteger(vrfStr)) { + throw new Exception(VRF_OPTION + ": " + vrfStr + " is not an integer"); } - optionVNI = Integer.parseInt(vniStr); - if (optionVNI < 1 || optionVNI > VNI_MAX) { // nic name limit - throw new Exception(VNI_OPTION + ": " + vniStr + " is out of the plugin supported vni range: [1, " + VNI_MAX + "]"); + optionVRF = Integer.parseInt(vrfStr); + if (optionVRF < 1 || optionVRF > VRF_MAX) { // nic name limit + throw new Exception(VRF_OPTION + ": " + vrfStr + " is out of the plugin supported vrf range: [1, " + VRF_MAX + "]"); } } Network optionV4Net = null; @@ -180,25 +180,25 @@ public synchronized void createNetwork(CreateNetworkRequest req) throws Exceptio // handle var sw = ensureSwitch(); IntMap networks = sw.getNetworks(); - int selectedVni = 0; - if (optionVNI == 0) { + int selectedVrf = 0; + if (optionVRF == 0) { for (int i : networks.keySet()) { - if (selectedVni < i) { - selectedVni = i; + if (selectedVrf < i) { + selectedVrf = i; } } - selectedVni += 1; // greater than the biggest recorded vni - if (selectedVni > VNI_MAX) { - throw new Exception("cannot use auto selected vni " + selectedVni + ", out of range: [1," + VNI_MAX + "]"); + selectedVrf += 1; // greater than the biggest recorded vrf + if (selectedVrf > VRF_MAX) { + throw new Exception("cannot use auto selected vrf " + selectedVrf + ", out of range: [1," + VRF_MAX + "]"); } } else { try { - sw.getNetwork(optionVNI); + sw.getNetwork(optionVRF); } catch (NotFoundException ignore) { - selectedVni = optionVNI; + selectedVrf = optionVRF; } - if (selectedVni == 0) { - throw new Exception(VNI_OPTION + ": " + optionVNI + " already exists"); + if (selectedVrf == 0) { + throw new Exception(VRF_OPTION + ": " + optionVRF + " already exists"); } } @@ -215,29 +215,29 @@ public synchronized void createNetwork(CreateNetworkRequest req) throws Exceptio } else { v6net = optionV6Net; } - sw.addNetwork(selectedVni, v4net, v6net, new Annotations(Collections.singletonMap(NETWORK_NETWORK_ID_ANNOTATION, req.networkId))); - Logger.alert("network added: vni=" + selectedVni + ", v4=" + v4net + ", v6=" + v6net + ", docker:networkId=" + req.networkId); - VirtualNetwork net = sw.getNetwork(selectedVni); + sw.addNetwork(selectedVrf, v4net, v6net, new Annotations(Collections.singletonMap(NETWORK_NETWORK_ID_ANNOTATION, req.networkId))); + Logger.alert("network added: vrf=" + selectedVrf + ", v4=" + v4net + ", v6=" + v6net + ", docker:networkId=" + req.networkId); + VirtualNetwork net = sw.getNetwork(selectedVrf); if (!req.networkId.equals(net.getAnnotations().other.get(NETWORK_NETWORK_ID_ANNOTATION))) { Logger.shouldNotHappen("adding network failed, maybe concurrent modification"); try { - sw.delNetwork(selectedVni); + sw.delNetwork(selectedVrf); } catch (Exception e2) { - Logger.error(LogType.SYS_ERROR, "rollback network " + selectedVni + " failed", e2); + Logger.error(LogType.SYS_ERROR, "rollback network " + selectedVrf + " failed", e2); } throw new Exception("unexpected state"); } // add entry veth try { - var umem = ensureUMem("" + selectedVni); + var umem = ensureUMem("" + selectedVrf); createNetworkEntryVeth(sw, umem, net); } catch (Exception e) { - Logger.error(LogType.SYS_ERROR, "creating network entry veth for network " + selectedVni + " failed", e); + Logger.error(LogType.SYS_ERROR, "creating network entry veth for network " + selectedVrf + " failed", e); try { - sw.delNetwork(selectedVni); + sw.delNetwork(selectedVrf); } catch (Exception e2) { - Logger.error(LogType.SYS_ERROR, "rollback network " + selectedVni + " failed", e2); + Logger.error(LogType.SYS_ERROR, "rollback network " + selectedVrf + " failed", e2); } throw e; } @@ -250,7 +250,7 @@ public synchronized void createNetwork(CreateNetworkRequest req) throws Exceptio GATEWAY_IP_ANNOTATION, GATEWAY_IPv4_FLAG_VALUE, GATEWAY_SUBNET_ANNOTATION, data.pool ))); - Logger.alert("ip added: vni=" + selectedVni + ", ip=" + gateway + ", mac=" + mac); + Logger.alert("ip added: vrf=" + selectedVrf + ", ip=" + gateway + ", mac=" + mac); } if (!req.ipv6Data.isEmpty()) { @@ -262,7 +262,7 @@ public synchronized void createNetwork(CreateNetworkRequest req) throws Exceptio GATEWAY_IP_ANNOTATION, GATEWAY_IPv6_FLAG_VALUE, GATEWAY_SUBNET_ANNOTATION, data.pool ))); - Logger.alert("ip added: vni=" + selectedVni + ", ip=" + gateway + ", mac=" + mac); + Logger.alert("ip added: vrf=" + selectedVrf + ", ip=" + gateway + ", mac=" + mac); } } @@ -346,7 +346,7 @@ private void createUMemHolderXDPIface(Switch sw, UMem umem) throws Exception { private void createNetworkEntryVeth(Switch sw, UMem umem, VirtualNetwork net) throws Exception { int index = 0; if (net != null) { - index = net.vni; + index = net.vrf; } String hostNic = NETWORK_ENTRY_VETH_PREFIX + index; @@ -377,7 +377,7 @@ private XDPIface createXDPIface(Switch sw, UMem umem, VirtualNetwork net, String SwitchUtils.GetSharedMapGroupResult reusedResult; BPFObject bpfobj; if (isPodNic) { - reusedResult = SwitchUtils.createBPFObjectWithReusedMaps(sw, net.vni, reusedMaps -> + reusedResult = SwitchUtils.createBPFObjectWithReusedMaps(sw, net.vrf, reusedMaps -> BPFObject.loadAndAttachToNic(nicname, reusedMaps, BPFMode.SKB, true) ); bpfobj = reusedResult.object(); @@ -401,7 +401,7 @@ private XDPIface createXDPIface(Switch sw, UMem umem, VirtualNetwork net, String XDPIface iface; try { - iface = sw.addXDP(nicname, net != null ? net.vni : NETWORK_ENTRY_VNI, umem, + iface = sw.addXDP(nicname, net != null ? net.vrf : NETWORK_ENTRY_VRF, umem, new XDPIface.XDPParams(0, 32, 32, BPFMode.SKB, false, 0, false, isPodNic, new XDPIface.BPFInfo( @@ -447,8 +447,8 @@ public synchronized void deleteNetwork(String networkId) throws Exception { deleteNetworkEntryVeth(sw, net); - sw.delNetwork(net.vni); - Logger.alert("network deleted: vni=" + net.vni + ", docker:networkId=" + networkId); + sw.delNetwork(net.vrf); + Logger.alert("network deleted: vrf=" + net.vrf + ", docker:networkId=" + networkId); persistConfig(); } @@ -514,8 +514,8 @@ private void persistConfig() { } private void deleteNetworkEntryVeth(Switch sw, VirtualNetwork net) throws Exception { - String swNic = NETWORK_ENTRY_VETH_PREFIX + net.vni + NETWORK_ENTRY_VETH_PEER_SUFFIX; - deleteNic(sw, getUMem("" + net.vni), swNic); + String swNic = NETWORK_ENTRY_VETH_PREFIX + net.vrf + NETWORK_ENTRY_VETH_PEER_SUFFIX; + deleteNic(sw, getUMem("" + net.vrf), swNic); } @Override @@ -556,7 +556,7 @@ public synchronized CreateEndpointResponse createEndpoint(CreateEndpointRequest XDPIface xdpIface = createXDPIface(sw, umem, net, podNic); xdpIface.setAnnotations(new Annotations(anno)); - Logger.alert("xdp added: " + xdpIface.nic + ", vni=" + net.vni + Logger.alert("xdp added: " + xdpIface.nic + ", vrf=" + net.vrf + ", endpointId=" + req.endpointId + ", ipv4=" + anno.get(VETH_ENDPOINT_IPv4_ANNOTATION) + ", ipv6=" + anno.get(VETH_ENDPOINT_IPv6_ANNOTATION) diff --git a/app/src/main/java/io/vproxy/app/process/Shutdown.java b/app/src/main/java/io/vproxy/app/process/Shutdown.java index 2482f1299..83681dd8d 100644 --- a/app/src/main/java/io/vproxy/app/process/Shutdown.java +++ b/app/src/main/java/io/vproxy/app/process/Shutdown.java @@ -639,11 +639,11 @@ public static String currentConfig() { commands.add(cmd); umemNames.add(umem.alias); } - // create vpc + // create vrf for (var key : sw.getNetworks().keySet()) { - int vpc = key; - VirtualNetwork network = sw.getNetworks().get(vpc); - cmd = "add vpc " + vpc + " to switch " + sw.alias + " v4network " + network.v4network; + int vrf = key; + VirtualNetwork network = sw.getNetworks().get(vrf); + cmd = "add vrf " + vrf + " to switch " + sw.alias + " v4network " + network.v4network; if (network.v6network != null) { cmd += " v6network " + network.v6network; } @@ -658,7 +658,7 @@ public static String currentConfig() { if (ipmac.annotations.nosave) { continue; } - cmd = "add ip " + ipmac.ip.formatToIPString() + " to vpc " + vpc + " in switch " + sw.alias + cmd = "add ip " + ipmac.ip.formatToIPString() + " to vrf " + vrf + " in switch " + sw.alias + " mac " + ipmac.mac + " routing " + (ipmac.routing ? "on" : "off"); if (!ipmac.annotations.isEmpty()) { @@ -678,20 +678,20 @@ public static String currentConfig() { } } if (!hasDefaultV4) { - cmd = "remove route " + RouteTable.defaultRuleName + " from vpc " + vpc + " in switch " + sw.alias; + cmd = "remove route " + RouteTable.defaultRuleName + " from vrf " + vrf + " in switch " + sw.alias; commands.add(cmd); } if (!hasDefaultV6 && network.v6network != null) { - cmd = "remove route " + RouteTable.defaultRuleV6Name + " from vpc " + vpc + " in switch " + sw.alias; + cmd = "remove route " + RouteTable.defaultRuleV6Name + " from vrf " + vrf + " in switch " + sw.alias; commands.add(cmd); } for (var r : network.routeTable.getRules()) { if (r.alias.equals(RouteTable.defaultRuleName) || r.alias.equals(RouteTable.defaultRuleV6Name)) { continue; } - cmd = "add route " + r.alias + " to vpc " + vpc + " in switch " + sw.alias + " network " + r.rule; + cmd = "add route " + r.alias + " to vrf " + vrf + " in switch " + sw.alias + " network " + r.rule; if (r.ip == null) { - cmd += " vni " + r.toVni; + cmd += " vrf " + r.toVrf; } else { cmd += " via " + r.ip.formatToIPString(); } @@ -714,7 +714,7 @@ public static String currentConfig() { if (!(iface instanceof TapIface tap)) { continue; } - cmd = "add tap " + tap.dev + " to switch " + sw.alias + " vni " + tap.localSideVni; + cmd = "add tap " + tap.dev + " to switch " + sw.alias + " vrf " + tap.localSideVrf; if (tap.postScript != null && !tap.postScript.isBlank()) { cmd += " post-script " + tap.postScript; } @@ -727,13 +727,13 @@ public static String currentConfig() { } if (iface instanceof FubukiTunIface f) { cmd = "add fubuki " + f.nodeName + " to switch " + sw.alias - + " password " + f.key + " vni " + f.localSideVni + " mac " + f.mac + + " password " + f.key + " vrf " + f.localSideVrf + " mac " + f.mac + " address " + f.serverIPPort.formatToIPPortString(); if (f.getLocalAddr() != null) { cmd += " ip " + f.getLocalAddr().formatToIPMaskString(); } } else { - cmd = "add tun " + tun.dev + " to switch " + sw.alias + " vni " + tun.localSideVni + cmd = "add tun " + tun.dev + " to switch " + sw.alias + " vrf " + tun.localSideVrf + " mac " + tun.mac; if (tun.postScript != null && !tun.postScript.isBlank()) { cmd += " post-script " + tun.postScript; @@ -757,7 +757,7 @@ public static String currentConfig() { + " tx-ring-size " + xdp.params.txRingSize() + " mode " + xdp.params.mode().name() + " busy-poll " + xdp.params.busyPollBudget() - + " vni " + xdp.vni; + + " vrf " + xdp.vrf; if (xdp.params.offload()) { cmd += " offload"; } @@ -775,7 +775,7 @@ public static String currentConfig() { continue; } cmd = "add fubuki-etherip " + etherip.getParentIface().name().substring("fubuki:".length()) + - " to switch " + sw.alias + " vni " + etherip.localSideVni + " ip " + etherip.targetIP.formatToIPString(); + " to switch " + sw.alias + " vrf " + etherip.localSideVrf + " ip " + etherip.targetIP.formatToIPString(); commands.add(cmd); } // create sub interfaces @@ -786,7 +786,7 @@ public static String currentConfig() { if (!switchInterfaceRequiresSaving(vif.getParentIface())) { continue; } - cmd = "add vlan " + vif.remoteVLan + "@" + vif.getParentIface().name() + " to switch " + sw.alias + " vni " + vif.localVni; + cmd = "add vlan " + vif.remoteVLan + "@" + vif.getParentIface().name() + " to switch " + sw.alias + " vrf " + vif.localVrf; commands.add(cmd); } // set iface options @@ -804,14 +804,14 @@ public static String currentConfig() { } // add persistent arp records var networks = sw.getNetworks(); - for (var vni : networks.keySet()) { - var network = networks.get(vni); + for (var vrf : networks.keySet()) { + var network = networks.get(vrf); var macEntries = network.macTable.listEntries(); for (var mac : macEntries) { if (mac.getTimeout() != -1) { continue; } - cmd = "add arp " + mac.mac + " to vpc " + network.vni + " in sw " + sw.alias + " iface " + mac.iface.name(); + cmd = "add arp " + mac.mac + " to vrf " + network.vrf + " in sw " + sw.alias + " iface " + mac.iface.name(); commands.add(cmd); } var ipEntries = network.arpTable.listEntries(); @@ -819,7 +819,7 @@ public static String currentConfig() { if (ip.getTimeout() != -1) { continue; } - cmd = "add arp " + ip.mac + " to vpc " + network.vni + " in sw " + sw.alias + " ip " + ip.ip.formatToIPString(); + cmd = "add arp " + ip.mac + " to vrf " + network.vrf + " in sw " + sw.alias + " ip " + ip.ip.formatToIPString(); commands.add(cmd); } } diff --git a/core/src/main/java/io/vproxy/vswitch/PacketBuffer.java b/core/src/main/java/io/vproxy/vswitch/PacketBuffer.java index e48ebeb48..fe8b18fe0 100644 --- a/core/src/main/java/io/vproxy/vswitch/PacketBuffer.java +++ b/core/src/main/java/io/vproxy/vswitch/PacketBuffer.java @@ -30,12 +30,12 @@ public static PacketBuffer fromVXLanBytes(Iface devin, ByteArray buf, int pktOff return new PacketBuffer(devin, buf, pktOff, pad); } - public static PacketBuffer fromEtherBytes(Iface devin, int vni, ByteArray buf, int pktOff, int pad) { - return new PacketBuffer(devin, vni, buf, pktOff, pad); + public static PacketBuffer fromEtherBytes(Iface devin, int vrf, ByteArray buf, int pktOff, int pad) { + return new PacketBuffer(devin, vrf, buf, pktOff, pad); } - public static PacketBuffer fromIpBytes(Iface devin, int vni, ByteArray buf, int pktOff, int pad) { - return new PacketBuffer(devin, vni, buf, pktOff, pad, FLAG_IP); + public static PacketBuffer fromIpBytes(Iface devin, int vrf, ByteArray buf, int pktOff, int pad) { + return new PacketBuffer(devin, vrf, buf, pktOff, pad, FLAG_IP); } public static PacketBuffer fromPacket(VXLanPacket pkt) { @@ -58,7 +58,7 @@ public static PacketBuffer fromPacket(VirtualNetwork network, AbstractIpPacket p // this will be set when tx dev is determined // this will be set before passing to packet filters, and cleared after it's handled public Iface devout; - public int vni; // vni or vlan number, must always be valid + public int vrf; // vrf number, must always be valid public VirtualNetwork network; // might be null public int flags; @@ -106,18 +106,18 @@ private PacketBuffer(Iface devin, ByteArray fullbuf, int pktOff, int pad) { } // fromEtherBytes - private PacketBuffer(Iface devin, int vni, ByteArray fullbuf, int pktOff, int pad) { + private PacketBuffer(Iface devin, int vrf, ByteArray fullbuf, int pktOff, int pad) { super(fullbuf, pktOff, pad); this.devin = devin; - this.vni = vni; + this.vrf = vrf; this.flags = 0; } // fromIpBytes - private PacketBuffer(Iface devin, int vni, ByteArray fullbuf, int pktOff, int pad, int flags) { + private PacketBuffer(Iface devin, int vrf, ByteArray fullbuf, int pktOff, int pad, int flags) { super(fullbuf, pktOff, pad); this.devin = devin; - this.vni = vni; + this.vrf = vrf; this.flags = flags; } @@ -125,7 +125,7 @@ private PacketBuffer(Iface devin, int vni, ByteArray fullbuf, int pktOff, int pa private PacketBuffer(VXLanPacket pkt) { super(null); this.devin = null; - this.vni = pkt.getVni(); + this.vrf = pkt.getVni(); this.flags = FLAG_VXLAN; this.vxlan = pkt; initPackets(true, false, false); @@ -135,7 +135,7 @@ private PacketBuffer(VXLanPacket pkt) { private PacketBuffer(VirtualNetwork network, EthernetPacket pkt) { super(null); this.devin = null; - this.vni = network.vni; + this.vrf = network.vrf; this.network = network; this.flags = 0; this.pkt = pkt; @@ -146,7 +146,7 @@ private PacketBuffer(VirtualNetwork network, EthernetPacket pkt) { private PacketBuffer(VirtualNetwork network, AbstractIpPacket pkt) { super(null); this.devin = null; - this.vni = network.vni; + this.vrf = network.vrf; this.network = network; this.flags = FLAG_IP; this.ipPkt = pkt; @@ -182,7 +182,7 @@ public String init() { } if ((flags & FLAG_VXLAN) == FLAG_VXLAN) { this.vxlan = (VXLanPacket) pkt; - this.vni = this.vxlan.getVni(); + this.vrf = this.vxlan.getVni(); initPackets(true, false, false); } else if ((flags & FLAG_IP) == FLAG_IP) { this.ipPkt = (AbstractIpPacket) pkt; @@ -313,25 +313,25 @@ public PacketFullTuple getFullTuple() { } public void setNetwork(VirtualNetwork network) { - this.vni = network.vni; + this.vrf = network.vrf; this.network = network; if (vxlan != null) { - vxlan.setVni(network.vni); + vxlan.setVni(network.vrf); } } - public void executeWithVni(int vni, Runnable r) { - if (this.vni == vni) { + public void executeWithVrf(int vrf, Runnable r) { + if (this.vrf == vrf) { r.run(); return; } VirtualNetwork networkBackup = this.network; - this.vni = vni; + this.vrf = vrf; this.network = null; if (this.vxlan != null) { - this.vxlan.setVni(vni); + this.vxlan.setVni(vrf); } r.run(); @@ -433,12 +433,12 @@ public String toString() { pkt = udpPkt; } return "PacketBuffer{" + - "in=" + devin + - ", out=" + devout + - ", vni=" + vni + - ", pktBuf=" + (pktBuf == null ? "" : pktBuf.toHexString()) + - ", pkt=" + (pkt == null ? "" : pkt.description()) + - "}@" + Utils.toHexString(super.hashCode()); + "in=" + devin + + ", out=" + devout + + ", vrf=" + vrf + + ", pktBuf=" + (pktBuf == null ? "" : pktBuf.toHexString()) + + ", pkt=" + (pkt == null ? "" : pkt.description()) + + "}@" + Utils.toHexString(super.hashCode()); } public String description() { @@ -453,8 +453,8 @@ public String description() { pkt = udpPkt; } return "in=" + (devin == null ? "null" : devin.name()) + - ",out=" + (devout == null ? "null" : devout.name()) + - ",vni=" + vni + - (pkt == null ? "" : "," + pkt.description()); + ",out=" + (devout == null ? "null" : devout.name()) + + ",vrf=" + vrf + + (pkt == null ? "" : "," + pkt.description()); } } diff --git a/core/src/main/java/io/vproxy/vswitch/RouteTable.java b/core/src/main/java/io/vproxy/vswitch/RouteTable.java index af033f5d6..d9396dd5f 100644 --- a/core/src/main/java/io/vproxy/vswitch/RouteTable.java +++ b/core/src/main/java/io/vproxy/vswitch/RouteTable.java @@ -27,10 +27,10 @@ public RouteTable() { } public RouteTable(VirtualNetwork n) { - this.defaultV4Rule = new RouteRule(defaultRuleName, n.v4network, n.vni); + this.defaultV4Rule = new RouteRule(defaultRuleName, n.v4network, n.vrf); RouteRule defaultV6Rule = null; if (n.v6network != null) { - defaultV6Rule = new RouteRule(defaultRuleV6Name, n.v6network, n.vni); + defaultV6Rule = new RouteRule(defaultRuleV6Name, n.v6network, n.vrf); } this.defaultV6Rule = defaultV6Rule; @@ -101,31 +101,31 @@ public String toString() { public static class RouteRule implements Networks.Rule { public final String alias; public final Network rule; - public final int toVni; + public final int toVrf; public final IP ip; - public RouteRule(String alias, Network rule, int toVni) { + public RouteRule(String alias, Network rule, int toVrf) { this.alias = alias; this.rule = rule; - this.toVni = toVni; + this.toVrf = toVrf; this.ip = null; } public RouteRule(String alias, Network rule, IP ip) { this.alias = alias; this.rule = rule; - this.toVni = 0; + this.toVrf = 0; this.ip = ip; } - public boolean isLocalDirect(int currentVni) { - return ip == null && (toVni == 0 || toVni == currentVni); + public boolean isLocalDirect(int currentVrf) { + return ip == null && (toVrf == 0 || toVrf == currentVrf); } @Override public String toString() { return alias + " -> network " + rule + ( - ip == null ? (" vni " + toVni) : (" via " + ip.formatToIPString()) + ip == null ? (" vrf " + toVrf) : (" via " + ip.formatToIPString()) ); } @@ -134,15 +134,15 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; RouteRule routeRule = (RouteRule) o; - return toVni == routeRule.toVni && - Objects.equals(alias, routeRule.alias) && - Objects.equals(rule, routeRule.rule) && - Objects.equals(ip, routeRule.ip); + return toVrf == routeRule.toVrf && + Objects.equals(alias, routeRule.alias) && + Objects.equals(rule, routeRule.rule) && + Objects.equals(ip, routeRule.ip); } @Override public int hashCode() { - return Objects.hash(alias, rule, toVni, ip); + return Objects.hash(alias, rule, toVrf, ip); } } } diff --git a/core/src/main/java/io/vproxy/vswitch/Switch.java b/core/src/main/java/io/vproxy/vswitch/Switch.java index 4859528f1..555bb9ccc 100644 --- a/core/src/main/java/io/vproxy/vswitch/Switch.java +++ b/core/src/main/java/io/vproxy/vswitch/Switch.java @@ -294,30 +294,30 @@ public IntMap getNetworks() { return networks; } - public VirtualNetwork getNetwork(int vni) throws NotFoundException { - VirtualNetwork t = networks.get(vni); + public VirtualNetwork getNetwork(int vrf) throws NotFoundException { + VirtualNetwork t = networks.get(vrf); if (t == null) { - throw new NotFoundException("vni", "" + vni); + throw new NotFoundException("vrf", "" + vrf); } return t; } - public VirtualNetwork addNetwork(int vni, Network v4network, Network v6network, Annotations annotations) throws AlreadyExistException, XException { - if (networks.containsKey(vni)) { - throw new AlreadyExistException("vni " + vni + " already exists in switch " + alias); + public VirtualNetwork addNetwork(int vrf, Network v4network, Network v6network, Annotations annotations) throws AlreadyExistException, XException { + if (networks.containsKey(vrf)) { + throw new AlreadyExistException("vrf " + vrf + " already exists in switch " + alias); } if (eventLoop == null) { - throw new XException("the switch " + alias + " is not bond to any event loop, cannot add vni"); + throw new XException("the switch " + alias + " is not bond to any event loop, cannot add vrf"); } - VirtualNetwork t = new VirtualNetwork(sw, vni, eventLoop, v4network, v6network, macTableTimeout, arpTableTimeout, annotations); - networks.put(vni, t); + VirtualNetwork t = new VirtualNetwork(sw, vrf, eventLoop, v4network, v6network, macTableTimeout, arpTableTimeout, annotations); + networks.put(vrf, t); return t; } - public void delNetwork(int vni) throws NotFoundException { - VirtualNetwork t = networks.remove(vni); + public void delNetwork(int vrf) throws NotFoundException { + VirtualNetwork t = networks.remove(vrf); if (t == null) { - throw new NotFoundException("vni", "" + vni); + throw new NotFoundException("vrf", "" + vrf); } t.clearCache(); } @@ -326,7 +326,7 @@ public List getIfaces() { return new ArrayList<>(ifaces.keySet()); } - public TapIface addTap(String dev, int vni, String postScript) throws XException, IOException { + public TapIface addTap(String dev, int vrf, String postScript) throws XException, IOException { NetEventLoop netEventLoop = eventLoop; if (netEventLoop == null) { throw new XException("the switch " + alias + " is not bond to any event loop, cannot add tap device"); @@ -337,7 +337,7 @@ public TapIface addTap(String dev, int vni, String postScript) throws XException if (!(fds instanceof FDsWithTap)) { throw new IOException("tap is not supported by " + fds + ", use -Dvfd=posix or -Dvfd=windows"); } - TapIface iface = new TapIface(dev, vni, postScript); + TapIface iface = new TapIface(dev, vrf, postScript); try { initIface(iface); } catch (Exception e) { @@ -405,7 +405,7 @@ public void delIface(String ifaceName) throws NotFoundException { utilRemoveIface(iface); } - public TunIface addTun(String dev, int vni, MacAddress mac, String postScript) throws XException, IOException { + public TunIface addTun(String dev, int vrf, MacAddress mac, String postScript) throws XException, IOException { NetEventLoop netEventLoop = eventLoop; if (netEventLoop == null) { throw new XException("the switch " + alias + " is not bond to any event loop, cannot add tun device"); @@ -416,7 +416,7 @@ public TunIface addTun(String dev, int vni, MacAddress mac, String postScript) t if (!(fds instanceof FDsWithTap)) { throw new IOException("tun is not supported by " + fds + ", use -Dvfd=posix or -Dvfd=windows"); } - TunIface iface = new TunIface(dev, vni, mac, postScript); + TunIface iface = new TunIface(dev, vrf, mac, postScript); try { initIface(iface); } catch (Exception e) { @@ -429,7 +429,7 @@ public TunIface addTun(String dev, int vni, MacAddress mac, String postScript) t } public FubukiTunIface addFubuki(String nodeName, String password, - int vni, MacAddress mac, + int vrf, MacAddress mac, IPPort remoteAddr, IPMask localAddr) throws AlreadyExistException, XException { for (Iface i : ifaces.keySet()) { @@ -441,7 +441,7 @@ public FubukiTunIface addFubuki(String nodeName, String password, } } - var iface = new FubukiTunIface(vni, mac, nodeName, remoteAddr, localAddr, password); + var iface = new FubukiTunIface(vrf, mac, nodeName, remoteAddr, localAddr, password); try { initIface(iface); @@ -486,7 +486,7 @@ public RemoteSwitchIface addRemoteSwitch(String alias, IPPort vxlanSockAddr, boo return iface; } - public VLanAdaptorIface addVLanAdaptor(String parentIfaceName, int vlan, int localVni) throws XException, AlreadyExistException, NotFoundException { + public VLanAdaptorIface addVLanAdaptor(String parentIfaceName, int vlan, int localVrf) throws XException, AlreadyExistException, NotFoundException { NetEventLoop netEventLoop = eventLoop; if (netEventLoop == null) { throw new XException("the switch " + alias + " is not bond to any event loop, cannot add vlan adaptor"); @@ -503,7 +503,7 @@ public VLanAdaptorIface addVLanAdaptor(String parentIfaceName, int vlan, int loc if (parentIface == null) { throw new NotFoundException("iface", parentIfaceName); } - var vif = new VLanAdaptorIface(parentIface, vlan, localVni); + var vif = new VLanAdaptorIface(parentIface, vlan, localVrf); parentIface.addVLanAdaptor(vif); try { @@ -519,7 +519,7 @@ public VLanAdaptorIface addVLanAdaptor(String parentIfaceName, int vlan, int loc return vif; } - public FubukiEtherIPIface addFubukiEtherIP(String parentIfaceName, int vni, IPv4 targetIP) throws XException, AlreadyExistException, NotFoundException, PreconditionUnsatisfiedException { + public FubukiEtherIPIface addFubukiEtherIP(String parentIfaceName, int vrf, IPv4 targetIP) throws XException, AlreadyExistException, NotFoundException, PreconditionUnsatisfiedException { NetEventLoop netEventLoop = eventLoop; if (netEventLoop == null) { throw new XException("the switch " + alias + " is not bond to any event loop, cannot add vlan adaptor"); @@ -531,7 +531,7 @@ public FubukiEtherIPIface addFubukiEtherIP(String parentIfaceName, int vni, IPv4 throw new NotFoundException("fubuki", parentIfaceName); } var iface = (FubukiTunIface) opt.get(); - var vif = iface.addEtherIPSubIface(targetIP, vni); + var vif = iface.addEtherIPSubIface(targetIP, vrf); try { initIface(vif); @@ -546,7 +546,7 @@ public FubukiEtherIPIface addFubukiEtherIP(String parentIfaceName, int vni, IPv4 return vif; } - public XDPIface addXDP(String nic, int vni, UMem umem, XDPIface.XDPParams params) throws XException, AlreadyExistException { + public XDPIface addXDP(String nic, int vrf, UMem umem, XDPIface.XDPParams params) throws XException, AlreadyExistException { NetEventLoop netEventLoop = eventLoop; if (netEventLoop == null) { throw new XException("the switch " + this.alias + " is not bond to any event loop, cannot add xdp"); @@ -568,7 +568,7 @@ public XDPIface addXDP(String nic, int vni, UMem umem, XDPIface.XDPParams params var blockingCallback = new BlockCallback(); loop.runOnLoop(() -> { - var iface = new XDPIface(nic, vni, umem, params); + var iface = new XDPIface(nic, vrf, umem, params); try { initIface(iface); } catch (Exception e) { @@ -585,7 +585,7 @@ public XDPIface addXDP(String nic, int vni, UMem umem, XDPIface.XDPParams params return iface; } - public ProgramIface addProgramIface(String alias, int vni) throws XException, AlreadyExistException, NotFoundException { + public ProgramIface addProgramIface(String alias, int vrf) throws XException, AlreadyExistException, NotFoundException { NetEventLoop netEventLoop = eventLoop; if (netEventLoop == null) { throw new XException("the switch " + this.alias + " is not bond to any event loop, cannot add vlan adaptor"); @@ -600,9 +600,9 @@ public ProgramIface addProgramIface(String alias, int vni) throws XException, Al throw new AlreadyExistException("ProgramIface", alias); } } - var net = networks.get(vni); + var net = networks.get(vrf); if (net == null) { - throw new NotFoundException("vpc", "" + vni); + throw new NotFoundException("vrf", "" + vrf); } var iface = new ProgramIface(alias, net); @@ -663,11 +663,11 @@ private void sendPacket(PacketBuffer pkb, Iface iface) { pkb.fastpath = false; if (pkb.tcp instanceof EnhancedTCPEntry) { var tcp = (EnhancedTCPEntry) pkb.tcp; - tcp.fastpath = new Fastpath(iface, pkb.vni, pkb.pkt.getSrc(), pkb.pkt.getDst()); + tcp.fastpath = new Fastpath(iface, pkb.vrf, pkb.pkt.getSrc(), pkb.pkt.getDst()); assert Logger.lowLevelDebug("recording tcp fastpath on output: " + tcp.fastpath); } else if (pkb.udp instanceof EnhancedUDPEntry) { var udp = (EnhancedUDPEntry) pkb.udp; - udp.fastpath = new Fastpath(iface, pkb.vni, pkb.pkt.getSrc(), pkb.pkt.getDst()); + udp.fastpath = new Fastpath(iface, pkb.vrf, pkb.pkt.getSrc(), pkb.pkt.getDst()); assert Logger.lowLevelDebug("recording udp fastpath on output: " + udp.fastpath); } } else { @@ -859,11 +859,11 @@ private boolean __preHandleInputPkb0(PacketBuffer pkb) { } } - // init vpc network - int vni = pkb.vni; - VirtualNetwork network = sw.getNetwork(vni); + // init vrf network + int vrf = pkb.vrf; + VirtualNetwork network = sw.getNetwork(vrf); if (network == null) { - assert Logger.lowLevelDebug("vni not defined: " + vni); + assert Logger.lowLevelDebug("vrf not defined: " + vrf); return false; } pkb.network = network; @@ -875,7 +875,7 @@ private boolean __preHandleInputPkb0(PacketBuffer pkb) { return false; // drop } var route = network.routeTable.lookup(pkb.ipPkt.getDst()); - if (route != null && route.isLocalDirect(network.vni)) { + if (route != null && route.isLocalDirect(network.vrf)) { assert Logger.lowLevelDebug("packet from " + pkb.devin + " to " + pkb.ipPkt.getDst() + " requires no routing"); var mac = network.arpTable.lookup(pkb.ipPkt.getDst()); if (mac == null) { diff --git a/core/src/main/java/io/vproxy/vswitch/SwitchDelegate.java b/core/src/main/java/io/vproxy/vswitch/SwitchDelegate.java index 317a7be7a..161288203 100644 --- a/core/src/main/java/io/vproxy/vswitch/SwitchDelegate.java +++ b/core/src/main/java/io/vproxy/vswitch/SwitchDelegate.java @@ -66,13 +66,13 @@ public Collection getIfaces() { } public interface GetTable { - VirtualNetwork getTable(int vni); + VirtualNetwork getTable(int vrf); } private final GetTable getTableFunc; - public VirtualNetwork getNetwork(int vni) { - return getTableFunc.getTable(vni); + public VirtualNetwork getNetwork(int vrf) { + return getTableFunc.getTable(vrf); } public interface GetSelectorEventLoop { diff --git a/core/src/main/java/io/vproxy/vswitch/VirtualNetwork.java b/core/src/main/java/io/vproxy/vswitch/VirtualNetwork.java index 7492bd114..b90482b67 100644 --- a/core/src/main/java/io/vproxy/vswitch/VirtualNetwork.java +++ b/core/src/main/java/io/vproxy/vswitch/VirtualNetwork.java @@ -21,7 +21,7 @@ import java.util.concurrent.ThreadLocalRandom; public class VirtualNetwork implements WithUserData { - public final int vni; + public final int vrf; public final Network v4network; public final Network v6network; public final MacTable macTable; @@ -35,11 +35,11 @@ public class VirtualNetwork implements WithUserData { private final FDs fds; public VirtualNetwork(SwitchDelegate swCtx, - int vni, NetEventLoop loop, + int vrf, NetEventLoop loop, Network v4network, Network v6network, int macTableTimeout, int arpTableTimeout, Annotations annotations) { - this.vni = vni; + this.vrf = vrf; this.v4network = v4network; this.v6network = v6network; if (annotations == null) { @@ -163,14 +163,14 @@ public void setAnnotations(Annotations annotations) { @Override public String toString() { return "VirtualNetwork{" + - "vni=" + vni + - ", v4network=" + v4network + - ", v6network=" + v6network + - ", macTable=" + macTable + - ", arpTable=" + arpTable + - ", ips=" + ips + - ", routeTable=" + routeTable + - '}'; + "vrf=" + vrf + + ", v4network=" + v4network + + ", v6network=" + v6network + + ", macTable=" + macTable + + ", arpTable=" + arpTable + + ", ips=" + ips + + ", routeTable=" + routeTable + + '}'; } private Map userdata; diff --git a/core/src/main/java/io/vproxy/vswitch/iface/BareVXLanIface.java b/core/src/main/java/io/vproxy/vswitch/iface/BareVXLanIface.java index ed6512650..754b01414 100644 --- a/core/src/main/java/io/vproxy/vswitch/iface/BareVXLanIface.java +++ b/core/src/main/java/io/vproxy/vswitch/iface/BareVXLanIface.java @@ -5,9 +5,9 @@ import java.util.Objects; -public class BareVXLanIface extends AbstractBaseSwitchSocketIface implements LocalSideVniGetterSetter { +public class BareVXLanIface extends AbstractBaseSwitchSocketIface implements LocalSideVrfGetterSetter { public final IPPort udpSockAddress; // remote vxlan address - private int localSideVni; + private int localSideVrf; public BareVXLanIface(IPPort udpSockAddress) { super(udpSockAddress); @@ -47,8 +47,8 @@ protected void manipulate() { } @Override - public int getLocalSideVni(int hint) { - return localSideVni; + public int getLocalSideVrf(int hintVrf) { + return localSideVrf; } @Override @@ -57,7 +57,7 @@ public int getOverhead() { } @Override - public void setLocalSideVni(int vni) { - this.localSideVni = vni; + public void setLocalSideVrf(int vrf) { + this.localSideVrf = vrf; } } diff --git a/core/src/main/java/io/vproxy/vswitch/iface/DatagramInputHandler.java b/core/src/main/java/io/vproxy/vswitch/iface/DatagramInputHandler.java index ab16e227f..787580b76 100644 --- a/core/src/main/java/io/vproxy/vswitch/iface/DatagramInputHandler.java +++ b/core/src/main/java/io/vproxy/vswitch/iface/DatagramInputHandler.java @@ -132,13 +132,13 @@ private PacketBuffer handleNetworkAndGetPKB(IPPort remote) { if (iface instanceof BareVXLanIface biface) { // additional check if (isNewIface) { - biface.setLocalSideVni(pkb.vni); + biface.setLocalSideVrf(pkb.vrf); } else { - int ifaceVni = biface.getLocalSideVni(pkb.vni); - if (ifaceVni != pkb.vni) { + int ifaceVrf = biface.getLocalSideVrf(pkb.vrf); + if (ifaceVrf != pkb.vrf) { Logger.warn(LogType.INVALID_EXTERNAL_DATA, "received vxlan packet from " + remote + " " + - "but originally vni is " + ifaceVni + ", currently " + pkb.vni); + "but originally vrf is " + ifaceVrf + ", currently " + pkb.vrf); return null; } } diff --git a/core/src/main/java/io/vproxy/vswitch/iface/FubukiEtherIPIface.java b/core/src/main/java/io/vproxy/vswitch/iface/FubukiEtherIPIface.java index ca3129e4d..7588d0e6f 100644 --- a/core/src/main/java/io/vproxy/vswitch/iface/FubukiEtherIPIface.java +++ b/core/src/main/java/io/vproxy/vswitch/iface/FubukiEtherIPIface.java @@ -15,16 +15,16 @@ public class FubukiEtherIPIface extends Iface implements SubIface { private final FubukiTunIface parent; public final IPv4 targetIP; - public final int localSideVni; + public final int localSideVrf; - public FubukiEtherIPIface(FubukiTunIface parent, IPv4 targetIP, int localSideVni) throws PreconditionUnsatisfiedException { + public FubukiEtherIPIface(FubukiTunIface parent, IPv4 targetIP, int localSideVrf) throws PreconditionUnsatisfiedException { if (parent.getLocalAddr() == null) { throw new PreconditionUnsatisfiedException("local addr of the fubuki iface " + parent.name() + " is not retrieved yet"); } this.parent = parent; this.targetIP = targetIP.stripHostname(); - this.localSideVni = localSideVni; + this.localSideVrf = localSideVrf; } @Override @@ -51,8 +51,8 @@ public void sendPacket(PacketBuffer pkb) { } @Override - public int getLocalSideVni(int hint) { - return localSideVni; + public int getLocalSideVrf(int hint) { + return localSideVrf; } @Override @@ -67,7 +67,7 @@ public String name() { @Override protected String toStringExtra() { - return ",vni:" + localSideVni; + return ",vrf:" + localSideVrf; } @Override @@ -98,7 +98,7 @@ public void destroy() { } void onPacket(ByteArray packet, int off, int pad) { - var pkb = PacketBuffer.fromEtherBytes(this, localSideVni, packet, off, pad); + var pkb = PacketBuffer.fromEtherBytes(this, localSideVrf, packet, off, pad); var err = pkb.init(); if (err != null) { assert Logger.lowLevelDebug("got invalid packet: " + err); diff --git a/core/src/main/java/io/vproxy/vswitch/iface/FubukiTunIface.java b/core/src/main/java/io/vproxy/vswitch/iface/FubukiTunIface.java index e8527ad72..39996b3a5 100644 --- a/core/src/main/java/io/vproxy/vswitch/iface/FubukiTunIface.java +++ b/core/src/main/java/io/vproxy/vswitch/iface/FubukiTunIface.java @@ -27,11 +27,11 @@ public class FubukiTunIface extends TunIface { Fubuki fubuki; private Switch sw; - public FubukiTunIface(int localSideVni, MacAddress mac, + public FubukiTunIface(int localSideVrf, MacAddress mac, String nodeName, IPPort serverIPPort, IPMask localAddr, String key) { - super("", localSideVni, mac, null); + super("", localSideVrf, mac, null); this.nodeName = nodeName; this.serverIPPort = serverIPPort; this.localAddr = localAddr; @@ -103,12 +103,12 @@ public void destroy() { private final Map etheripSubIfaces = new HashMap<>(); - public FubukiEtherIPIface addEtherIPSubIface(IPv4 ip, int vni) throws AlreadyExistException, PreconditionUnsatisfiedException { + public FubukiEtherIPIface addEtherIPSubIface(IPv4 ip, int vrf) throws AlreadyExistException, PreconditionUnsatisfiedException { ip = ip.stripHostname(); if (etheripSubIfaces.containsKey(ip)) { throw new AlreadyExistException("fubuki-cable", ip.formatToIPString()); } - var iface = new FubukiEtherIPIface(this, ip, vni); + var iface = new FubukiEtherIPIface(this, ip, vrf); etheripSubIfaces.put(ip, iface); return iface; } @@ -125,7 +125,7 @@ private void clearManagedIPs() { } VirtualNetwork net; try { - net = sw.getNetwork(localSideVni); + net = sw.getNetwork(localSideVrf); } catch (NotFoundException ignore) { return; } @@ -147,7 +147,7 @@ public void onPacket(Fubuki fubuki, ByteArray packet) { var p = PRE_PADDING.concat(packet).concat(POST_PADDING).copy().arrange(); bondLoop.runOnLoop(() -> { VProxyThread.current().newUuidDebugInfo(); - var pkb = PacketBuffer.fromIpBytes(FubukiTunIface.this, localSideVni, p, PRE_PADDING.length(), POST_PADDING.length()); + var pkb = PacketBuffer.fromIpBytes(FubukiTunIface.this, localSideVrf, p, PRE_PADDING.length(), POST_PADDING.length()); var initErr = pkb.init(); if (initErr == null) { @@ -174,13 +174,13 @@ public void onPacket(Fubuki fubuki, ByteArray packet) { @Override public void addAddress(Fubuki fubuki, IPv4 ip, IPv4 mask) { bondLoop.runOnLoop(() -> { - Logger.warn(LogType.ALERT, "fubuki is trying to add ip " + ip + " to vpc " + localSideVni); + Logger.warn(LogType.ALERT, "fubuki is trying to add ip " + ip + " to vrf " + localSideVrf); localAddr = new IPMask(ip, mask); VirtualNetwork net; try { - net = sw.getNetwork(localSideVni); + net = sw.getNetwork(localSideVrf); } catch (NotFoundException ignore) { - Logger.error(LogType.IMPROPER_USE, "network " + localSideVni + " does not exist, ip " + ip + " will not be added, you will have to add the ip manually"); + Logger.error(LogType.IMPROPER_USE, "network " + localSideVrf + " does not exist, ip " + ip + " will not be added, you will have to add the ip manually"); return; } try { @@ -206,10 +206,10 @@ public void addAddress(Fubuki fubuki, IPv4 ip, IPv4 mask) { @Override public void deleteAddress(Fubuki fubuki, IPv4 ip, IPv4 mask) { bondLoop.runOnLoop(() -> { - Logger.warn(LogType.ALERT, "fubuki is trying to remove ip " + ip + " from vpc " + localSideVni); + Logger.warn(LogType.ALERT, "fubuki is trying to remove ip " + ip + " from vrf " + localSideVrf); VirtualNetwork net; try { - net = sw.getNetwork(localSideVni); + net = sw.getNetwork(localSideVrf); } catch (NotFoundException ignore) { return; } diff --git a/core/src/main/java/io/vproxy/vswitch/iface/Iface.java b/core/src/main/java/io/vproxy/vswitch/iface/Iface.java index c69bb095d..d389f7f91 100644 --- a/core/src/main/java/io/vproxy/vswitch/iface/Iface.java +++ b/core/src/main/java/io/vproxy/vswitch/iface/Iface.java @@ -55,7 +55,7 @@ public int getIndex() { return index; } - public abstract int getLocalSideVni(int hint); + public abstract int getLocalSideVrf(int hint); public abstract int getOverhead(); diff --git a/core/src/main/java/io/vproxy/vswitch/iface/LocalSideVniGetterSetter.java b/core/src/main/java/io/vproxy/vswitch/iface/LocalSideVniGetterSetter.java deleted file mode 100644 index 5947691c4..000000000 --- a/core/src/main/java/io/vproxy/vswitch/iface/LocalSideVniGetterSetter.java +++ /dev/null @@ -1,7 +0,0 @@ -package io.vproxy.vswitch.iface; - -public interface LocalSideVniGetterSetter { - int getLocalSideVni(int hint); - - void setLocalSideVni(int serverSideVni); -} diff --git a/core/src/main/java/io/vproxy/vswitch/iface/LocalSideVrfGetterSetter.java b/core/src/main/java/io/vproxy/vswitch/iface/LocalSideVrfGetterSetter.java new file mode 100644 index 000000000..95f47e7d8 --- /dev/null +++ b/core/src/main/java/io/vproxy/vswitch/iface/LocalSideVrfGetterSetter.java @@ -0,0 +1,7 @@ +package io.vproxy.vswitch.iface; + +public interface LocalSideVrfGetterSetter { + int getLocalSideVrf(int hintVrf); + + void setLocalSideVrf(int vrf); +} diff --git a/core/src/main/java/io/vproxy/vswitch/iface/ProgramIface.java b/core/src/main/java/io/vproxy/vswitch/iface/ProgramIface.java index 0e9ce85d5..58e4dbf69 100644 --- a/core/src/main/java/io/vproxy/vswitch/iface/ProgramIface.java +++ b/core/src/main/java/io/vproxy/vswitch/iface/ProgramIface.java @@ -61,8 +61,8 @@ public void sendPacket(PacketBuffer pkb) { } @Override - public int getLocalSideVni(int hint) { - return network.vni; + public int getLocalSideVrf(int hint) { + return network.vrf; } @Override diff --git a/core/src/main/java/io/vproxy/vswitch/iface/RemoteSideVniGetterSetter.java b/core/src/main/java/io/vproxy/vswitch/iface/RemoteSideVniGetterSetter.java deleted file mode 100644 index 8c7300b28..000000000 --- a/core/src/main/java/io/vproxy/vswitch/iface/RemoteSideVniGetterSetter.java +++ /dev/null @@ -1,7 +0,0 @@ -package io.vproxy.vswitch.iface; - -public interface RemoteSideVniGetterSetter { - int getRemoteSideVni(); - - void setRemoteSideVni(int remoteSideVni); -} diff --git a/core/src/main/java/io/vproxy/vswitch/iface/RemoteSwitchIface.java b/core/src/main/java/io/vproxy/vswitch/iface/RemoteSwitchIface.java index 0326befea..477908652 100644 --- a/core/src/main/java/io/vproxy/vswitch/iface/RemoteSwitchIface.java +++ b/core/src/main/java/io/vproxy/vswitch/iface/RemoteSwitchIface.java @@ -61,7 +61,7 @@ protected void manipulate() { } @Override - public int getLocalSideVni(int hint) { + public int getLocalSideVrf(int hint) { return hint; } diff --git a/core/src/main/java/io/vproxy/vswitch/iface/TapIface.java b/core/src/main/java/io/vproxy/vswitch/iface/TapIface.java index 234dd3a26..bdfb9d551 100644 --- a/core/src/main/java/io/vproxy/vswitch/iface/TapIface.java +++ b/core/src/main/java/io/vproxy/vswitch/iface/TapIface.java @@ -21,7 +21,7 @@ public class TapIface extends Iface { public final String dev; private TapDatagramFD tap; - public final int localSideVni; + public final int localSideVrf; public final String postScript; private AbstractDatagramFD operateTap; @@ -30,10 +30,10 @@ public class TapIface extends Iface { private final ByteBuffer sndBuf = ByteBuffer.allocateDirect(2048); public TapIface(String dev, - int localSideVni, + int localSideVrf, String postScript) { this.dev = dev; - this.localSideVni = localSideVni; + this.localSideVrf = localSideVrf; this.postScript = postScript; } @@ -61,7 +61,7 @@ public String name() { @Override protected String toStringExtra() { - return ",vni:" + localSideVni; + return ",vrf:" + localSideVrf; } @Override @@ -98,7 +98,7 @@ public void init(IfaceInitParams params) throws Exception { } try { - SwitchUtils.executeDevPostScript(params.sw.alias, tap.getTap().dev, localSideVni, postScript); + SwitchUtils.executeDevPostScript(params.sw.alias, tap.getTap().dev, localSideVrf, postScript); } catch (Exception e) { // executing script failed // close the fds @@ -159,8 +159,8 @@ public void destroy() { } @Override - public int getLocalSideVni(int hint) { - return localSideVni; + public int getLocalSideVrf(int hint) { + return localSideVrf; } @Override @@ -203,7 +203,7 @@ public void readable(HandlerContext> ctx) { if (rcvBuf.position() == PRESERVED_LEN) { break; // nothing read, quit loop } - PacketBuffer pkb = PacketBuffer.fromEtherBytes(iface, localSideVni, raw, PRESERVED_LEN, TOTAL_LEN - rcvBuf.position()); + PacketBuffer pkb = PacketBuffer.fromEtherBytes(iface, localSideVrf, raw, PRESERVED_LEN, TOTAL_LEN - rcvBuf.position()); String err = pkb.init(); if (err != null) { assert Logger.lowLevelDebug("got invalid packet: " + err); diff --git a/core/src/main/java/io/vproxy/vswitch/iface/TunIface.java b/core/src/main/java/io/vproxy/vswitch/iface/TunIface.java index daf620713..292bd8506 100644 --- a/core/src/main/java/io/vproxy/vswitch/iface/TunIface.java +++ b/core/src/main/java/io/vproxy/vswitch/iface/TunIface.java @@ -26,7 +26,7 @@ public class TunIface extends Iface { public final String dev; private TapDatagramFD tun; - public final int localSideVni; + public final int localSideVrf; public final MacAddress mac; public final String postScript; @@ -36,11 +36,11 @@ public class TunIface extends Iface { private final ByteBuffer sndBuf = ByteBuffer.allocateDirect(2048); public TunIface(String dev, - int localSideVni, + int localSideVrf, MacAddress mac, String postScript) { this.dev = dev; - this.localSideVni = localSideVni; + this.localSideVrf = localSideVrf; this.mac = mac; this.postScript = postScript; } @@ -69,7 +69,7 @@ public String name() { @Override protected String toStringExtra() { - return ",vni:" + localSideVni + ",mac:" + mac; + return ",vrf:" + localSideVrf + ",mac:" + mac; } protected boolean customInitSteps() { @@ -114,7 +114,7 @@ public void init(IfaceInitParams params) throws Exception { } try { - SwitchUtils.executeDevPostScript(params.sw.alias, tun.getTap().dev, localSideVni, postScript); + SwitchUtils.executeDevPostScript(params.sw.alias, tun.getTap().dev, localSideVrf, postScript); } catch (Exception e) { // executing script failed // close the fds @@ -325,8 +325,8 @@ public void destroy() { } @Override - public int getLocalSideVni(int hint) { - return localSideVni; + public int getLocalSideVrf(int hint) { + return localSideVrf; } @Override @@ -370,7 +370,7 @@ public void readable(HandlerContext> ctx) { if (rcvBuf.position() == position) { break; // nothing read, quit loop } - PacketBuffer pkb = PacketBuffer.fromIpBytes(iface, localSideVni, raw, PRESERVED_LEN, TOTAL_LEN - rcvBuf.position()); + PacketBuffer pkb = PacketBuffer.fromIpBytes(iface, localSideVrf, raw, PRESERVED_LEN, TOTAL_LEN - rcvBuf.position()); receivedPacket(pkb); } } diff --git a/core/src/main/java/io/vproxy/vswitch/iface/VLanAdaptorIface.java b/core/src/main/java/io/vproxy/vswitch/iface/VLanAdaptorIface.java index 487c68ac2..5924584a0 100644 --- a/core/src/main/java/io/vproxy/vswitch/iface/VLanAdaptorIface.java +++ b/core/src/main/java/io/vproxy/vswitch/iface/VLanAdaptorIface.java @@ -6,13 +6,13 @@ public class VLanAdaptorIface extends Iface implements SubIface { private final Iface parentIface; public final int remoteVLan; - public final int localVni; + public final int localVrf; private boolean ready = false; - public VLanAdaptorIface(Iface parentIface, int remoteVLan, int localVni) { + public VLanAdaptorIface(Iface parentIface, int remoteVLan, int localVrf) { this.parentIface = parentIface; this.remoteVLan = remoteVLan; - this.localVni = localVni; + this.localVrf = localVrf; } @Override @@ -37,8 +37,8 @@ public void sendPacket(PacketBuffer pkb) { } @Override - public int getLocalSideVni(int hint) { - return localVni; + public int getLocalSideVrf(int hint) { + return localVrf; } @Override @@ -58,7 +58,7 @@ public String name() { @Override protected String toStringExtra() { - return ",vni:" + localVni; + return ",vrf:" + localVrf; } @Override @@ -72,7 +72,7 @@ public void setReady() { } public void handle(PacketBuffer pkb) { - pkb.vni = localVni; + pkb.vrf = localVrf; pkb.pkt.setVlan(EthernetPacket.PENDING_VLAN_CODE); pkb.devin = this; } diff --git a/core/src/main/java/io/vproxy/vswitch/iface/XDPIface.java b/core/src/main/java/io/vproxy/vswitch/iface/XDPIface.java index bcfc26623..1be78f9e4 100644 --- a/core/src/main/java/io/vproxy/vswitch/iface/XDPIface.java +++ b/core/src/main/java/io/vproxy/vswitch/iface/XDPIface.java @@ -28,7 +28,7 @@ public class XDPIface extends Iface { public final XDPParams params; private XDPSocket xsk; - public final int vni; + public final int vrf; private SelectorEventLoop loop; private final Allocator allocator; @@ -48,7 +48,7 @@ public record XDPParams(int queueId, int rxRingSize, int txRingSize, BPFMode mod BPFInfo bpf) { } - public XDPIface(String nic, int vni, UMem umem, XDPParams params) { + public XDPIface(String nic, int vrf, UMem umem, XDPParams params) { // check offload if (params.offload) { if (params.bpf.mac2port == null || params.bpf.srcmac2count == null) { @@ -60,7 +60,7 @@ public XDPIface(String nic, int vni, UMem umem, XDPParams params) { this.umem = umem; this.params = params; - this.vni = vni; + this.vrf = vrf; this.allocator = Allocator.ofUnsafe(); this.sendingChunkPointers = new PointerArray(allocator, params.txRingSize); @@ -213,8 +213,8 @@ public XDPSocket getXsk() { } @Override - public int getLocalSideVni(int hint) { - return this.vni; + public int getLocalSideVrf(int hint) { + return this.vrf; } @Override @@ -248,7 +248,7 @@ public String name() { @Override protected String toStringExtra() { - return "#q=" + params.queueId + ",umem=" + umem.alias + ",vni:" + vni + (params.offload ? ",offload" : ""); + return "#q=" + params.queueId + ",umem=" + umem.alias + ",vrf:" + vrf + (params.offload ? ",offload" : ""); } private class XDPHandler implements Handler { @@ -278,7 +278,7 @@ public void readable(HandlerContext ctx) { for (var chunk : ls) { var fullBuffer = new UMemChunkByteArray(xsk, chunk); - var pkb = PacketBuffer.fromEtherBytes(XDPIface.this, vni, fullBuffer, + var pkb = PacketBuffer.fromEtherBytes(XDPIface.this, vrf, fullBuffer, (int) (chunk.getPktAddr() - chunk.getAddr()), (int) (chunk.getEndAddr() - chunk.getPktAddr() - chunk.getPktLen())); diff --git a/core/src/main/java/io/vproxy/vswitch/node/BroadcastOutput.java b/core/src/main/java/io/vproxy/vswitch/node/BroadcastOutput.java index 824038eb9..f4a324211 100644 --- a/core/src/main/java/io/vproxy/vswitch/node/BroadcastOutput.java +++ b/core/src/main/java/io/vproxy/vswitch/node/BroadcastOutput.java @@ -41,8 +41,8 @@ protected HandleResult handle(PacketBuffer pkb, NodeGraphScheduler scheduler) { var isFirst = true; HandleResult res = HandleResult.DROP; for (Iface f : sw.getIfaces()) { - // send if vni matches - if (f.getLocalSideVni(pkb.vni) != pkb.vni) { + // send if vrf matches + if (f.getLocalSideVrf(pkb.vrf) != pkb.vrf) { continue; } // no duplicated sending diff --git a/core/src/main/java/io/vproxy/vswitch/node/FloodOutput.java b/core/src/main/java/io/vproxy/vswitch/node/FloodOutput.java index 6a4232c3e..454cef36e 100644 --- a/core/src/main/java/io/vproxy/vswitch/node/FloodOutput.java +++ b/core/src/main/java/io/vproxy/vswitch/node/FloodOutput.java @@ -53,7 +53,7 @@ protected HandleResult handle(PacketBuffer pkb, NodeGraphScheduler scheduler) { if (pkb.devin != null && iface == pkb.devin) { continue; } - if (iface.getLocalSideVni(pkb.vni) != pkb.vni) { + if (iface.getLocalSideVrf(pkb.vrf) != pkb.vrf) { continue; } if (!iface.getParams().isFloodAllowed()) { diff --git a/core/src/main/java/io/vproxy/vswitch/node/IPInputRoute.java b/core/src/main/java/io/vproxy/vswitch/node/IPInputRoute.java index e667df095..298abcece 100644 --- a/core/src/main/java/io/vproxy/vswitch/node/IPInputRoute.java +++ b/core/src/main/java/io/vproxy/vswitch/node/IPInputRoute.java @@ -101,10 +101,10 @@ private HandleResult route(PacketBuffer pkb) { } assert Logger.lowLevelDebug("route rule found: " + rule); - int vni = rule.toVni; - if (vni == pkb.vni) { + int vrf = rule.toVrf; + if (vrf == pkb.vrf) { // direct route - assert Logger.lowLevelDebug("in the same vpc"); + assert Logger.lowLevelDebug("in the same vrf"); if (pkb.debugger.isDebugOn()) { pkb.debugger.line(d -> d.append("direct route")); } @@ -131,16 +131,16 @@ private HandleResult route(PacketBuffer pkb) { pkb.pkt.setSrc(srcMac); pkb.pkt.setDst(dstMac); return _returnnext(pkb, ethernetOutput); - } else if (vni != 0) { + } else if (vrf != 0) { // route to another network - assert Logger.lowLevelDebug("routing to another vpc: " + vni); + assert Logger.lowLevelDebug("routing to another vrf: " + vrf); if (pkb.debugger.isDebugOn()) { pkb.debugger.line(d -> d.append("route to another network")); } - VirtualNetwork n = sw.getNetwork(vni); + VirtualNetwork n = sw.getNetwork(vrf); if (n == null) { // cannot handle if the network does no exist - assert Logger.lowLevelDebug("target network " + vni + " is not found"); + assert Logger.lowLevelDebug("target network " + vrf + " is not found"); if (pkb.debugger.isDebugOn()) { pkb.debugger.line(d -> d.append("target network not found")); } @@ -159,7 +159,7 @@ private HandleResult route(PacketBuffer pkb) { } var targetRule = n.routeTable.lookup(dst); - if (targetRule != null && !targetRule.isLocalDirect(n.vni)) { + if (targetRule != null && !targetRule.isLocalDirect(n.vrf)) { assert Logger.lowLevelDebug("still require routing after switching the network"); if (pkb.debugger.isDebugOn()) { pkb.debugger.line(d -> d.append("still need routing after switching the network")); diff --git a/core/src/main/java/io/vproxy/vswitch/node/IPOutputRoute.java b/core/src/main/java/io/vproxy/vswitch/node/IPOutputRoute.java index 75f548dac..9185af408 100644 --- a/core/src/main/java/io/vproxy/vswitch/node/IPOutputRoute.java +++ b/core/src/main/java/io/vproxy/vswitch/node/IPOutputRoute.java @@ -61,22 +61,22 @@ protected HandleResult handle(PacketBuffer pkb, NodeGraphScheduler scheduler) { assert Logger.lowLevelDebug("route rule found: " + routeRule); - if (routeRule.toVni == pkb.vni) { + if (routeRule.toVrf == pkb.vrf) { assert Logger.lowLevelDebug("direct route, no changes required"); if (pkb.debugger.isDebugOn()) { pkb.debugger.line(d -> d.append("direct route")); } return determineDstMacAndReturn(pkb); - } else if (routeRule.toVni != 0) { - assert Logger.lowLevelDebug("route to another vpc"); + } else if (routeRule.toVrf != 0) { + assert Logger.lowLevelDebug("route to another vrf"); if (pkb.debugger.isDebugOn()) { pkb.debugger.line(d -> d.append("route to another network")); } - // search for any synthetic ip in the target vpc - VirtualNetwork targetNetwork = sw.getNetwork(routeRule.toVni); + // search for any synthetic ip in the target vrf + VirtualNetwork targetNetwork = sw.getNetwork(routeRule.toVrf); if (targetNetwork == null) { - assert Logger.lowLevelDebug("target vpc not found"); + assert Logger.lowLevelDebug("target vrf not found"); if (pkb.debugger.isDebugOn()) { pkb.debugger.line(d -> d.append("target network not found")); } @@ -84,7 +84,7 @@ protected HandleResult handle(PacketBuffer pkb, NodeGraphScheduler scheduler) { } MacAddress targetMac = SwitchUtils.getRoutedSrcMac(targetNetwork, dst); if (targetMac == null) { - assert Logger.lowLevelDebug("cannot find src/dst mac for sending this packet to another vpc"); + assert Logger.lowLevelDebug("cannot find src/dst mac for sending this packet to another vrf"); if (pkb.debugger.isDebugOn()) { pkb.debugger.line(d -> d.append("no src/dst mac found for routing out the packet")); } diff --git a/core/src/main/java/io/vproxy/vswitch/stack/conntrack/Fastpath.java b/core/src/main/java/io/vproxy/vswitch/stack/conntrack/Fastpath.java index 618218af9..12fefcf8e 100644 --- a/core/src/main/java/io/vproxy/vswitch/stack/conntrack/Fastpath.java +++ b/core/src/main/java/io/vproxy/vswitch/stack/conntrack/Fastpath.java @@ -10,13 +10,13 @@ public class Fastpath { public final Iface output; - public final int vni; + public final int vrf; public final MacAddress local; public final MacAddress remote; - public Fastpath(Iface output, int vni, MacAddress local, MacAddress remote) { + public Fastpath(Iface output, int vrf, MacAddress local, MacAddress remote) { this.output = output; - this.vni = vni; + this.vrf = vrf; this.local = local; this.remote = remote; } @@ -25,13 +25,13 @@ public boolean validateAndSetInto(SwitchDelegate sw, PacketBuffer pkb) { if (output.isDestroyed()) { return false; } - if (vni != pkb.vni) { - var net = sw.getNetwork(pkb.vni); + if (vrf != pkb.vrf) { + var net = sw.getNetwork(pkb.vrf); if (net == null) { return false; } pkb.network = net; - pkb.vni = net.vni; + pkb.vrf = net.vrf; } EthernetPacket ether = new EthernetPacket(); ether.setDst(remote); @@ -49,10 +49,10 @@ public boolean validateAndSetInto(SwitchDelegate sw, PacketBuffer pkb) { @Override public String toString() { return "Fastpath{" + - "output=" + (output == null ? "null" : output.name()) + - ", vni=" + vni + - ", local=" + local + - ", remote=" + remote + - '}'; + "output=" + (output == null ? "null" : output.name()) + + ", vrf=" + vrf + + ", local=" + local + + ", remote=" + remote + + '}'; } } diff --git a/core/src/main/java/io/vproxy/vswitch/util/SwitchUtils.java b/core/src/main/java/io/vproxy/vswitch/util/SwitchUtils.java index bc0a79a9c..09744f60e 100644 --- a/core/src/main/java/io/vproxy/vswitch/util/SwitchUtils.java +++ b/core/src/main/java/io/vproxy/vswitch/util/SwitchUtils.java @@ -36,7 +36,7 @@ private SwitchUtils() { public static VXLanPacket getOrMakeVXLanPacket(PacketBuffer pkb) { if (pkb.vxlan == null) { var p = new VXLanPacket(); - p.setVni(pkb.vni); + p.setVni(pkb.vrf); p.setPacket(pkb.pkt); pkb.vxlan = p; } @@ -94,14 +94,14 @@ public static void checkAndUpdateMss(PacketBuffer pkb, Iface iface) { } } - public static void executeDevPostScript(String switchAlias, String dev, int vni, String postScript) throws Exception { + public static void executeDevPostScript(String switchAlias, String dev, int vrf, String postScript) throws Exception { if (postScript == null || postScript.isBlank()) { return; } ProcessBuilder pb = new ProcessBuilder().command(postScript); var env = pb.environment(); env.put("DEV", dev); - env.put("VNI", "" + vni); + env.put("VRF", "" + vrf); env.put("SWITCH", switchAlias); Utils.execute(pb, 10 * 1000); } @@ -625,9 +625,9 @@ public void release(boolean detach) { } } - public static GetSharedMapGroupResult createBPFObjectWithReusedMaps(Switch sw, int vni, + public static GetSharedMapGroupResult createBPFObjectWithReusedMaps(Switch sw, int vrf, BPFObjectCreator fn) throws IOException { - var mapGroupName = "mac2port:" + sw.alias + ":" + vni; + var mapGroupName = "mac2port:" + sw.alias + ":" + vrf; var mapName = Prebuilt.DEFAULT_MAC_TO_PORT_MAP_NAME; var res = SharedBPFMapHolder.getInstance().getOrCreate(mapGroupName, () -> { diff --git a/core/src/main/java/io/vproxy/vswitch/util/UserInfo.java b/core/src/main/java/io/vproxy/vswitch/util/UserInfo.java index 92aee8e2a..3abd42d90 100644 --- a/core/src/main/java/io/vproxy/vswitch/util/UserInfo.java +++ b/core/src/main/java/io/vproxy/vswitch/util/UserInfo.java @@ -7,15 +7,15 @@ public class UserInfo { public final String user; public final Aes256Key key; public final String pass; - public final int vni; + public final int vrf; public final IfaceParams defaultIfaceParams; - public UserInfo(String user, Aes256Key key, String pass, int vni, + public UserInfo(String user, Aes256Key key, String pass, int vrf, IfaceParams defaultIfaceParams) { this.user = user; this.key = key; this.pass = pass; - this.vni = vni; + this.vrf = vrf; this.defaultIfaceParams = defaultIfaceParams; } } diff --git a/doc/architecture.md b/doc/architecture.md index afd5dab6e..3bbfc95d6 100644 --- a/doc/architecture.md +++ b/doc/architecture.md @@ -80,7 +80,7 @@ The SDN virtual switch is provided with the `switch` resource. #### VirtualNetwork -A virtual network inside the switch. The name of the VPC is a number which usually represents the VLan or VNI of the network. +A virtual network inside the switch. The name of the VRF is a number which usually represents the VLan or VNI of the network. Inside the network, you can configure ips, route tables. You can also handle packets programmatically or with the flow generator. diff --git a/doc/switch-fubuki-integration.md b/doc/switch-fubuki-integration.md index c330e66a2..bd795a9d4 100644 --- a/doc/switch-fubuki-integration.md +++ b/doc/switch-fubuki-integration.md @@ -12,11 +12,11 @@ We can combine them by converting fubuki tun interfaces into rx/tx APIs and hook After launching vproxy, we can get detailed into about the commands used in this article: * `man switch` -* `man vpc` +* `man vrf` * `man fubuki` * `man iface` * `man switch add` -* `man vpc add-to` +* `man vrf add-to` * `man fubuki add-to` * `man iface list-detail` * `man iface remove-from` @@ -39,26 +39,26 @@ add switch sw0 3. Creating virtual network ``` -add vpc 1 to switch sw0 v4network 10.99.88.0/24 +add vrf 1 to switch sw0 v4network 10.99.88.0/24 ``` Descriptions: -* `add vpc 1` means creating vpc `1`, whose vni is 1 +* `add vrf 1` means creating vrf `1`, whose id is 1 * `to switch sw0` means it's added into `sw0` -* `v4network $.$.$.$/$` means the v4 network range limit of this vpc +* `v4network $.$.$.$/$` means the v4 network range limit of this vrf 4. Creating fubuki interface ``` -add fubuki fbk0 to switch sw0 vni 1 mac 00:11:22:33:44:55 ip 10.99.88.199/24 address $.$.$.$:$ password $ +add fubuki fbk0 to switch sw0 vrf 1 mac 00:11:22:33:44:55 ip 10.99.88.199/24 address $.$.$.$:$ password $ ``` Descriptions: * `add fubuki fbk0` means create a fubuki interface, named as `fbk0` * `to switch sw0` means it's added into `sw0` -* `vni 1` means the interface by default belongs to the vpc whose vni is 1 (in other words, `vpc 1`) +* `vrf 1` means the interface by default belongs to the vrf with id 1 * `mac $:$:$:$:$:$` means the mac address allocated for the interface. Since fubuki runs in tun mode, the switch has to simulate the layer 2 frames * `ip $.$.$.$/$` means the ip address and mask for this interface to use. You may omit this option, in this case, fubuki will automatically allocate an ip instead * `address $.$.$.$:$` means the address and port of the remote fubuki server diff --git a/doc/switch.md b/doc/switch.md index 02b98d341..095c00c42 100644 --- a/doc/switch.md +++ b/doc/switch.md @@ -11,11 +11,11 @@ vproxy implemented a layer-3 stackable virtual switch, supporting the following * arp table based on arp or ndp requests/responses * active arp/ndp unicast or broadcast * virtual ips (which supports arp/ndp and icmp ping) -* bind tap devices into vpc +* bind tap devices into vrf * bare vxlan socks * encrypted vxlan link to another switch * bare vxlan link to another switch -* route packets from one vpc to another vpc +* route packets from one vrf to another vrf * route packets to a specific ip address and the following security features: @@ -34,8 +34,8 @@ Ok, Let's play with it! ## Words -* vpc: The switch is a vxlan switch, so networks are divided by the vni. However it's wired to say "dev0 in vni 1", so let's say "dev0 in vpc 1" instead. So when I say "vpc 1", I'm actually saying the network formed by packets with vni equals 1. -* vni: Id of a virtual network. +* vrf: The switch is a layer 3 virtual switch, networks are divided by vrfs. +* vrf: Id of a virtual network. * ns: Linux namespace. Here I mean `netns` (networking namespace) particularly. * tap: Tap devices, which can transfer l2 packets between kernel net stack and a user space program (in this case, the vproxy application). @@ -147,27 +147,27 @@ list-detail switch "sw2 -> event-loop-group (worker-elg) bind 0.0.0.0:18472 mac-table-timeout 300000 arp-table-timeout 14400000 bare-vxlan-access (allow-all)" ``` -### 2. vpc +### 2. vrf -You need to create vpc inside a switch before using it. The name of the vpc is the vni. +You need to create vrfs inside a switch before using it. The name of the vrf is the id number of it. For security consideration, vproxy switch requires you to specify a network, ips in arp or ndp neighbor solicitation/advertisement packets are only allowed in the configured network. ``` -add vpc 2 in switch sw0 v4network 172.16.2.0/16 v6network fd00::200/120 +add vrf 2 in switch sw0 v4network 172.16.2.0/16 v6network fd00::200/120 ``` -You may omit the `v6network`, which means disallow ipv6 ndp neighbor solicitation/advertisement. -Also note that this config cannot be modified. You can only remove and re-create. In this case, all synthetic ips will be lost because they are strictly attached to the vpc. +You may omit the `v6network`, which means disallowing ipv6 ndp neighbor solicitation/advertisement. +Also note that this config cannot be modified. You can only remove and re-create. In this case, all synthetic ips will be lost because they are strictly attached to the vrf. ### 3. tap Create or open a tap device. On linux, the tap name could be a pattern, e.g. `tap%d`. The generated tap device name will be returned, which is the tap shown in the `ip a` or `ip link` command. -Any tap device should bond to a vpc, so you need to specify the `vni` when creating. +Any tap device should bond to a vrf, so you need to specify the `vrf` when creating. ``` -add tap tap1 to switch sw0 vni 2 +add tap tap1 to switch sw0 vrf 2 ``` Then you can see the `tap1` with `ip link`. Operate the device freely. @@ -175,7 +175,7 @@ Then you can see the `tap1` with `ip link`. Operate the device freely. You may specify a `post-script` when adding the tap device. The script will be called after the tap device is created/enabled. ``` -add tap tap1 to switch sw0 vni 2 post-script /root/up-tap1.sh +add tap tap1 to switch sw0 vrf 2 post-script /root/up-tap1.sh ``` ### 4. bare vxlan socks @@ -184,11 +184,11 @@ This is allowed as default. Note that you might set a `SecurityGroup` when creat However, when the vproxy receives a vxlan packet, it records the remote address, and packets will be sent to that address. So make sure the sending and receiving port are the same. If you are using a linux vxlan device, set `port 8472 8473` when using `ip link add` will do the job. -Also, the sending vxlan packet's vni is set to the last received vxlan packet vni from the sock. If you want to connect two switches, see the following method. +Also, the sending vxlan packet's vrf is set to the last received vxlan packet vrf from the sock. If you want to connect two switches, see the following method. ### 5. bare vxlan link to another switch -This allows two switches to connect to each other and handle packets from all vpc instead of just one vpc when not configured (which will be handled as a basic bare vxlan sock). +This allows two switches to connect to each other and handle packets from all vrfs instead of just one when not configured (which will be handled as a basic bare vxlan sock). This requires two switches be able to directly talk each other and will use the listening udp sock to send packets to each other. @@ -221,31 +221,31 @@ This allows a switch to connect to another (usually public) switch with an encry On the connected switch (usually a switch on public network), which could be called the `server` side: ``` -add user to-vni2 to switch sw0 vni 2 password p@sSw0rD +add user to-vrf2 to switch sw0 vrf 2 password p@sSw0rD ``` On the switch to connect (usually a switch behind a NAT router), which could be called the `client` side: ``` -add user-client to-vni2 to switch sw0 password p@sSw0rD vni 2 address 192.168.77.1:18472 +add user-client to-vrf2 to switch sw0 password p@sSw0rD vrf 2 address 192.168.77.1:18472 ``` -As you can see, vni can be set both on the `server` and `client` sides, and they can be set to different values. The packets will be transformed on the server side. +As you can see, vrf can be set both on the `server` and `client` sides, and they can be set to different values. The packets will be transformed on the server side. To reduce any possible information leak of the server, the server will not send any packet to the client before receiving at least one vxlan packet from client, which will carry the vni of the client, then the server will be able to set the vni before sending packets to the client. Note that the user name cannot < 3 chars and cannot > 8 chars and only a-zA-Z0-9 allowed. After configuration, you should see an alert tell you the switches are connected. -### 7. route to another vpc +### 7. route to another vrf -You may add route rules to redirect packets to another vpc. +You may add route rules to redirect packets to another vrf. ``` -add route to172.17 to vpc 1314 in switch sw0 network 172.17.0.0/24 vni 1315 +add route to172.17 to vrf 1314 in switch sw0 network 172.17.0.0/24 vrf 1315 ``` -This rule makes ip packets in vpc `1314` that match `172.17.0.0/24` go to vpc `1315`. Note: the vpc `1315` should have at least one synthetic ip for the receiver to respond to the routed ip packet, otherwise it might not be able to respond. +This rule makes ip packets in vrf `1314` that match `172.17.0.0/24` go to vrf `1315`. Note: the vrf `1315` should have at least one synthetic ip for the receiver to respond to the routed ip packet, otherwise it might not be able to respond. The hop limit in ip packet will decrease by 1 and it will be dropped if it's 0 before routing. @@ -254,19 +254,19 @@ The hop limit in ip packet will decrease by 1 and it will be dropped if it's 0 b You may add routes to redirect packets to some address, which is usually expected to be a router. ``` -add route to172.17 to vpc 1314 in switch sw0 network 172.17.0.0/24 via 172.16.0.1 +add route to172.17 to vrf 1314 in switch sw0 network 172.17.0.0/24 via 172.16.0.1 ``` -This rule changes mac address of ip packets in vpc `1314` that match `172.17.0.0/24` to the mac of 172.16.0.1. +This rule changes mac address of ip packets in vrf `1314` that match `172.17.0.0/24` to the mac of 172.16.0.1. The hop limit in ip packet will decrease by 1 and it will be dropped if it's 0 before routing. ### 9. add synthetic ip -Add an ip to a vpc. The ip can respond arp requests or ndp neighbor solicitations, and can respond ICMP/ICMPv6 PING requests. The ip can be used as the default gateway. All route rules in the same vpc will apply to these ips, and when routing to another vpc, the ip in that vpc must exist otherwise arp/ndp requests will not be able to make. +Add an ip to a vrf. The ip can respond arp requests or ndp neighbor solicitations, and can respond ICMP/ICMPv6 PING requests. The ip can be used as the default gateway. All route rules in the same vrf will apply to these ips, and when routing to another vrf, the ip in that vrf must exist otherwise arp/ndp requests will not be able to make. ``` -add ip 172.16.0.21 to vpc 1314 in switch sw0 mac e2:8b:11:00:00:22 +add ip 172.16.0.21 to vrf 1314 in switch sw0 mac e2:8b:11:00:00:22 ``` You may set the mac more like a synthetic one, e.g. `02:00:00:00:00:01` @@ -281,7 +281,7 @@ output example: ``` 1) "Iface(remote:sw2,100.64.0.4:18472)" -2) "Iface(user:sw1link,192.168.56.2:45717,lvni:1314,rvni:1314)" +2) "Iface(user:sw1link,192.168.56.2:45717,lvrf:1314,rvrf:1314)" ``` ### 11. check mac and arp table @@ -289,16 +289,16 @@ output example: The mac and arp table are provided together. Data will be filled into the table and empty values will stay empty (e.g. the mac table entry of a mac is missing but in arp table the mac exists, then the output of an arp entry will show no Iface field). ``` -list-detail arp in vpc 1314 in sw sw0 +list-detail arp in vrf 1314 in sw sw0 ``` output example: ``` 1) "0a:00:27:00:02:54 172.16.0.254 Iface(remote:sw2,100.64.0.4:18472) ARP-TTL:13405 MAC-TTL:299" -2) "1a:a9:6b:b6:a2:2c 172.16.0.3 Iface(user:sw1link,192.168.56.2:45717,lvni:1314,rvni:1314) ARP-TTL:14398 MAC-TTL:299" +2) "1a:a9:6b:b6:a2:2c 172.16.0.3 Iface(user:sw1link,192.168.56.2:45717,lvrf:1314,rvrf:1314) ARP-TTL:14398 MAC-TTL:299" 3) "52:13:24:51:a3:1e 172.16.0.2 Iface(remote:sw2,100.64.0.4:18472) ARP-TTL:14383 MAC-TTL:299" -4) "d6:4b:ba:20:c1:01 172.16.0.4 Iface(user:sw1link,192.168.56.2:45717,lvni:1314,rvni:1314) ARP-TTL:14383 MAC-TTL:299" +4) "d6:4b:ba:20:c1:01 172.16.0.4 Iface(user:sw1link,192.168.56.2:45717,lvrf:1314,rvrf:1314) ARP-TTL:14383 MAC-TTL:299" 5) "fe:73:f8:bb:75:65 172.16.0.1 Iface(remote:sw2,100.64.0.4:18472) ARP-TTL:14398 MAC-TTL:299" ``` @@ -322,13 +322,13 @@ The `VM` creates a `vxlan` device and connect to `sw1`. The `Host X` runs a switch `sw-pub`. Connect `sw1`, `sw2`, `sw3` with bare vxlan links as the graph shows. Connect `sw1` to `sw-pub` with two encrypted vxlan links. -The encrypted link can only be connected to one vpc, so here we need two links. +The encrypted link can only be connected to one vrf, so here we need two links. -We create 3 vpc on all switches, to make it simple, we make the vni number and the network cidr representation consistent: +We create 3 vrfs on all switches, to make it simple, we make the vrf number and the network cidr representation consistent: -* vpc `1`: 172.16.`1`.0/24 + fd00::`1`00/120 -* vpc `2`: 172.16.`2`.0/24 + fd00::`2`00/120 -* vpc `3`: 172.16.`3`.0/24 + fd00::`3`00/120 +* vrf `1`: 172.16.`1`.0/24 + fd00::`1`00/120 +* vrf `2`: 172.16.`2`.0/24 + fd00::`2`00/120 +* vrf `3`: 172.16.`3`.0/24 + fd00::`3`00/120 When assigning ips to devices, we use the device number as the last 1 bytes of the ip address. So as the ipv6 addresses. Note that the ipv6 addresses are not shown in the graph, but they will be configured just like the ipv4 addresses. For example: @@ -339,11 +339,11 @@ etc... Add some synthetic(virtual) ips to the switches. Each network need at least one ipv4 and one ipv6 to be used as the default gateway because we will set up routes later. A default gateway allows packets to other networks to flow into the switches. Note: to make things easy to remember, use `254`(`fe`) as the last byte of the ip address. -Add the gw ip in vpc 1 on `sw2` as `172.16.1.254`. -Add the gw ip in vpc 2 on `sw-pub` as `172.16.2.254`. -Add the gw ip in vpc 3 on `sw3` as `172.16.3.254`. +Add the gw ip in vrf 1 on `sw2` as `172.16.1.254`. +Add the gw ip in vrf 2 on `sw-pub` as `172.16.2.254`. +Add the gw ip in vrf 3 on `sw3` as `172.16.3.254`. -Also, each switch that has a route rule to another vpc must have a corresponding synthetic ip in that vpc. Just set it to any unused ip would be fine, the values I choose are also recorded in the graph. +Also, each switch that has a route rule to another vrf must have a corresponding synthetic ip in that vrf. Just set it to any unused ip would be fine, the values I choose are also recorded in the graph. Devices and their ips are shown in the graph: @@ -354,400 +354,40 @@ Devices and their ips are shown in the graph: +----+ 172.16.1.1/24 172.16.3.6/24 172.16.1.3/24 | 172.16.2.2/24 | | 172.16.2.4/24 - ns1 | | ns2 | vni:3 ns3 | | ns4 + ns1 | | ns2 | vrf:3 ns3 | | ns4 +------+ +------+ +-------+ +------+ +------+ | tap1 | | tap2 | | vxlan | | tap3 | | tap4 | +--+---+ +--+---+ +-------+ +------+ +------+ | | | | | | | | | | - vni:1 vni:2 | vni:1 vni:2 + vrf:1 vrf:2 | vrf:1 vrf:2 v v (192.168.56.1) v v v 172.16.3.5/24 - +-------------+ +-------------+ +-------------+ vni:3 +------+ + +-------------+ +-------------+ +-------------+ vrf:3 +------+ | | vxlan link | | vxlan link | |<--------| tap5 | | Switch: sw2 |<====================>| Switch: sw1 |<====================>| Switch: sw3 | +------+ | | | | | |<-----+ ns0 iptables MASQ ------> INTERNET - +-------------+ +-------------+ +-------------+ vni:3 \ + +-------------+ +-------------+ +-------------+ vrf:3 \ ^ Host B (192.168.56.2) Host A (100.64.0.1) (100.64.0.4) Host C gw:172.16.3.254 -vni:1 | ^ ^ ip:172.16.1.193 (vni:1) - | | | ip:172.16.2.193 (vni:2) - gw:172.16.1.254 | | 2 encrypted links (for vpc 1->101 and vpc 2->102) - ip:172.16.2.192 (vni:2) | | - ip:172.16.3.192 (vni:3) (60.205.111.222) v v br0 +vrf:1 | ^ ^ ip:172.16.1.193 (vrf:1) + | | | ip:172.16.2.193 (vrf:2) + gw:172.16.1.254 | | 2 encrypted links (for vrf 1->101 and vrf 2->102) + ip:172.16.2.192 (vrf:2) | | + ip:172.16.3.192 (vrf:3) (60.205.111.222) v v br0 +--------------------+ +---------------------------+ - vni:102 | | vni:101 |+--------+ | + vrf:102 | | vrf:101 |+--------+ | gw:172.16.2.254 ------>| Switch: sw-pub |<----------| tap101 | 172.16.1.101/24 | - (vni:101) ip:172.16.1.190 | | |+--------+ | + (vrf:101) ip:172.16.1.190 | | |+--------+ | +--------------------+ +---------------------------+ Host X -<======> means two switches connected to each other, and packets in all vni can go through. -<------- means an endpoint device attached to one vpc of the switch, input packets are modified into vxlan packets with configured vni. -<------> means two switches connected to each other, but packets only in the configured vni are allowed. +<======> means two switches connected to each other, and packets in all vrf can go through. +<------- means an endpoint device attached to one vrf of the switch, input packets are modified into vxlan packets with configured vrf. +<------> means two switches connected to each other, but packets only in the configured vrfs are allowed. ``` -A brief summary for all ips in the form of a shell script, you may use it on all namespaces or virtual machines to check the connectivity: - -```shell -#!/bin/bash - -ips=""" -172.16.1.1 fd00::101 -172.16.2.2 fd00::202 -172.16.1.3 fd00::103 -172.16.2.4 fd00::204 -172.16.3.5 fd00::305 -172.16.3.6 fd00::306 -172.16.1.101 fd00::165 - -172.16.1.254 fd00::1fe -172.16.2.254 fd00::2fe -172.16.3.254 fd00::3fe - -172.16.2.192 fd00::2c0 -172.16.3.192 fd00::3c0 -172.16.1.193 fd00::1c1 -172.16.2.193 fd00::2c1 -172.16.1.190 fd00::1be -""" - -ip neighbor flush all -ip -6 neighbor flush all - -v6="6" - -for ip in $ips -do - if [ "$v6" == "6" ] - then - v6="" - else - v6="6" - fi - cmd="ping$v6 -c 1 -W 1 $ip" - printf "$ip\t" - for i in {1..3} - do - $cmd 1>/dev/null 2>/dev/null - code="$?" - if [ "$code" == "0" ] - then - echo "ok" - break - else - if [ "$i" == "3" ] - then - echo "fail" - fi - fi - done - sleep 0.2s -done -echo "finish" -``` - -You can see that the `tap5` is commented with `iptables MASQ`, we will use it as a internet gateway for the whole virtual network using iptables `-j MASQUERADE`. - -After configuration, we expect to see that: all devices can ping to any other devices in the network, and all devices can connect to the internet. - -### Preparing - -You will need this small script to create namespaces and let move tap devices into namespaces and give them ips: [netnsutil.py](https://github.com/wkgcass/vproxy/blob/master/misc/netnsutil.py), copy-paste and place it at `/root/vproxy/netnsutil.py`, remember to run `chmod +x` on them. - -Here we only use capability of the script to create namespaces, move tap devices into them and assign ips on them, but it also supports to invoke vproxy switch interfaces to create tap devices. See `./netnsutil.py --help` for more info. - -### Host A - -Enter the following commands to vproxy: - -```shell -# create switch sw1 -add switch sw1 address 0.0.0.0:18472 - -# create vpc 1,2,3 -add vpc 1 to switch sw1 v4network 172.16.1.0/24 v6network fd00::100/120 -add vpc 2 to switch sw1 v4network 172.16.2.0/24 v6network fd00::200/120 -add vpc 3 to switch sw1 v4network 172.16.3.0/24 v6network fd00::300/120 - -# bare vxlan link to sw2 and sw3 -add switch sw2 to switch sw1 address 192.168.56.2:18472 -add switch sw3 to switch sw1 address 100.64.0.4:18472 - -# encrypted link to sw-pub -add user-client sw1x1 to switch sw1 address 60.205.111.222:18472 vni 1 password vproxy -add user-client sw1x2 to switch sw1 address 60.205.111.222:18472 vni 2 password vproxy -``` - -### VM - -Run linux commands: - -```shell -# add a vxlan device to sw1 - -ip link add vxlan0 type vxlan id 3 remote 192.168.56.1 dstport 18472 srcport 18472 18473 -ip addr add 172.16.3.6/24 dev vxlan0 -ip addr add fd00::306/120 dev vxlan0 -ip link set vxlan0 up -ip route add 172.16.1.0/24 via 172.16.3.254 -ip route add 172.16.2.0/24 via 172.16.3.254 -ip -6 route add fd00::100/120 via fd00::3fe dev vxlan0 -ip -6 route add fd00::200/120 via fd00::3fe dev vxlan0 -``` - -### Host B - -Prepare two scripts and run `chmod +x` on them: - -`/root/vproxy/tapns10.sh` - -```shell -/root/vproxy/netnsutil.py add ns=ns1 sw=sw2 vni=1 addr=172.16.1.1/24 gate=172.16.1.254 v6addr=fd00::101/120 v6gate=fd00::1fe -``` - -`/root/vproxy/tapns20.sh` - -```shell -/root/vproxy/netnsutil.py add ns=ns2 sw=sw2 vni=2 addr=172.16.2.2/24 gate=172.16.2.254 v6addr=fd00::202/120 v6gate=fd00::2fe -``` - -Enter the following commands to vproxy: - -```shell -# create switch sw2 -add switch sw2 address 0.0.0.0:18472 - -# create vpc 1,2,3 -add vpc 1 to switch sw2 v4network 172.16.1.0/24 v6network fd00::100/120 -add vpc 2 to switch sw2 v4network 172.16.2.0/24 v6network fd00::200/120 -add vpc 3 to switch sw2 v4network 172.16.3.0/24 v6network fd00::300/120 - -# bare vxlan link to sw1 -add switch sw1 to switch sw2 address 192.168.56.1:18472 - -# add synthetic ip in vpc 1 -add ip 172.16.1.254 to vpc 1 in switch sw2 mac 04:00:00:00:12:54 -add ip fd00::1fe to vpc 1 in switch sw2 mac 06:00:00:00:12:54 - -# add route from vpc 1 to vpc 2 -add route route-to-2 to vpc 1 in switch sw2 network 172.16.2.0/24 vni 2 -add route route-to-2-v6 to vpc 1 in switch sw2 network fd00::200/120 vni 2 -# add route from vpc 1 to vpc 3 -add route route-to-3 to vpc 1 in switch sw2 network 172.16.3.0/24 vni 3 -add route route-to-3-v6 to vpc 1 in switch sw2 network fd00::300/120 vni 3 -# add route from vpc 2 to vpc 1 -add route route-to-1 to vpc 2 in switch sw2 network 172.16.1.0/24 vni 1 -add route route-to-1-v6 to vpc 2 in switch sw2 network fd00::100/120 vni 1 -# add route from vpc 2 to vpc 3 -add route route-to-3 to vpc 2 in switch sw2 network 172.16.3.0/24 vni 3 -add route route-to-3-v6 to vpc 2 in switch sw2 network fd00::300/120 vni 3 -# add route from vpc 3 to vpc 1 -add route route-to-1 to vpc 3 in switch sw2 network 172.16.1.0/24 vni 1 -add route route-to-1-v6 to vpc 3 in switch sw2 network fd00::100/120 vni 1 -# add route from vpc 3 to vpc 2 -add route route-to-2 to vpc 3 in switch sw2 network 172.16.2.0/24 vni 2 -add route route-to-2-v6 to vpc 3 in switch sw2 network fd00::200/120 vni 2 - -# add corresponding synthetic ips in the routed vpc -add ip 172.16.2.192 to vpc 2 in switch sw2 mac 04:00:00:00:21:92 -add ip fd00::2c0 to vpc 2 in switch sw2 mac 06:00:00:00:21:92 -add ip 172.16.3.192 to vpc 3 in switch sw2 mac 04:00:00:00:31:92 -add ip fd00::3c0 to vpc 3 in switch sw2 mac 06:00:00:00:31:92 - -# add default route to the internet -add route internet to vpc 1 in switch sw2 network 0.0.0.0/0 vni 3 -add route internet-v6 to vpc 1 in switch sw2 network ::/0 vni 3 - -# route packets to the default gateway in vpc 3 -add route internet-forward to vpc 3 in switch sw2 network 0.0.0.0/0 via 172.16.3.254 -add route internet-forward-v6 to vpc 3 in switch sw2 network ::/0 via fd00::3fe - -# add tap devices and execute the prepared scripts -add tap tapns10 to switch sw2 vni 1 post-script /root/vproxy/tapns10.sh -add tap tapns20 to switch sw2 vni 2 post-script /root/vproxy/tapns20.sh -``` - -### Host C - -Prepare three scripts and remember to `chmod +x` on them: - -`/root/vproxy/tapns30.sh` - -```shell -/root/vproxy/netnsutil.py add ns=ns3 sw=sw3 vni=1 addr=172.16.1.3/24 gate=172.16.1.254 v6addr=fd00::103/120 v6gate=fd00::1fe -``` - -`/root/vproxy/tapns40.sh` - -```shell -/root/vproxy/netnsutil.py add ns=ns4 sw=sw3 vni=2 addr=172.16.2.4/24 gate=172.16.2.254 v6addr=fd00::204/120 v6gate=fd00::2fe -``` - -`/root/vproxy/tap5.sh` - -```shell -ip addr add 172.16.3.5/24 dev tap5 -ip -6 addr add fd00::305/120 dev tap5 -ip link set tap5 up -ip route add 172.16.1.0/24 via 172.16.3.254 -ip route add 172.16.2.0/24 via 172.16.3.254 -ip -6 route add fd00::100/120 via fd00::3fe dev tap5 -ip -6 route add fd00::200/120 via fd00::3fe dev tap5 -``` - -Enter the following commands to vproxy: - -```shell -# create switch sw3 -add switch sw3 address 0.0.0.0:18472 - -# create vpc 1,2,3 -add vpc 1 to switch sw3 v4network 172.16.1.0/24 v6network fd00::100/120 -add vpc 2 to switch sw3 v4network 172.16.2.0/24 v6network fd00::200/120 -add vpc 3 to switch sw3 v4network 172.16.3.0/24 v6network fd00::300/120 - -# bare vxlan link to sw1 -add switch sw1 to switch sw3 address 100.64.0.1:18472 - -# add synthetic ip in vpc 3 -add ip 172.16.3.254 to vpc 3 in switch sw3 mac 04:00:00:00:32:54 -add ip fd00::3fe to vpc 3 in switch sw3 mac 06:00:00:00:32:54 - -# add route from vpc 1 to vpc 2 -add route route-to-2 to vpc 1 in switch sw3 network 172.16.2.0/24 vni 2 -add route route-to-2-v6 to vpc 1 in switch sw3 network fd00::200/120 vni 2 -# add route from vpc 1 to vpc 3 -add route route-to-3 to vpc 1 in switch sw3 network 172.16.3.0/24 vni 3 -add route route-to-3-v6 to vpc 1 in switch sw3 network fd00::300/120 vni 3 -# add route from vpc 2 to vpc 1 -add route route-to-1 to vpc 2 in switch sw3 network 172.16.1.0/24 vni 1 -add route route-to-1-v6 to vpc 2 in switch sw3 network fd00::100/120 vni 1 -# add route from vpc 2 to vpc 3 -add route route-to-3 to vpc 2 in switch sw3 network 172.16.3.0/24 vni 3 -add route route-to-3-v6 to vpc 2 in switch sw3 network fd00::300/120 vni 3 -# add route from vpc 3 to vpc 1 -add route route-to-1 to vpc 3 in switch sw3 network 172.16.1.0/24 vni 1 -add route route-to-1-v6 to vpc 3 in switch sw3 network fd00::100/120 vni 1 -# add route from vpc 3 to vpc 2 -add route route-to-2 to vpc 3 in switch sw3 network 172.16.2.0/24 vni 2 -add route route-to-2-v6 to vpc 3 in switch sw3 network fd00::200/120 vni 2 - -# add corresponding synthetic ips in the routed vpc -add ip 172.16.1.193 to vpc 1 in switch sw3 mac 04:00:00:00:11:93 -add ip fd00::1c1 to vpc 1 in switch sw3 mac 06:00:00:00:11:93 -add ip 172.16.2.193 to vpc 2 in switch sw3 mac 04:00:00:00:21:93 -add ip fd00::2c1 to vpc 2 in switch sw3 mac 06:00:00:00:21:93 - -# add default route to the internet -add route internet to vpc 3 in switch sw3 network 0.0.0.0/0 via 172.16.3.5 -add route internet-v6 to vpc 3 in switch sw3 network ::/0 via fd00::305 - -# add tap devices and execute the prepared scripts -add tap tapns30 to switch sw3 vni 1 post-script /root/vproxy/tapns30.sh -add tap tapns40 to switch sw3 vni 2 post-script /root/vproxy/tapns40.sh -add tap tap5 to switch sw3 vni 3 post-script /root/vproxy/tap5.sh -``` - -Then add iptables rules for the virtual network to visit the Internet. - -```shell -# enable ip_forward -sysctl -w net.ipv4.ip_forward=1 - -# add rules -iptables -t nat -A POSTROUTING -s 172.16.1.0/24 -d 100.64.0.0/10 -o enp0s8 -j SNAT --to 100.64.0.4 -iptables -t nat -A POSTROUTING -s 172.16.2.0/24 -d 100.64.0.0/10 -o enp0s8 -j SNAT --to 100.64.0.4 -iptables -t nat -A POSTROUTING -s 172.16.3.0/24 -d 100.64.0.0/10 -o enp0s8 -j SNAT --to 100.64.0.4 - -iptables -t nat -A POSTROUTING -s 172.16.1.0/24 ! -d 172.16.0.0/12 -o enp0s3 -j SNAT --to 10.0.2.15 -iptables -t nat -A POSTROUTING -s 172.16.2.0/24 ! -d 172.16.0.0/12 -o enp0s3 -j SNAT --to 10.0.2.15 -iptables -t nat -A POSTROUTING -s 172.16.3.0/24 ! -d 172.16.0.0/12 -o enp0s3 -j SNAT --to 10.0.2.15 -``` - -Here, I have a device called `enp0s3` connected to the Internet, and I have device called `enp0s8`, which is connected to `100.64.0.0/10` network. - -Change the settings to match your network. - -### Host X - -We create a bridge for testing: If we can manage a bridge device, we are able to manage any linux device by putting it on the bridge. - -```shell -# br0 -ip link add name br0 type bridge -# fix the mac address of the bridge -ip link set dev br0 address 08:00:00:00:00:00 -# add ips -ip addr add 172.16.1.101/24 dev br0 -ip -6 addr add fd00::165/120 dev br0 -# up -ip link set dev br0 up -# add routes -ip route add 172.16.2.0/24 via 172.16.1.254 -ip route add 172.16.3.0/24 via 172.16.1.254 -ip -6 route add fd00::200/120 via fd00::1fe dev br0 -ip -6 route add fd00::300/120 via fd00::1fe dev br0 -``` - -Prepare a script and remember to `chmod +x` on it: - -`/root/vproxy/tap101.sh` - -```shell -ip link set dev tap101 up -ip link set dev tap101 master br0 -``` - -Here, we do not assign ip on the tap device, simply move it into the bridge. - -Enter the following commands to vproxy: - -```shell -# create switch sw-pub -add switch sw-pub address 0.0.0.0:18472 - -# create vpc 101,102, NOTE we do not create vpc 103 here -add vpc 101 to switch sw-pub v4network 172.16.1.0/24 v6network fd00::100/120 -add vpc 102 to switch sw-pub v4network 172.16.2.0/24 v6network fd00::200/120 - -# add user for sw1 to connect -add user sw1x1 to switch sw-pub vni 101 password vproxy -add user sw1x2 to switch sw-pub vni 102 password vproxy - -# add synthetic ip in vpc 1 -add ip 172.16.2.254 to vpc 102 in switch sw-pub mac 04:00:00:00:22:54 -add ip fd00::2fe to vpc 102 in switch sw-pub mac 06:00:00:00:22:54 - -# add route from vpc 2 to vpc 1 -add route route-to-1 to vpc 102 in switch sw-pub network 172.16.1.0/24 vni 101 -add route route-to-1-v6 to vpc 102 in switch sw-pub network fd00::100/120 vni 101 -# add route from vpc 1 to vpc 2 -add route route-to-2 to vpc 101 in switch sw-pub network 172.16.2.0/24 vni 102 -add route route-to-2-v6 to vpc 101 in switch sw-pub network fd00::200/120 vni 102 - -# add corresponding synthetic ips in the routed vpc -add ip 172.16.1.190 to vpc 101 in switch sw-pub mac 04:00:00:00:11:90 -add ip fd00::1be to vpc 101 in switch sw-pub mac 06:00:00:00:11:90 - -# add routes -# note, here we do not have a encrypted link from vpc 3 to vpc 103 (and we did not create vpc 103 at all) -# as a result, we route vpc 3 packets to vpc 101, and then route them to gateway of vpc 1 -add route route-to-3-1 to vpc 102 in switch sw-pub network 172.16.3.0/24 vni 101 -add route route-to-3 to vpc 101 in switch sw-pub network 172.16.3.0/24 via 172.16.1.254 -add route route-to-3-1-v6 to vpc 102 in switch sw-pub network fd00::300/120 vni 101 -add route route-to-3-v6 to vpc 101 in switch sw-pub network fd00::300/120 via fd00::1fe - -# add route to the internet -# first route to vpc 101, then route to the default gateway of vpc 1 -add route route-to-internet-1 to vpc 102 in switch sw-pub network 0.0.0.0/0 vni 101 -add route route-to-internet to vpc 101 in switch sw-pub network 0.0.0.0/0 via 172.16.1.254 -add route route-to-internet-1-v6 to vpc 102 in switch sw-pub network ::/0 vni 101 -add route route-to-internet-v6 to vpc 101 in switch sw-pub network ::/0 via fd00::1fe - -# add tap devices and execute the prepared scripts -add tap tap101 to switch sw-pub vni 101 post-script /root/vproxy/tap101.sh -``` +You may use `switch-test-init.sh` to build the testing environment. ### Debug @@ -755,7 +395,7 @@ The bare vxlan endpoint (VM on the graph), and the encrypted link (from sw1 to s To check the connectivity between switches, use command `list-detail iface in switch ${switch-name}`. -To check mac+arp table, use command `list-detail arp in vpc ${vni} in switch ${switch-name}`. +To check mac+arp table, use command `list-detail arp in vrf ${vrf} in switch ${switch-name}`. When a packet arrives, switch will record the input interface and the src mac of the input packet. diff --git a/doc/using-application-layer-protocols.md b/doc/using-application-layer-protocols.md index 7ee429345..788126408 100644 --- a/doc/using-application-layer-protocols.md +++ b/doc/using-application-layer-protocols.md @@ -5,7 +5,7 @@ The layer 4 TCP loadbalancer transfers all data from one frontend connection to one backend. This will result in the following major problems: 1. One backend load would be higher than others if the netflow of a single connection is very high but other connections are not busy. -2. RPC is frequently used in the internal network (e.g. idc or vpc). Almost all impl of rpc protocols would create a connection with a few connnections, and won't be closed in normal cases. If using the L4 loadbalancing, the backend rpc services won't be able to scale out. +2. RPC is frequently used in the internal network. Almost all impl of rpc protocols would create a connection with a few connnections, and won't be closed in normal cases. If using the L4 loadbalancing, the backend rpc services won't be able to scale out. So `vproxy` defines a set of interfaces which allow users to customize their own application level protocols, and to dispatch frames to different backend in one connection. diff --git a/doc_zh/switch-fubuki-integration.md b/doc_zh/switch-fubuki-integration.md index d3ede046a..9b14a0435 100644 --- a/doc_zh/switch-fubuki-integration.md +++ b/doc_zh/switch-fubuki-integration.md @@ -10,11 +10,11 @@ 可以在启动vproxy后,使用如下命令查看本文档用到的命令细节: * `man switch` -* `man vpc` +* `man vrf` * `man fubuki` * `man iface` * `man switch add` -* `man vpc add-to` +* `man vrf add-to` * `man fubuki add-to` * `man iface list-detail` * `man iface remove-from` @@ -37,26 +37,26 @@ add switch sw0 3. 创建虚拟网络 ``` -add vpc 1 to switch sw0 v4network 10.99.88.0/24 +add vrf 1 to switch sw0 v4network 10.99.88.0/24 ``` 命令解释: -* `add vpc 1` 表示创建`1`号vpc,其vni即为1 +* `add vrf 1` 表示创建`1`号vrf * `to switch sw0` 表示加入`sw0`中 -* `v4network $.$.$.$/$` 表示该vpc的v4的网段限制 +* `v4network $.$.$.$/$` 表示该vrf的v4的网段限制 4. 创建fubuki接口 ``` -add fubuki fbk0 to switch sw0 vni 1 mac 00:11:22:33:44:55 ip 10.99.88.199/24 address $.$.$.$:$ password $ +add fubuki fbk0 to switch sw0 vrf 1 mac 00:11:22:33:44:55 ip 10.99.88.199/24 address $.$.$.$:$ password $ ``` 命令解释: * `add fubuki fbk0` 表示创建一个fubuki网口,名为`fbk0` * `to switch sw0` 表示加入`sw0`中 -* `vni 1` 表示该网口默认属于vni为`1`的vpc,即`vpc 1` +* `vrf 1` 表示该网口默认属于`vrf 1` * `mac $:$:$:$:$:$` 表示为该网口分配的mac地址。由于fubuki是tun模式,所以需要交换机为其模拟二层报文 * `ip $.$.$.$/$` 表示该网口使用的ip和掩码,可以不指定,不指定则由fubuki为其分配一个ip * `address $.$.$.$:$` 表示远端fubuki地址和端口 diff --git a/doc_zh/using-application-layer-protocols.md b/doc_zh/using-application-layer-protocols.md index 2c4da989d..52f094cc1 100644 --- a/doc_zh/using-application-layer-protocols.md +++ b/doc_zh/using-application-layer-protocols.md @@ -5,7 +5,7 @@ 纯四层的TCP负载均衡将一条前端连接的所有流量转发到同一个后端。这会引发如下几个主要问题: 1. 如果某一连接的流量非常高,但其他连接的流量较低,则会导致某一特定后端的负载升高。 -2. 内部网络(比如idc或者云计算的vpc)经常使用rpc,几乎所有rpc协议的实现都会开一个带有少量连接的连接池,并且正常情况下连接不会关闭。如果使用四层负载均衡,rpc服务将无法进行水平扩容。 +2. 内部网络经常使用rpc,几乎所有rpc协议的实现都会开一个带有少量连接的连接池,并且正常情况下连接不会关闭。如果使用四层负载均衡,rpc服务将无法进行水平扩容。 所以`vproxy`定义了一套接口,允许用户自定义应用层协议,可以自由地将不同的frame分发至不同的后端。 diff --git a/extended/src/main/java/io/vproxy/vproxyx/pktfiltergen/flow/FlowMatcher.java b/extended/src/main/java/io/vproxy/vproxyx/pktfiltergen/flow/FlowMatcher.java index 65bac7ac3..25738acb0 100644 --- a/extended/src/main/java/io/vproxy/vproxyx/pktfiltergen/flow/FlowMatcher.java +++ b/extended/src/main/java/io/vproxy/vproxyx/pktfiltergen/flow/FlowMatcher.java @@ -40,8 +40,8 @@ public class FlowMatcher { // ct_state public String ct_state; - // vni - public int vni; + // vrf + public int vrf; // customized public String predicate; @@ -107,8 +107,8 @@ public String toIfConditionString(Flows.GenContext ctx) { throw new UnsupportedOperationException("ct_state=" + ct_state); } } - if (vni != 0) { - appendAnd(sb).append("pkb.network != null && pkb.network.vni == ").append(vni); + if (vrf != 0) { + appendAnd(sb).append("pkb.network != null && pkb.network.vrf == ").append(vrf); } if (predicate != null) { ctx.registerPredicateMethod(predicate); @@ -193,8 +193,8 @@ public String toString() { if (ct_state != null) { appendSplit(sb).append("ct_state=").append(ct_state); } - if (vni != 0) { - appendSplit(sb).append("vni=").append(vni); + if (vrf != 0) { + appendSplit(sb).append("vrf=").append(vrf); } if (predicate != null) { appendSplit(sb).append("predicate=").append(predicate); diff --git a/extended/src/main/java/io/vproxy/vproxyx/pktfiltergen/flow/FlowParser.java b/extended/src/main/java/io/vproxy/vproxyx/pktfiltergen/flow/FlowParser.java index 7127ffaa9..d146273a8 100644 --- a/extended/src/main/java/io/vproxy/vproxyx/pktfiltergen/flow/FlowParser.java +++ b/extended/src/main/java/io/vproxy/vproxyx/pktfiltergen/flow/FlowParser.java @@ -173,8 +173,8 @@ private void parseMatcher(String s) throws Exception { } flow.matcher.ct_state = value; return; - case "vni": - flow.matcher.vni = parsePositiveInt(value); + case "vrf": + flow.matcher.vrf = parsePositiveInt(value); return; case "predicate": assertValidMethodName(value); diff --git a/misc/general.md b/misc/general.md index a9b3ed41b..14f0ae346 100644 --- a/misc/general.md +++ b/misc/general.md @@ -55,7 +55,7 @@ There are many kinds of `$resource-type`s, as shown in this figure: session (sess) --+ dns-cache --+-- /* state */ - vni --+ + vrf --+ arp --+ bytes-in (bin) --+ diff --git a/misc/netnsutil.py b/misc/netnsutil.py index ef98a459f..f1594a011 100755 --- a/misc/netnsutil.py +++ b/misc/netnsutil.py @@ -45,7 +45,7 @@ def runVProxyCommand(swaddr, password, commandStr): def buildTapName(ns): return 'tap' + ns + '0' -def add(swaddr, password, sw, ns, vni, addr, gate, v6addr, v6gate): +def add(swaddr, password, sw, ns, vrf, addr, gate, v6addr, v6gate): # check for netns ret, out, err = runCommand(['ip', 'netns', 'show']) if ret != 0: @@ -79,7 +79,7 @@ def add(swaddr, password, sw, ns, vni, addr, gate, v6addr, v6gate): if not exists: print 'creating ' + nic + ' in main ns ...' ret, out, err = runVProxyCommand(swaddr, password, - 'add tap ' + nic + ' to switch ' + sw + ' vni ' + vni) + 'add tap ' + nic + ' to switch ' + sw + ' vrf ' + vrf) if ret != 0: raise Exception('creating tap ' + nic + ' failed: ' + out + ', ' + err) if out != nic: @@ -207,14 +207,14 @@ def main(args): op = None sw = None ns = None - vni = None + vrf = None addr = None gate = None v6addr = None v6gate = None HELP_STR=""" -usage: add ns={} sw={} vni={} addr={} gate={} [v6addr={} v6gate={}] +usage: add ns={} sw={} vrf={} addr={} gate={} [v6addr={} v6gate={}] del ns={} sw={} default: swaddr = 127.0.0.1:16309 @@ -224,7 +224,7 @@ def main(args): pass vproxy switch configuration password ns name of the netns sw name of the switch to connect to - vni vni for the net interface to connect to + vrf vrf for the net interface to connect to addr ip address and mask of the net dev in x.x.x.x/x format gate the gateway address v6addr ipv6 address and mask of the net dev [optional] @@ -251,8 +251,8 @@ def main(args): sw = arg[len('sw='):] elif arg.startswith('ns='): ns = arg[len('ns='):] - elif arg.startswith('vni='): - vni = arg[len('vni='):] + elif arg.startswith('vrf='): + vrf = arg[len('vrf='):] elif arg.startswith('addr='): addr = arg[len('addr='):] elif arg.startswith('gate='): @@ -284,8 +284,8 @@ def main(args): raise Exception('missing argument sw={...}') if ns == None: raise Exception('missing argument ns={...}') - if vni == None: - raise Exception('missing argument vni={...}') + if vrf == None: + raise Exception('missing argument vrf={...}') if addr == None: raise Exception('missing argument addr={...}') if gate == None: @@ -300,13 +300,13 @@ def main(args): print 'password = ' + password print 'sw = ' + sw print 'ns = ' + ns - print 'vni = ' + vni + print 'vrf = ' + vrf print 'addr = ' + addr print 'gate = ' + gate print 'v6addr =', v6addr print 'v6gate =', v6gate print '==========================' - add(swaddr, password, sw, ns, vni, addr, gate, v6addr, v6gate) + add(swaddr, password, sw, ns, vrf, addr, gate, v6addr, v6gate) else: if sw == None: raise Exception('missing argument sw={...}') diff --git a/misc/switch-test-init.sh b/misc/switch-test-init.sh index c697e344c..ef70e5f8a 100755 --- a/misc/switch-test-init.sh +++ b/misc/switch-test-init.sh @@ -282,145 +282,145 @@ echo "releasing files ..." cat > /vproxy/sw1 < /vproxy/sw2 < /vproxy/sw3 < /vproxy/sw-pub < /vproxy/tapns10.sh < /vproxy/tapns20.sh < /vproxy/tapns30.sh < /vproxy/tapns40.sh <