Search in sources :

Example 1 with PRIORITY_STATEFUL_SNAT_RULE

use of org.onosproject.kubevirtnetworking.api.Constants.PRIORITY_STATEFUL_SNAT_RULE 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)

Aggregations

Gauge (io.prometheus.client.Gauge)1 MetricsServlet (io.prometheus.client.exporter.MetricsServlet)1 ScheduledFuture (java.util.concurrent.ScheduledFuture)1 TimeUnit (java.util.concurrent.TimeUnit)1 Server (org.eclipse.jetty.server.Server)1 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)1 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)1 IpAddress (org.onlab.packet.IpAddress)1 MacAddress (org.onlab.packet.MacAddress)1 SharedScheduledExecutors (org.onlab.util.SharedScheduledExecutors)1 CoreService (org.onosproject.core.CoreService)1 GW_ENTRY_TABLE (org.onosproject.kubevirtnetworking.api.Constants.GW_ENTRY_TABLE)1 PRIORITY_FLOATING_IP_DOWNSTREAM_RULE (org.onosproject.kubevirtnetworking.api.Constants.PRIORITY_FLOATING_IP_DOWNSTREAM_RULE)1 PRIORITY_FLOATING_IP_UPSTREAM_RULE (org.onosproject.kubevirtnetworking.api.Constants.PRIORITY_FLOATING_IP_UPSTREAM_RULE)1 PRIORITY_STATEFUL_SNAT_RULE (org.onosproject.kubevirtnetworking.api.Constants.PRIORITY_STATEFUL_SNAT_RULE)1 KubevirtFloatingIp (org.onosproject.kubevirtnetworking.api.KubevirtFloatingIp)1 KubevirtPort (org.onosproject.kubevirtnetworking.api.KubevirtPort)1 KubevirtPortService (org.onosproject.kubevirtnetworking.api.KubevirtPortService)1 KubevirtPrometheusAssuranceService (org.onosproject.kubevirtnetworking.api.KubevirtPrometheusAssuranceService)1 KubevirtRouter (org.onosproject.kubevirtnetworking.api.KubevirtRouter)1