Search in sources :

Example 1 with GATEWAY

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

the class KubevirtPrometheusAssuranceManager method publishSnatMetrics.

private void publishSnatMetrics() {
    if (prometheusExporter == null) {
        log.error("Prometheus Server isn't ready.");
        return;
    }
    String[] snatLabelValues = new String[3];
    routerService.routers().stream().filter(router -> router.enableSnat() && router.electedGateway() != null && router.peerRouter() != null && router.peerRouter().ipAddress() != null && router.peerRouter().macAddress() != null).forEach(router -> {
        KubevirtNode gateway = nodeService.node(router.electedGateway());
        if (gateway == null) {
            return;
        }
        String routerSnatIp = router.external().keySet().stream().findAny().orElse(null);
        if (routerSnatIp == null) {
            return;
        }
        flowRuleService.getFlowEntries(gateway.intgBridge()).forEach(flowEntry -> {
            if (((IndexTableId) flowEntry.table()).id() == GW_ENTRY_TABLE && flowEntry.priority() == PRIORITY_STATEFUL_SNAT_RULE) {
                snatLabelValues[0] = router.name();
                snatLabelValues[1] = routerSnatIp;
                snatLabelValues[2] = gateway.hostname();
                if (isSnatUpstreamFlorEntryForRouter(router, flowEntry)) {
                    pktSNATTx.labels(snatLabelValues).set(flowEntry.packets());
                    byteSNATTx.labels(snatLabelValues).set(flowEntry.bytes());
                } else if (isSnatDownstreamFlorEntryForRouter(routerSnatIp, flowEntry)) {
                    pktSNATRx.labels(snatLabelValues).set(flowEntry.packets());
                    byteSNATRx.labels(snatLabelValues).set(flowEntry.bytes());
                }
            }
        });
    });
}
Also used : ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) ScheduledFuture(java.util.concurrent.ScheduledFuture) KubevirtRouter(org.onosproject.kubevirtnetworking.api.KubevirtRouter) GATEWAY(org.onosproject.kubevirtnode.api.KubevirtNode.Type.GATEWAY) CoreService(org.onosproject.core.CoreService) DeviceService(org.onosproject.net.device.DeviceService) FlowEntry(org.onosproject.net.flow.FlowEntry) KubevirtPort(org.onosproject.kubevirtnetworking.api.KubevirtPort) KubevirtNodeService(org.onosproject.kubevirtnode.api.KubevirtNodeService) ETH_SRC(org.onosproject.net.flow.criteria.Criterion.Type.ETH_SRC) SharedScheduledExecutors(org.onlab.util.SharedScheduledExecutors) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) Component(org.osgi.service.component.annotations.Component) FlowRuleService(org.onosproject.net.flow.FlowRuleService) TrafficSelector(org.onosproject.net.flow.TrafficSelector) PRIORITY_STATEFUL_SNAT_RULE(org.onosproject.kubevirtnetworking.api.Constants.PRIORITY_STATEFUL_SNAT_RULE) Gauge(io.prometheus.client.Gauge) Activate(org.osgi.service.component.annotations.Activate) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) Server(org.eclipse.jetty.server.Server) KubevirtFloatingIp(org.onosproject.kubevirtnetworking.api.KubevirtFloatingIp) PRIORITY_FLOATING_IP_UPSTREAM_RULE(org.onosproject.kubevirtnetworking.api.Constants.PRIORITY_FLOATING_IP_UPSTREAM_RULE) IpAddress(org.onlab.packet.IpAddress) KubevirtRouterService(org.onosproject.kubevirtnetworking.api.KubevirtRouterService) KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) Logger(org.slf4j.Logger) KubevirtPrometheusAssuranceService(org.onosproject.kubevirtnetworking.api.KubevirtPrometheusAssuranceService) IndexTableId(org.onosproject.net.flow.IndexTableId) Deactivate(org.osgi.service.component.annotations.Deactivate) MetricsServlet(io.prometheus.client.exporter.MetricsServlet) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ETH_DST(org.onosproject.net.flow.criteria.Criterion.Type.ETH_DST) GW_ENTRY_TABLE(org.onosproject.kubevirtnetworking.api.Constants.GW_ENTRY_TABLE) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) TimeUnit(java.util.concurrent.TimeUnit) PRIORITY_FLOATING_IP_DOWNSTREAM_RULE(org.onosproject.kubevirtnetworking.api.Constants.PRIORITY_FLOATING_IP_DOWNSTREAM_RULE) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) MacAddress(org.onlab.packet.MacAddress) Reference(org.osgi.service.component.annotations.Reference) IPV4_DST(org.onosproject.net.flow.criteria.Criterion.Type.IPV4_DST) KubevirtPortService(org.onosproject.kubevirtnetworking.api.KubevirtPortService) KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) IndexTableId(org.onosproject.net.flow.IndexTableId)

