Search in sources :

Example 1 with FlowInfo

use of org.onosproject.openstacktelemetry.api.FlowInfo in project onos by opennetworkinglab.

the class DefaultInfluxRecordTest method setUp.

/**
 * Initial setup for this unit test.
 */
@Before
public void setUp() {
    FlowInfo.Builder builder1 = new DefaultFlowInfo.DefaultBuilder();
    FlowInfo.Builder builder2 = new DefaultFlowInfo.DefaultBuilder();
    StatsInfo statsInfo = new DefaultStatsInfo.DefaultBuilder().build();
    FlowInfo info1 = builder1.withFlowType((byte) STATIC_INTEGER_1).withInputInterfaceId(STATIC_INTEGER_1).withOutputInterfaceId(STATIC_INTEGER_1).withDeviceId(DeviceId.deviceId(STATIC_STRING_1)).withSrcIp(IpPrefix.valueOf(IpAddress.valueOf(IP_ADDRESS_1), IP_PREFIX_LENGTH_1)).withDstIp(IpPrefix.valueOf(IpAddress.valueOf(IP_ADDRESS_1), IP_PREFIX_LENGTH_1)).withSrcPort(TpPort.tpPort(PORT_1)).withDstPort(TpPort.tpPort(PORT_1)).withProtocol((byte) STATIC_INTEGER_1).withVlanId(VlanId.vlanId(STATIC_STRING_1)).withSrcMac(MacAddress.valueOf(MAC_ADDRESS_1)).withDstMac(MacAddress.valueOf(MAC_ADDRESS_1)).withStatsInfo(statsInfo).build();
    FlowInfo info2 = builder2.withFlowType((byte) STATIC_INTEGER_2).withInputInterfaceId(STATIC_INTEGER_2).withOutputInterfaceId(STATIC_INTEGER_2).withDeviceId(DeviceId.deviceId(STATIC_STRING_2)).withSrcIp(IpPrefix.valueOf(IpAddress.valueOf(IP_ADDRESS_2), IP_PREFIX_LENGTH_2)).withDstIp(IpPrefix.valueOf(IpAddress.valueOf(IP_ADDRESS_2), IP_PREFIX_LENGTH_2)).withSrcPort(TpPort.tpPort(PORT_2)).withDstPort(TpPort.tpPort(PORT_2)).withProtocol((byte) STATIC_INTEGER_2).withVlanId(VlanId.vlanId(STATIC_STRING_2)).withSrcMac(MacAddress.valueOf(MAC_ADDRESS_2)).withDstMac(MacAddress.valueOf(MAC_ADDRESS_2)).withStatsInfo(statsInfo).build();
    flowInfos1 = ImmutableSet.of(info1);
    flowInfos2 = ImmutableSet.of(info2);
    record1 = new DefaultInfluxRecord(MEASUREMENT_1, flowInfos1);
    sameAsRecord1 = new DefaultInfluxRecord(MEASUREMENT_1, flowInfos1);
    record2 = new DefaultInfluxRecord(MEASUREMENT_2, flowInfos2);
}
Also used : DefaultFlowInfo(org.onosproject.openstacktelemetry.api.DefaultFlowInfo) FlowInfo(org.onosproject.openstacktelemetry.api.FlowInfo) DefaultStatsInfo(org.onosproject.openstacktelemetry.api.DefaultStatsInfo) StatsInfo(org.onosproject.openstacktelemetry.api.StatsInfo) DefaultStatsInfo(org.onosproject.openstacktelemetry.api.DefaultStatsInfo) Before(org.junit.Before)

Example 2 with FlowInfo

use of org.onosproject.openstacktelemetry.api.FlowInfo in project onos by opennetworkinglab.

the class StatsFlowRuleManager method mergeFlowInfo.

/**
 * Merges old FlowInfo.StatsInfo and current FlowInfo.StatsInfo.
 *
 * @param flowInfo current FlowInfo object
 * @param fBuilder Builder for FlowInfo
 * @param sBuilder Builder for StatsInfo
 * @return Merged FlowInfo object
 */
