use of org.onosproject.kubevirtnode.api.KubevirtNode in project onos by opennetworkinglab.
the class KubevirtNetworkHandler method setGatewayIcmpRulesForTenantNetwork.
private void setGatewayIcmpRulesForTenantNetwork(KubevirtNode node, KubevirtNetwork network) {
KubevirtRouter router = getRouterForKubevirtNetwork(kubevirtRouterService, network);
if (router == null) {
return;
}
KubevirtNode electedGw = gatewayNodeForSpecifiedRouter(nodeService, router);
if (electedGw == null) {
return;
}
setGatewayIcmpRuleForTenantInternalNetwork(router, network, TENANT_ICMP_TABLE, electedGw.intgBridge(), network.tenantDeviceId(node.hostname()), true);
}
use of org.onosproject.kubevirtnode.api.KubevirtNode in project onos by opennetworkinglab.
the class KubevirtRoutingSnatHandler method initGatewayNodeSnatForRouter.
private void initGatewayNodeSnatForRouter(KubevirtRouter router, String gateway, boolean install) {
if (gateway == null) {
log.warn("Fail to initialize gateway node snat for router {} " + "because there's no gateway assigned to it", router.name());
return;
}
KubevirtNode electedGw = kubevirtNodeService.node(gateway);
if (electedGw == null) {
log.warn("Fail to initialize gateway node snat for router {} " + "because there's no gateway assigned to it", router.name());
return;
}
String routerSnatIp = router.external().keySet().stream().findAny().orElse(null);
if (routerSnatIp == null) {
log.warn("Fail to initialize gateway node snat for router {} " + "because there's no gateway snat ip assigned to it", router.name());
return;
}
String externalNet = router.external().values().stream().findAny().orElse(null);
if (externalNet == null) {
return;
}
if (router.peerRouter() != null && router.peerRouter().ipAddress() != null && router.peerRouter().macAddress() != null) {
setArpResponseToPeerRouter(electedGw, Ip4Address.valueOf(routerSnatIp), install);
setStatefulSnatUpstreamRules(electedGw, router, Ip4Address.valueOf(routerSnatIp), router.peerRouter().macAddress(), install);
setStatefulSnatDownstreamRuleForRouter(electedGw, router, Ip4Address.valueOf(routerSnatIp), kubevirtNetworkService.network(externalNet), install);
}
}
use of org.onosproject.kubevirtnode.api.KubevirtNode in project onos by opennetworkinglab.
the class KubevirtRoutingArpHandler method setRuleArpRequestToController.
/**
* Sets default ARP flow rule to retrieve peer router mac address.
*
* @param routerSnatIp route Snat IP
* @param peerRouterIp peer router IP
* @param gatewayNodeId gateway node
* @param install install if true, uninstall otherwise
*/
private void setRuleArpRequestToController(IpAddress routerSnatIp, IpAddress peerRouterIp, String gatewayNodeId, boolean install) {
KubevirtNode gatewayNode = kubevirtNodeService.node(gatewayNodeId);
if (gatewayNode == null) {
return;
}
if (routerSnatIp == null) {
return;
}
TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(EthType.EtherType.ARP.ethType().toShort()).matchArpOp(ARP.OP_REPLY).matchArpSpa(peerRouterIp.getIp4Address()).matchArpTpa(routerSnatIp.getIp4Address()).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().punt().build();
kubevirtFlowRuleService.setRule(appId, gatewayNode.intgBridge(), selector, treatment, PRIORITY_ARP_GATEWAY_RULE, GW_ENTRY_TABLE, install);
}
use of org.onosproject.kubevirtnode.api.KubevirtNode in project onos by opennetworkinglab.
the class KubevirtRoutingArpHandler method retrievePeerRouterMac.
/**
* Triggers ARP request to retrieve the peer router mac address.
*
* @param router kubevirt router
* @param peerRouterIp peer router IP address
*/
private void retrievePeerRouterMac(KubevirtRouter router, IpAddress peerRouterIp) {
log.info("Sending ARP request to the peer router {} to retrieve the MAC address.", peerRouterIp.getIp4Address().toString());
String routerSnatIp = router.external().keySet().stream().findAny().orElse(null);
if (routerSnatIp == null) {
return;
}
IpAddress sourceIp = IpAddress.valueOf(routerSnatIp);
MacAddress sourceMac = DEFAULT_GATEWAY_MAC;
Ethernet ethRequest = ARP.buildArpRequest(sourceMac.toBytes(), sourceIp.toOctets(), peerRouterIp.toOctets(), VlanId.NO_VID);
KubevirtNode gatewayNode = kubevirtNodeService.node(router.electedGateway());
if (gatewayNode == null) {
return;
}
PortNumber externalPatchPortNum = KubevirtNetworkingUtil.externalPatchPortNum(deviceService, gatewayNode);
if (externalPatchPortNum == null) {
return;
}
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(externalPatchPortNum).build();
packetService.emit(new DefaultOutboundPacket(gatewayNode.intgBridge(), treatment, ByteBuffer.wrap(ethRequest.serialize())));
}
use of org.onosproject.kubevirtnode.api.KubevirtNode in project onos by opennetworkinglab.
the class KubevirtSwitchingTenantHandler method setEgressRules.
private void setEgressRules(KubevirtPort port, boolean install) {
if (port.ipAddress() == null) {
return;
}
KubevirtNetwork network = kubevirtNetworkService.network(port.networkId());
if (network == null) {
return;
}
if (network.type() == FLAT || network.type() == VLAN) {
return;
}
if (network.segmentId() == null) {
return;
}
KubevirtNode localNode = kubevirtNodeService.node(port.deviceId());
if (localNode == null || localNode.type() == MASTER) {
return;
}
for (KubevirtNode remoteNode : kubevirtNodeService.completeNodes(WORKER)) {
if (remoteNode.hostname().equals(localNode.hostname())) {
continue;
}
while (true) {
KubevirtNode updatedNode = kubevirtNodeService.node(localNode.hostname());
if (tunnelToTenantPort(deviceService, updatedNode, network) != null) {
break;
} else {
log.info("Waiting for tunnel to tenant patch port creation " + "on egress rule setup on node {}", updatedNode);
waitFor(3);
}
}
PortNumber patchPortNumber = tunnelToTenantPort(deviceService, remoteNode, network);
PortNumber tunnelPortNumber = tunnelPort(remoteNode, network);
if (tunnelPortNumber == null) {
return;
}
TrafficSelector.Builder sIpBuilder = DefaultTrafficSelector.builder().matchInPort(patchPortNumber).matchEthType(Ethernet.TYPE_IPV4).matchIPDst(IpPrefix.valueOf(port.ipAddress(), 32));
TrafficSelector.Builder sArpBuilder = DefaultTrafficSelector.builder().matchInPort(patchPortNumber).matchEthType(Ethernet.TYPE_ARP).matchArpTpa(Ip4Address.valueOf(port.ipAddress().toString()));
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder().setTunnelId(Long.parseLong(network.segmentId())).extension(buildExtension(deviceService, remoteNode.tunBridge(), localNode.dataIp().getIp4Address()), remoteNode.tunBridge()).setOutput(tunnelPortNumber);
flowRuleService.setRule(appId, remoteNode.tunBridge(), sIpBuilder.build(), tBuilder.build(), PRIORITY_TUNNEL_RULE, TUNNEL_DEFAULT_TABLE, install);
flowRuleService.setRule(appId, remoteNode.tunBridge(), sArpBuilder.build(), tBuilder.build(), PRIORITY_TUNNEL_RULE, TUNNEL_DEFAULT_TABLE, install);
}
log.debug("Install egress rules for instance {}, segment ID {}", port.ipAddress(), network.segmentId());
}
Aggregations