Example 2 with GATEWAY

use of org.onosproject.kubevirtnode.api.KubevirtNode.Type.GATEWAY 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 3 with GATEWAY

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

the class KubevirtNodeUtil method buildKubevirtNode.

/**
 * Returns the kubevirt node from the node.
 *
 * @param node a raw node object returned from a k8s client
 * @return kubevirt node
 */
public static KubevirtNode buildKubevirtNode(Node node) {
    String hostname = node.getMetadata().getName();
    IpAddress managementIp = null;
    IpAddress dataIp = null;
    for (NodeAddress nodeAddress : node.getStatus().getAddresses()) {
        if (nodeAddress.getType().equals(INTERNAL_IP)) {
            managementIp = IpAddress.valueOf(nodeAddress.getAddress());
            dataIp = IpAddress.valueOf(nodeAddress.getAddress());
        }
    }
    Set<String> rolesFull = node.getMetadata().getLabels().keySet().stream().filter(l -> l.contains(K8S_ROLE)).collect(Collectors.toSet());
    KubevirtNode.Type nodeType = WORKER;
    for (String roleStr : rolesFull) {
        String role = roleStr.split("/")[1];
        if (MASTER.name().equalsIgnoreCase(role)) {
            nodeType = MASTER;
            break;
        }
    }
    // start to parse kubernetes annotation
    Map<String, String> annots = node.getMetadata().getAnnotations();
    String physnetConfig = annots.get(PHYSNET_CONFIG_KEY);
    String gatewayConfig = annots.get(GATEWAY_CONFIG_KEY);
    String dataIpStr = annots.get(DATA_IP_KEY);
    Set<KubevirtPhyInterface> phys = new HashSet<>();
    String gatewayBridgeName = null;
    try {
        if (physnetConfig != null) {
            JSONArray configJson = new JSONArray(physnetConfig);
            for (int i = 0; i < configJson.length(); i++) {
                JSONObject object = configJson.getJSONObject(i);
                String network = object.getString(NETWORK_KEY);
                String intf = object.getString(INTERFACE_KEY);
                if (network != null && intf != null) {
                    String physBridgeId;
                    if (object.has(PHYS_BRIDGE_ID)) {
                        physBridgeId = object.getString(PHYS_BRIDGE_ID);
                    } else {
                        physBridgeId = genDpidFromName(network + intf + hostname);
                        log.trace("host {} physnet dpid for network {} intf {} is null so generate dpid {}", hostname, network, intf, physBridgeId);
                    }
                    phys.add(DefaultKubevirtPhyInterface.builder().network(network).intf(intf).physBridge(DeviceId.deviceId(physBridgeId)).build());
                }
            }
        }
        if (dataIpStr != null) {
            dataIp = IpAddress.valueOf(dataIpStr);
        }
        if (gatewayConfig != null) {
            JsonNode jsonNode = new ObjectMapper().readTree(gatewayConfig);
            nodeType = GATEWAY;
            gatewayBridgeName = jsonNode.get(GATEWAY_BRIDGE_NAME).asText();
        }
    } catch (JSONException | JsonProcessingException e) {
        log.error("Failed to parse physnet config or gateway config object", e);
    }
    // if the node is taint with kubevirt.io key configured,
    // we mark this node as OTHER type, and do not add it into the cluster
    NodeSpec spec = node.getSpec();
    if (spec.getTaints() != null) {
        for (Taint taint : spec.getTaints()) {
            String effect = taint.getEffect();
            String key = taint.getKey();
            String value = taint.getValue();
            if (StringUtils.equals(effect, NO_SCHEDULE_EFFECT) && StringUtils.equals(key, KUBEVIRT_IO_KEY) && StringUtils.equals(value, DRAINING_VALUE)) {
                nodeType = OTHER;
            }
        }
    }
    return DefaultKubevirtNode.builder().hostname(hostname).managementIp(managementIp).dataIp(dataIp).type(nodeType).state(KubevirtNodeState.ON_BOARDED).phyIntfs(phys).gatewayBridgeName(gatewayBridgeName).build();
}
Also used : Address(org.xbill.DNS.Address) StringUtils(org.apache.commons.lang.StringUtils) OvsdbNodeId(org.onosproject.ovsdb.controller.OvsdbNodeId) GATEWAY(org.onosproject.kubevirtnode.api.KubevirtNode.Type.GATEWAY) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) DefaultKubevirtNode(org.onosproject.kubevirtnode.api.DefaultKubevirtNode) KubevirtApiConfig(org.onosproject.kubevirtnode.api.KubevirtApiConfig) NodeSpec(io.fabric8.kubernetes.api.model.NodeSpec) DefaultKubevirtPhyInterface(org.onosproject.kubevirtnode.api.DefaultKubevirtPhyInterface) InetAddress(java.net.InetAddress) HashSet(java.util.HashSet) Strings(com.google.common.base.Strings) JSONException(org.json.JSONException) WORKER(org.onosproject.kubevirtnode.api.KubevirtNode.Type.WORKER) JSONObject(org.json.JSONObject) OvsdbController(org.onosproject.ovsdb.controller.OvsdbController) OTHER(org.onosproject.kubevirtnode.api.KubevirtNode.Type.OTHER) NodeAddress(io.fabric8.kubernetes.api.model.NodeAddress) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) Node(io.fabric8.kubernetes.api.model.Node) IpAddress(org.onlab.packet.IpAddress) KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) Tools.get(org.onlab.util.Tools.get) Logger(org.slf4j.Logger) Device(org.onosproject.net.Device) Taint(io.fabric8.kubernetes.api.model.Taint) BridgeName(org.onosproject.net.behaviour.BridgeName) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) MASTER(org.onosproject.kubevirtnode.api.KubevirtNode.Type.MASTER) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) KubevirtPhyInterface(org.onosproject.kubevirtnode.api.KubevirtPhyInterface) UnknownHostException(java.net.UnknownHostException) Collectors(java.util.stream.Collectors) List(java.util.List) SONA_PROJECT_DOMAIN(org.onosproject.kubevirtnode.api.Constants.SONA_PROJECT_DOMAIN) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) OvsdbClientService(org.onosproject.ovsdb.controller.OvsdbClientService) ConfigBuilder(io.fabric8.kubernetes.client.ConfigBuilder) KubevirtNodeState(org.onosproject.kubevirtnode.api.KubevirtNodeState) DeviceId(org.onosproject.net.DeviceId) JSONArray(org.json.JSONArray) Dictionary(java.util.Dictionary) BridgeConfig(org.onosproject.net.behaviour.BridgeConfig) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) JsonNode(com.fasterxml.jackson.databind.JsonNode) Taint(io.fabric8.kubernetes.api.model.Taint) Taint(io.fabric8.kubernetes.api.model.Taint) DefaultKubevirtNode(org.onosproject.kubevirtnode.api.DefaultKubevirtNode) KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) JSONObject(org.json.JSONObject) DefaultKubevirtPhyInterface(org.onosproject.kubevirtnode.api.DefaultKubevirtPhyInterface) KubevirtPhyInterface(org.onosproject.kubevirtnode.api.KubevirtPhyInterface) NodeSpec(io.fabric8.kubernetes.api.model.NodeSpec) IpAddress(org.onlab.packet.IpAddress) NodeAddress(io.fabric8.kubernetes.api.model.NodeAddress) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HashSet(java.util.HashSet)