private FlowInfo mergeFlowInfo(FlowInfo flowInfo, FlowInfo.Builder fBuilder, StatsInfo.Builder sBuilder) {
    for (FlowInfo gFlowInfo : gFlowInfoSet) {
        log.debug("Old FlowInfo:\n{}", gFlowInfo.toString());
        if (gFlowInfo.roughEquals(flowInfo)) {
            // Get old StatsInfo object and merge the value to current object.
            StatsInfo oldStatsInfo = gFlowInfo.statsInfo();
            sBuilder.withPrevAccPkts(oldStatsInfo.currAccPkts());
            sBuilder.withPrevAccBytes(oldStatsInfo.currAccBytes());
            FlowInfo newFlowInfo = fBuilder.withStatsInfo(sBuilder.build()).build();
            gFlowInfoSet.remove(gFlowInfo);
            gFlowInfoSet.add(newFlowInfo);
            log.debug("Old FlowInfo found, Merge this {}", newFlowInfo.toString());
            return newFlowInfo;
        }
    }
    // No such record, then build the FlowInfo object and return this object.
    log.debug("No FlowInfo found, add new FlowInfo {}", flowInfo.toString());
    FlowInfo newFlowInfo = fBuilder.withStatsInfo(sBuilder.build()).build();
    gFlowInfoSet.add(newFlowInfo);
    return newFlowInfo;
}
Also used : FlowInfo(org.onosproject.openstacktelemetry.api.FlowInfo) DefaultFlowInfo(org.onosproject.openstacktelemetry.api.DefaultFlowInfo) StatsInfo(org.onosproject.openstacktelemetry.api.StatsInfo) DefaultStatsInfo(org.onosproject.openstacktelemetry.api.DefaultStatsInfo)

Example 3 with FlowInfo

use of org.onosproject.openstacktelemetry.api.FlowInfo in project onos by opennetworkinglab.

the class StatsFlowRuleManager method getOverlayDstPortBasedFlowInfos.

/**
 * Gets a set of flow infos by referring to overlay destination VM port.
 *
 * @return flow infos
 */
