Search in sources :

Example 31 with KubevirtNode

use of org.onosproject.kubevirtnode.api.KubevirtNode in project onos by opennetworkinglab.

the class KubevirtFlowRuleManager method initializeGatewayNodePipeline.

protected void initializeGatewayNodePipeline(KubevirtNode kubevirtNode) {
    DeviceId deviceId = kubevirtNode.intgBridge();
    // for inbound to gateway entry table transition
    connectTables(deviceId, STAT_INBOUND_TABLE, GW_ENTRY_TABLE);
    // for gateway entry to gateway drop table transition
    connectTables(deviceId, GW_ENTRY_TABLE, GW_DROP_TABLE);
    // for setting up default gateway drop table
    setupGatewayNodeDropTable(deviceId);
    // for setting up default Forwarding table behavior which is NORMAL
    setupNormalTable(deviceId, FORWARDING_TABLE);
    kubevirtNode.phyIntfs().stream().filter(intf -> intf.physBridge() != null).forEach(phyIntf -> {
        setupNormalTable(phyIntf.physBridge(), STAT_INBOUND_TABLE);
    });
}
Also used : DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) GATEWAY(org.onosproject.kubevirtnode.api.KubevirtNode.Type.GATEWAY) CoreService(org.onosproject.core.CoreService) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) FlowRuleService(org.onosproject.net.flow.FlowRuleService) ApplicationId(org.onosproject.core.ApplicationId) NodeId(org.onosproject.cluster.NodeId) GW_DROP_TABLE(org.onosproject.kubevirtnetworking.api.Constants.GW_DROP_TABLE) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) GW_ENTRY_TABLE(org.onosproject.kubevirtnetworking.api.Constants.GW_ENTRY_TABLE) Executors(java.util.concurrent.Executors) Objects(java.util.Objects) EthType(org.onlab.packet.EthType) FlowRule(org.onosproject.net.flow.FlowRule) ACL_EGRESS_TABLE(org.onosproject.kubevirtnetworking.api.Constants.ACL_EGRESS_TABLE) ClusterService(org.onosproject.cluster.ClusterService) PRIORITY_ARP_DEFAULT_RULE(org.onosproject.kubevirtnetworking.api.Constants.PRIORITY_ARP_DEFAULT_RULE) DeviceId(org.onosproject.net.DeviceId) Dictionary(java.util.Dictionary) FlowRuleOperationsContext(org.onosproject.net.flow.FlowRuleOperationsContext) DHCP_TABLE(org.onosproject.kubevirtnetworking.api.Constants.DHCP_TABLE) ARP_TABLE(org.onosproject.kubevirtnetworking.api.Constants.ARP_TABLE) KubevirtNetworkingUtil.getPropertyValueAsBoolean(org.onosproject.kubevirtnetworking.util.KubevirtNetworkingUtil.getPropertyValueAsBoolean) Tools(org.onlab.util.Tools) KubevirtFlowRuleService(org.onosproject.kubevirtnetworking.api.KubevirtFlowRuleService) ComponentContext(org.osgi.service.component.ComponentContext) FORWARDING_TABLE(org.onosproject.kubevirtnetworking.api.Constants.FORWARDING_TABLE) KubevirtNodeService(org.onosproject.kubevirtnode.api.KubevirtNodeService) Component(org.osgi.service.component.annotations.Component) WORKER(org.onosproject.kubevirtnode.api.KubevirtNode.Type.WORKER) TrafficSelector(org.onosproject.net.flow.TrafficSelector) Activate(org.osgi.service.component.annotations.Activate) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) ExecutorService(java.util.concurrent.ExecutorService) PROVIDER_NETWORK_ONLY_DEFAULT(org.onosproject.kubevirtnetworking.impl.OsgiPropertyConstants.PROVIDER_NETWORK_ONLY_DEFAULT) KUBEVIRT_NETWORKING_APP_ID(org.onosproject.kubevirtnetworking.api.Constants.KUBEVIRT_NETWORKING_APP_ID) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) Logger(org.slf4j.Logger) STAT_INBOUND_TABLE(org.onosproject.kubevirtnetworking.api.Constants.STAT_INBOUND_TABLE) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) KubevirtNodeEvent(org.onosproject.kubevirtnode.api.KubevirtNodeEvent) VTAP_INBOUND_TABLE(org.onosproject.kubevirtnetworking.api.Constants.VTAP_INBOUND_TABLE) KubevirtNodeListener(org.onosproject.kubevirtnode.api.KubevirtNodeListener) PROVIDER_NETWORK_ONLY(org.onosproject.kubevirtnetworking.impl.OsgiPropertyConstants.PROVIDER_NETWORK_ONLY) ConfigProperty(org.onosproject.cfg.ConfigProperty) Modified(org.osgi.service.component.annotations.Modified) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Reference(org.osgi.service.component.annotations.Reference) LeadershipService(org.onosproject.cluster.LeadershipService) DeviceId(org.onosproject.net.DeviceId)

Example 32 with KubevirtNode

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);
    }
}
Also used : KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode)