Aggregations

KubevirtNode (org.onosproject.kubevirtnode.api.KubevirtNode)3 GATEWAY (org.onosproject.kubevirtnode.api.KubevirtNode.Type.GATEWAY)3 DeviceService (org.onosproject.net.device.DeviceService)3 Logger (org.slf4j.Logger)3 Dictionary (java.util.Dictionary)2 Set (java.util.Set)2 IpAddress (org.onlab.packet.IpAddress)2 CoreService (org.onosproject.core.CoreService)2 GW_ENTRY_TABLE (org.onosproject.kubevirtnetworking.api.Constants.GW_ENTRY_TABLE)2 WORKER (org.onosproject.kubevirtnode.api.KubevirtNode.Type.WORKER)2 KubevirtNodeService (org.onosproject.kubevirtnode.api.KubevirtNodeService)2 DeviceId (org.onosproject.net.DeviceId)2 FlowRuleService (org.onosproject.net.flow.FlowRuleService)2 TrafficSelector (org.onosproject.net.flow.TrafficSelector)2 Activate (org.osgi.service.component.annotations.Activate)2 Component (org.osgi.service.component.annotations.Component)2 Deactivate (org.osgi.service.component.annotations.Deactivate)2 Reference (org.osgi.service.component.annotations.Reference)2 ReferenceCardinality (org.osgi.service.component.annotations.ReferenceCardinality)2 LoggerFactory.getLogger (org.slf4j.LoggerFactory.getLogger)2