private Set<FlowInfo> getOverlayDstPortBasedFlowInfos() {
    Set<FlowInfo> flowInfos = Sets.newConcurrentHashSet();
    Set<PortNumber> instPortNums = instPortService.instancePorts().stream().map(InstancePort::portNumber).collect(Collectors.toSet());
    Set<DeviceId> deviceIds = osNodeService.completeNodes(COMPUTE).stream().map(OpenstackNode::intgBridge).collect(Collectors.toSet());
    deviceIds.forEach(d -> {
        List<PortStatistics> stats = deviceService.getPortStatistics(d).stream().filter(s -> instPortNums.contains(s.portNumber())).collect(Collectors.toList());
        stats.forEach(s -> {
            InstancePort instPort = getInstancePort(d, s.portNumber());
            if (instPort != null) {
                flowInfos.add(buildTxFlowInfoFromInstancePort(instPort, s));
                flowInfos.add(buildRxFlowInfoFromInstancePort(instPort, s));
            }
        });
    });
    return flowInfos;
}
Also used : FlowInfo(org.onosproject.openstacktelemetry.api.FlowInfo) DefaultFlowInfo(org.onosproject.openstacktelemetry.api.DefaultFlowInfo) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) FlowEntry(org.onosproject.net.flow.FlowEntry) DriverService(org.onosproject.net.driver.DriverService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) PROP_MONITOR_OVERLAY_DEFAULT(org.onosproject.openstacktelemetry.impl.OsgiPropertyConstants.PROP_MONITOR_OVERLAY_DEFAULT) FlowRuleService(org.onosproject.net.flow.FlowRuleService) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) PROTOCOL_UDP(org.onlab.packet.IPv4.PROTOCOL_UDP) MastershipService(org.onosproject.mastership.MastershipService) OpenstackTelemetryService(org.onosproject.openstacktelemetry.api.OpenstackTelemetryService) PROP_EGRESS_STATS_DEFAULT(org.onosproject.openstacktelemetry.impl.OsgiPropertyConstants.PROP_EGRESS_STATS_DEFAULT) OpenstackTelemetryUtil.getBooleanProperty(org.onosproject.openstacktelemetry.util.OpenstackTelemetryUtil.getBooleanProperty) OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) StatsInfo(org.onosproject.openstacktelemetry.api.StatsInfo) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) DEFAULT_DATA_POINT_SIZE(org.onosproject.openstacktelemetry.api.Constants.DEFAULT_DATA_POINT_SIZE) DeviceId(org.onosproject.net.DeviceId) IPV4_DST(org.onosproject.net.flow.criteria.Criterion.Type.IPV4_DST) Dictionary(java.util.Dictionary) FlowRuleOperationsContext(org.onosproject.net.flow.FlowRuleOperationsContext) IPV4_SRC(org.onosproject.net.flow.criteria.Criterion.Type.IPV4_SRC) Host(org.onosproject.net.Host) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) DefaultStatsFlowRule(org.onosproject.openstacktelemetry.api.DefaultStatsFlowRule) ComponentContext(org.osgi.service.component.ComponentContext) STAT_FLAT_OUTBOUND_TABLE(org.onosproject.openstacknetworking.api.Constants.STAT_FLAT_OUTBOUND_TABLE) HostService(org.onosproject.net.host.HostService) ArrayList(java.util.ArrayList) VTAP_INBOUND_TABLE(org.onosproject.openstacknetworking.api.Constants.VTAP_INBOUND_TABLE) Component(org.osgi.service.component.annotations.Component) TrafficSelector(org.onosproject.net.flow.TrafficSelector) VXLAN(org.onosproject.openstacktelemetry.api.Constants.VXLAN) PROP_MONITOR_OVERLAY(org.onosproject.openstacktelemetry.impl.OsgiPropertyConstants.PROP_MONITOR_OVERLAY) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Criterion(org.onosproject.net.flow.criteria.Criterion) TCP_SRC(org.onosproject.net.flow.criteria.Criterion.Type.TCP_SRC) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) PROP_REVERSE_PATH_STATS(org.onosproject.openstacktelemetry.impl.OsgiPropertyConstants.PROP_REVERSE_PATH_STATS) PROP_MONITOR_UNDERLAY(org.onosproject.openstacktelemetry.impl.OsgiPropertyConstants.PROP_MONITOR_UNDERLAY) UdpPortCriterion(org.onosproject.net.flow.criteria.UdpPortCriterion) VlanId(org.onlab.packet.VlanId) FlowInfo(org.onosproject.openstacktelemetry.api.FlowInfo) MacAddress(org.onlab.packet.MacAddress) TCP_DST(org.onosproject.net.flow.criteria.Criterion.Type.TCP_DST) ScheduledFuture(java.util.concurrent.ScheduledFuture) CoreService(org.onosproject.core.CoreService) PROP_MONITOR_UNDERLAY_DEFAULT(org.onosproject.openstacktelemetry.impl.OsgiPropertyConstants.PROP_MONITOR_UNDERLAY_DEFAULT) LoggerFactory(org.slf4j.LoggerFactory) IPProtocolCriterion(org.onosproject.net.flow.criteria.IPProtocolCriterion) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) StatsFlowRuleAdminService(org.onosproject.openstacktelemetry.api.StatsFlowRuleAdminService) SharedScheduledExecutors(org.onlab.util.SharedScheduledExecutors) STAT_OUTBOUND_TABLE(org.onosproject.openstacknetworking.api.Constants.STAT_OUTBOUND_TABLE) SWITCH(org.onosproject.net.Device.Type.SWITCH) IP_PROTO(org.onosproject.net.flow.criteria.Criterion.Type.IP_PROTO) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) UDP_SRC(org.onosproject.net.flow.criteria.Criterion.Type.UDP_SRC) Driver(org.onosproject.net.driver.Driver) TYPE_IPV4(org.onlab.packet.Ethernet.TYPE_IPV4) PROP_EGRESS_STATS(org.onosproject.openstacktelemetry.impl.OsgiPropertyConstants.PROP_EGRESS_STATS) Device(org.onosproject.net.Device) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) VTAP_OUTBOUND_TABLE(org.onosproject.openstacknetworking.api.Constants.VTAP_OUTBOUND_TABLE) List(java.util.List) FlowRule(org.onosproject.net.flow.FlowRule) Optional(java.util.Optional) Queue(java.util.Queue) OPENSTACK_TELEMETRY_APP_ID(org.onosproject.openstacktelemetry.api.Constants.OPENSTACK_TELEMETRY_APP_ID) IpPrefix(org.onlab.packet.IpPrefix) DefaultStatsInfo(org.onosproject.openstacktelemetry.api.DefaultStatsInfo) COMPUTE(org.onosproject.openstacknode.api.OpenstackNode.NodeType.COMPUTE) PortStatistics(org.onosproject.net.device.PortStatistics) VTAP_FLAT_OUTBOUND_TABLE(org.onosproject.openstacknetworking.api.Constants.VTAP_FLAT_OUTBOUND_TABLE) VLAN(org.onosproject.openstacktelemetry.api.Constants.VLAN) CONTROLLER(org.onosproject.openstacknode.api.OpenstackNode.NodeType.CONTROLLER) OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) TcpPortCriterion(org.onosproject.net.flow.criteria.TcpPortCriterion) Activate(org.osgi.service.component.annotations.Activate) LinkedList(java.util.LinkedList) PROP_PORT_STATS(org.onosproject.openstacktelemetry.impl.OsgiPropertyConstants.PROP_PORT_STATS) FLAT(org.onosproject.openstacktelemetry.api.Constants.FLAT) IpAddress(org.onlab.packet.IpAddress) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) STAT_INBOUND_TABLE(org.onosproject.openstacknetworking.api.Constants.STAT_INBOUND_TABLE) Logger(org.slf4j.Logger) DefaultFlowInfo(org.onosproject.openstacktelemetry.api.DefaultFlowInfo) PROP_PORT_STATS_DEFAULT(org.onosproject.openstacktelemetry.impl.OsgiPropertyConstants.PROP_PORT_STATS_DEFAULT) Maps(com.google.common.collect.Maps) PROP_REVERSE_PATH_STATS_DEFAULT(org.onosproject.openstacktelemetry.impl.OsgiPropertyConstants.PROP_REVERSE_PATH_STATS_DEFAULT) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) TimeUnit(java.util.concurrent.TimeUnit) StatsFlowRule(org.onosproject.openstacktelemetry.api.StatsFlowRule) Modified(org.osgi.service.component.annotations.Modified) PROTOCOL_TCP(org.onlab.packet.IPv4.PROTOCOL_TCP) UDP_DST(org.onosproject.net.flow.criteria.Criterion.Type.UDP_DST) Reference(org.osgi.service.component.annotations.Reference) InstancePortService(org.onosproject.openstacknetworking.api.InstancePortService) DeviceId(org.onosproject.net.DeviceId) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) PortNumber(org.onosproject.net.PortNumber) PortStatistics(org.onosproject.net.device.PortStatistics)