Example 33 with KubevirtNode

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());
}
Also used : KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) KubevirtNetwork(org.onosproject.kubevirtnetworking.api.KubevirtNetwork) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) PortNumber(org.onosproject.net.PortNumber) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 34 with KubevirtNode

use of org.onosproject.kubevirtnode.api.KubevirtNode in project onos by opennetworkinglab.

the class KubevirtSwitchingTenantHandler method setIngressRules.

private void setIngressRules(KubevirtNetwork network, boolean install) {
    if (network == null) {
        return;
    }
    if (network.type() == FLAT || network.type() == VLAN) {
        return;
    }
    if (network.segmentId() == null) {
        return;
    }
    for (KubevirtNode localNode : kubevirtNodeService.completeNodes(WORKER)) {
        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 ingress rule setup on node {}", updatedNode);
                waitFor(3);
            }
        }
        PortNumber patchPortNumber = tunnelToTenantPort(deviceService, localNode, network);
        TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder().matchTunnelId(Long.parseLong(network.segmentId()));
        TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder().setOutput(patchPortNumber);
        flowRuleService.setRule(appId, localNode.tunBridge(), sBuilder.build(), tBuilder.build(), PRIORITY_TUNNEL_RULE, TUNNEL_DEFAULT_TABLE, install);
        log.debug("Install ingress rules for segment ID {}", network.segmentId());
    }
}
Also used : KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) PortNumber(org.onosproject.net.PortNumber) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 35 with KubevirtNode

use of org.onosproject.kubevirtnode.api.KubevirtNode in project onos by opennetworkinglab.

the class KubevirtNodeCodec method decode.

@Override
public KubevirtNode decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    String hostname = nullIsIllegal(json.get(HOST_NAME).asText(), HOST_NAME + MISSING_MESSAGE);
    String type = nullIsIllegal(json.get(TYPE).asText(), TYPE + MISSING_MESSAGE);
    String mIp = nullIsIllegal(json.get(MANAGEMENT_IP).asText(), MANAGEMENT_IP + MISSING_MESSAGE);
    KubevirtNode.Builder nodeBuilder = DefaultKubevirtNode.builder().hostname(hostname).type(KubevirtNode.Type.valueOf(type)).state(KubevirtNodeState.INIT).managementIp(IpAddress.valueOf(mIp));
    if (json.get(DATA_IP) != null) {
        nodeBuilder.dataIp(IpAddress.valueOf(json.get(DATA_IP).asText()));
    }
    JsonNode intBridgeJson = json.get(INTEGRATION_BRIDGE);
    if (intBridgeJson != null) {
        nodeBuilder.intgBridge(DeviceId.deviceId(intBridgeJson.asText()));
    }
    JsonNode tunBridgeJson = json.get(TUNNEL_BRIDGE);
    if (tunBridgeJson != null) {
        nodeBuilder.tunBridge(DeviceId.deviceId(tunBridgeJson.asText()));
    }
    // parse physical interfaces
    List<KubevirtPhyInterface> phyIntfs = new ArrayList<>();
    JsonNode phyIntfsJson = json.get(PHYSICAL_INTERFACES);
    if (phyIntfsJson != null) {
        final JsonCodec<KubevirtPhyInterface> phyIntfCodec = context.codec(KubevirtPhyInterface.class);
        IntStream.range(0, phyIntfsJson.size()).forEach(i -> {
            ObjectNode intfJson = get(phyIntfsJson, i);
            phyIntfs.add(phyIntfCodec.decode(intfJson, context));
        });
    }
    nodeBuilder.phyIntfs(phyIntfs);
    JsonNode externalBridgeJson = json.get(GATEWAY_BRIDGE_NAME);
    if (externalBridgeJson != null) {
        nodeBuilder.gatewayBridgeName(externalBridgeJson.asText());
    }
    log.trace("node is {}", nodeBuilder.build().toString());
    return nodeBuilder.build();
}
Also used : KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) DefaultKubevirtNode(org.onosproject.kubevirtnode.api.DefaultKubevirtNode) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) KubevirtPhyInterface(org.onosproject.kubevirtnode.api.KubevirtPhyInterface) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

KubevirtNode (org.onosproject.kubevirtnode.api.KubevirtNode)49 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)13 TrafficSelector (org.onosproject.net.flow.TrafficSelector)13 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)13 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)12 PortNumber (org.onosproject.net.PortNumber)11 KubevirtNodeAdminService (org.onosproject.kubevirtnode.api.KubevirtNodeAdminService)10 DefaultKubevirtNode (org.onosproject.kubevirtnode.api.DefaultKubevirtNode)9 Produces (javax.ws.rs.Produces)8 KubevirtNodeService (org.onosproject.kubevirtnode.api.KubevirtNodeService)8 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 Path (javax.ws.rs.Path)6 Test (org.junit.Test)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 Set (java.util.Set)5 GET (javax.ws.rs.GET)5 MacAddress (org.onlab.packet.MacAddress)5 DeviceId (org.onosproject.net.DeviceId)5 DeviceService (org.onosproject.net.device.DeviceService)5 Logger (org.slf4j.Logger)5