Example 4 with FlowInfo

use of org.onosproject.openstacktelemetry.api.FlowInfo in project onos by opennetworkinglab.

the class OpenstackTelemetryUtil method flowsToLinks.

/**
 * Converts flow info to link info.
 *
 * @param flowInfos a set of flow infos
 * @return converted link infos
 */
public static Set<LinkInfo> flowsToLinks(Set<FlowInfo> flowInfos) {
    Set<LinkInfo> linkInfos = Sets.newConcurrentHashSet();
    for (FlowInfo flowInfo : flowInfos) {
        if (!ALL_IP_ADDRESSES.equals(flowInfo.srcIp().address().toString()) && ALL_IP_ADDRESSES.equals(flowInfo.dstIp().address().toString())) {
            FlowInfo dstFlowInfo = flowInfos.stream().filter(f -> f.dstIp().address().toString().equals(flowInfo.srcIp().address().toString())).findFirst().orElse(null);
            if (dstFlowInfo == null) {
                continue;
            }
            String linkId = flowInfo.deviceId().toString() + LINK_ID_DELIMITER + flowInfo.inputInterfaceId();
            String srcIp = flowInfo.srcIp().address().toString();
            String dstIp = flowInfo.dstIp().address().toString();
            int srcPort = flowInfo.srcPort() == null ? 0 : flowInfo.srcPort().toInt();
            int dstPort = flowInfo.dstPort() == null ? 0 : flowInfo.dstPort().toInt();
            String protocol = protocolByteToString(flowInfo.protocol());
            long txPacket = flowInfo.statsInfo().currAccPkts();
            long txByte = flowInfo.statsInfo().currAccBytes();
            long txDrop = flowInfo.statsInfo().dropPkts();
            long rxPacket = dstFlowInfo.statsInfo().currAccPkts();
            long rxByte = dstFlowInfo.statsInfo().currAccBytes();
            long rxDrop = dstFlowInfo.statsInfo().dropPkts();
            LinkStatsInfo statsInfo = DefaultLinkStatsInfo.builder().withTxPacket(txPacket).withRxPacket(rxPacket).withTxByte(txByte).withRxByte(rxByte).withTxDrop(txDrop).withRxDrop(rxDrop).withTimestamp(System.currentTimeMillis()).build();
            LinkInfo linkInfo = DefaultLinkInfo.builder().withLinkId(linkId).withSrcIp(srcIp).withDstIp(dstIp).withSrcPort(srcPort).withDstPort(dstPort).withProtocol(protocol).withLinkStats(statsInfo).build();
            linkInfos.add(linkInfo);
        }
    }
    return linkInfos;
}
Also used : FlowInfo(org.onosproject.openstacktelemetry.api.FlowInfo) LinkInfo(org.onosproject.openstacktelemetry.api.LinkInfo) DefaultLinkInfo(org.onosproject.openstacktelemetry.api.DefaultLinkInfo) DefaultLinkStatsInfo(org.onosproject.openstacktelemetry.api.DefaultLinkStatsInfo) LinkStatsInfo(org.onosproject.openstacktelemetry.api.LinkStatsInfo)

Example 5 with FlowInfo

use of org.onosproject.openstacktelemetry.api.FlowInfo in project onos by opennetworkinglab.

the class InfluxDbTelemetryManager method publish.

@Override
public void publish(InfluxRecord<String, Set<FlowInfo>> record) {
    if (producers == null || producers.isEmpty()) {
        log.debug("InfluxDB telemetry service has not been enabled!");
        return;
    }
    if (record.flowInfos().size() == 0) {
        log.debug("No record to publish");
        return;
    }
    log.debug("Publish {} stats records to InfluxDB", record.flowInfos().size());
    producers.forEach((k, v) -> {
        TelemetryConfig config = telemetryConfigService.getConfig(k);
        InfluxDbTelemetryConfig influxDbConfig = fromTelemetryConfig(config);
        String database = influxDbConfig.database();
        String measurement = influxDbConfig.measurement();
        BatchPoints batchPoints = BatchPoints.database(database).build();
        for (FlowInfo flowInfo : record.flowInfos()) {
            Point.Builder pointBuilder = Point.measurement((measurement == null) ? record.measurement() : measurement).tag(FLOW_TYPE, String.valueOf(flowInfo.flowType())).tag(DEVICE_ID, flowInfo.deviceId().toString()).tag(INPUT_INTERFACE_ID, String.valueOf(flowInfo.inputInterfaceId())).tag(OUTPUT_INTERFACE_ID, String.valueOf(flowInfo.outputInterfaceId())).tag(VXLAN_ID, String.valueOf(flowInfo.vxlanId())).tag(SRC_IP, flowInfo.srcIp().toString()).tag(DST_IP, flowInfo.dstIp().toString()).tag(DST_PORT, getTpPort(flowInfo.dstPort())).tag(PROTOCOL, String.valueOf(flowInfo.protocol())).addField(STARTUP_TIME, flowInfo.statsInfo().startupTime()).addField(FST_PKT_ARR_TIME, flowInfo.statsInfo().fstPktArrTime()).addField(LST_PKT_OFFSET, flowInfo.statsInfo().lstPktOffset()).addField(PREV_ACC_BYTES, flowInfo.statsInfo().prevAccBytes()).addField(PREV_ACC_PKTS, flowInfo.statsInfo().prevAccPkts()).addField(CURR_ACC_BYTES, flowInfo.statsInfo().currAccBytes()).addField(CURR_ACC_PKTS, flowInfo.statsInfo().currAccPkts()).addField(ERROR_PKTS, flowInfo.statsInfo().errorPkts()).addField(DROP_PKTS, flowInfo.statsInfo().dropPkts());
            if (flowInfo.vlanId() != null) {
                pointBuilder.tag(VLAN_ID, flowInfo.vlanId().toString());
            }
            if (flowInfo.srcPort() != null) {
                pointBuilder.tag(SRC_PORT, getTpPort(flowInfo.srcPort()));
            }
            if (flowInfo.dstPort() != null) {
                pointBuilder.tag(DST_PORT, getTpPort(flowInfo.dstPort()));
            }
            batchPoints.point(pointBuilder.build());
        }
        v.write(batchPoints);
    });
}
Also used : FlowInfo(org.onosproject.openstacktelemetry.api.FlowInfo) InfluxDbTelemetryConfig(org.onosproject.openstacktelemetry.api.config.InfluxDbTelemetryConfig) BatchPoints(org.influxdb.dto.BatchPoints) Point(org.influxdb.dto.Point) DefaultInfluxDbTelemetryConfig.fromTelemetryConfig(org.onosproject.openstacktelemetry.config.DefaultInfluxDbTelemetryConfig.fromTelemetryConfig) InfluxDbTelemetryConfig(org.onosproject.openstacktelemetry.api.config.InfluxDbTelemetryConfig) TelemetryConfig(org.onosproject.openstacktelemetry.api.config.TelemetryConfig)

Aggregations

FlowInfo (org.onosproject.openstacktelemetry.api.FlowInfo)12 DefaultFlowInfo (org.onosproject.openstacktelemetry.api.DefaultFlowInfo)8 DefaultStatsInfo (org.onosproject.openstacktelemetry.api.DefaultStatsInfo)6 StatsInfo (org.onosproject.openstacktelemetry.api.StatsInfo)6 Device (org.onosproject.net.Device)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 EqualsTester (com.google.common.testing.EqualsTester)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 IpAddress (org.onlab.packet.IpAddress)2 ConnectPoint (org.onosproject.net.ConnectPoint)2 Host (org.onosproject.net.Host)2 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)2 FlowEntry (org.onosproject.net.flow.FlowEntry)2 TrafficSelector (org.onosproject.net.flow.TrafficSelector)2 IPCriterion (org.onosproject.net.flow.criteria.IPCriterion)2 IPProtocolCriterion (org.onosproject.net.flow.criteria.IPProtocolCriterion)2 TcpPortCriterion (org.onosproject.net.flow.criteria.TcpPortCriterion)2 UdpPortCriterion (org.onosproject.net.flow.criteria.UdpPortCriterion)2 Maps (com.google.common.collect.Maps)1