Search in sources :

Example 6 with FlowInfo

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

the class FlowInfoJsonCodecTest method testEncode.

/**
 * Tests the flow info encoding.
 */
@Test
public void testEncode() {
    StatsInfo statsInfo = new DefaultStatsInfo.DefaultBuilder().withStartupTime(LONG_VALUE).withFstPktArrTime(LONG_VALUE).withLstPktOffset(INTEGER_VALUE).withPrevAccBytes(LONG_VALUE).withPrevAccPkts(INTEGER_VALUE).withCurrAccBytes(LONG_VALUE).withCurrAccPkts(INTEGER_VALUE).withErrorPkts(SHORT_VALUE).withDropPkts(SHORT_VALUE).build();
    FlowInfo flowInfo = new DefaultFlowInfo.DefaultBuilder().withFlowType((byte) FLOW_TYPE).withDeviceId(DeviceId.deviceId(DEVICE_ID)).withInputInterfaceId(INPUT_INTERFACE_ID).withOutputInterfaceId(OUTPUT_INTERFACE_ID).withVlanId(VlanId.vlanId((short) VLAN_ID)).withSrcIp(IpPrefix.valueOf(IpAddress.valueOf(SRC_IP_ADDRESS), SRC_IP_PREFIX)).withDstIp(IpPrefix.valueOf(IpAddress.valueOf(DST_IP_ADDRESS), DST_IP_PREFIX)).withSrcPort(TpPort.tpPort(SRC_PORT)).withDstPort(TpPort.tpPort(DST_PORT)).withProtocol((byte) PROTOCOL).withSrcMac(MacAddress.valueOf(SRC_MAC_ADDRESS)).withDstMac(MacAddress.valueOf(DST_MAC_ADDRESS)).withStatsInfo(statsInfo).build();
    ObjectNode nodeJson = flowInfoCodec.encode(flowInfo, context);
    assertThat(nodeJson, matchesFlowInfo(flowInfo));
    FlowInfo flowInfoDecoded = flowInfoCodec.decode(nodeJson, context);
    new EqualsTester().addEqualityGroup(flowInfo, flowInfoDecoded).testEquals();
}
Also used : DefaultFlowInfo(org.onosproject.openstacktelemetry.api.DefaultFlowInfo) FlowInfo(org.onosproject.openstacktelemetry.api.FlowInfo) FlowInfoJsonMatcher.matchesFlowInfo(org.onosproject.openstacktelemetry.codec.rest.FlowInfoJsonMatcher.matchesFlowInfo) DefaultStatsInfo(org.onosproject.openstacktelemetry.api.DefaultStatsInfo) StatsInfo(org.onosproject.openstacktelemetry.api.StatsInfo) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) EqualsTester(com.google.common.testing.EqualsTester) Test(org.junit.Test)

Example 7 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 8 with FlowInfo

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

the class StatsFlowRuleManager method getOverlayFlowInfos.

@Override
public Set<FlowInfo> getOverlayFlowInfos() {
    Set<FlowInfo> flowInfos = Sets.newConcurrentHashSet();
    // obtain all flow rule entries installed by telemetry app
    for (FlowEntry entry : flowRuleService.getFlowEntriesById(telemetryAppId)) {
        FlowInfo.Builder fBuilder = new DefaultFlowInfo.DefaultBuilder();
        TrafficSelector selector = entry.selector();
        IPCriterion srcIp = (IPCriterion) selector.getCriterion(IPV4_SRC);
        IPCriterion dstIp = (IPCriterion) selector.getCriterion(IPV4_DST);
        IPProtocolCriterion ipProtocol = (IPProtocolCriterion) selector.getCriterion(IP_PROTO);
        fBuilder.withFlowType(FLOW_TYPE_SONA).withSrcIp(srcIp.ip()).withDstIp(dstIp.ip());
        if (ipProtocol != null) {
            fBuilder.withProtocol((byte) ipProtocol.protocol());
            if (ipProtocol.protocol() == PROTOCOL_TCP) {
                TcpPortCriterion tcpSrc = (TcpPortCriterion) selector.getCriterion(TCP_SRC);
                TcpPortCriterion tcpDst = (TcpPortCriterion) selector.getCriterion(TCP_DST);
                fBuilder.withSrcPort(tcpSrc.tcpPort());
                fBuilder.withDstPort(tcpDst.tcpPort());
            } else if (ipProtocol.protocol() == PROTOCOL_UDP) {
                UdpPortCriterion udpSrc = (UdpPortCriterion) selector.getCriterion(UDP_SRC);
                UdpPortCriterion udpDst = (UdpPortCriterion) selector.getCriterion(UDP_DST);
                fBuilder.withSrcPort(udpSrc.udpPort());
                fBuilder.withDstPort(udpDst.udpPort());
            } else {
                log.debug("Other protocol: {}", ipProtocol.protocol());
            }
        }
        fBuilder.withSrcMac(getMacAddress(srcIp.ip().address())).withDstMac(getMacAddress(dstIp.ip().address())).withInputInterfaceId(getInterfaceId(srcIp.ip().address())).withOutputInterfaceId(getInterfaceId(dstIp.ip().address())).withVlanId(getVlanId(srcIp.ip().address())).withDeviceId(entry.deviceId());
        StatsInfo.Builder sBuilder = new DefaultStatsInfo.DefaultBuilder();
        sBuilder.withStartupTime(System.currentTimeMillis()).withFstPktArrTime(System.currentTimeMillis()).withLstPktOffset((int) (REFRESH_INTERVAL * MILLISECONDS)).withCurrAccPkts((int) entry.packets()).withCurrAccBytes(entry.bytes()).withErrorPkts((short) 0).withDropPkts((short) 0);
        fBuilder.withStatsInfo(sBuilder.build());
        FlowInfo flowInfo = mergeFlowInfo(fBuilder.build(), fBuilder, sBuilder);
        flowInfos.add(flowInfo);
        log.debug("FlowInfo: \n{}", flowInfo.toString());
    }
    return flowInfos;
}
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) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) TcpPortCriterion(org.onosproject.net.flow.criteria.TcpPortCriterion) IPProtocolCriterion(org.onosproject.net.flow.criteria.IPProtocolCriterion) UdpPortCriterion(org.onosproject.net.flow.criteria.UdpPortCriterion) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) FlowEntry(org.onosproject.net.flow.FlowEntry)

Example 9 with FlowInfo

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

the class StatsFlowRuleManager method getUnderlayFlowInfos.

@Override
public Set<FlowInfo> getUnderlayFlowInfos() {
    Set<FlowInfo> flowInfos = Sets.newConcurrentHashSet();
    for (Device device : getUnderlayDevices()) {
        if (!isEdgeSwitch(device.id())) {
            continue;
        }
        for (FlowEntry entry : flowRuleService.getFlowEntries(device.id())) {
            FlowInfo.Builder fBuilder = new DefaultFlowInfo.DefaultBuilder();
            TrafficSelector selector = entry.selector();
            Criterion inPort = selector.getCriterion(Criterion.Type.IN_PORT);
            Criterion dstIpCriterion = selector.getCriterion(Criterion.Type.IPV4_DST);
            if (inPort != null && dstIpCriterion != null) {
                IpAddress srcIp = getIpAddress(device, (PortCriterion) inPort);
                IpAddress dstIp = ((IPCriterion) dstIpCriterion).ip().address();
                if (srcIp == null) {
                    continue;
                }
                fBuilder.withFlowType(FLOW_TYPE_SONA).withSrcIp(IpPrefix.valueOf(srcIp, ARBITRARY_LENGTH)).withDstIp(IpPrefix.valueOf(dstIp, ARBITRARY_LENGTH)).withSrcMac(getMacAddress(srcIp)).withDstMac(getMacAddress(dstIp)).withInputInterfaceId(getInterfaceId(srcIp)).withOutputInterfaceId(getInterfaceId(dstIp)).withDeviceId(entry.deviceId());
                StatsInfo.Builder sBuilder = new DefaultStatsInfo.DefaultBuilder();
                sBuilder.withStartupTime(System.currentTimeMillis()).withFstPktArrTime(System.currentTimeMillis()).withLstPktOffset((int) (REFRESH_INTERVAL * MILLISECONDS)).withCurrAccPkts((int) entry.packets()).withCurrAccBytes(entry.bytes()).withErrorPkts((short) 0).withDropPkts((short) 0);
                fBuilder.withStatsInfo(sBuilder.build());
                FlowInfo flowInfo = mergeFlowInfo(fBuilder.build(), fBuilder, sBuilder);
                flowInfos.add(flowInfo);
            }
        }
    }
    return flowInfos;
}
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) Criterion(org.onosproject.net.flow.criteria.Criterion) UdpPortCriterion(org.onosproject.net.flow.criteria.UdpPortCriterion) IPProtocolCriterion(org.onosproject.net.flow.criteria.IPProtocolCriterion) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) TcpPortCriterion(org.onosproject.net.flow.criteria.TcpPortCriterion) Device(org.onosproject.net.Device) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) IpAddress(org.onlab.packet.IpAddress) FlowEntry(org.onosproject.net.flow.FlowEntry)

Example 10 with FlowInfo

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

the class StatsFlowRuleManager method getUnderlayDstPortBasedFlowInfos.

/**
 * Gets a set of flow infos by referring to underlay destination port.
 *
 * @return flow infos
 */
private Set<FlowInfo> getUnderlayDstPortBasedFlowInfos() {
    Set<FlowInfo> flowInfos = Sets.newConcurrentHashSet();
    for (Device d : getUnderlayDevices()) {
        List<PortStatistics> stats = new ArrayList<>(deviceService.getPortStatistics(d.id()));
        stats.forEach(s -> {
            Host host = hostService.getConnectedHosts(new ConnectPoint(d.id(), s.portNumber())).stream().findFirst().orElse(null);
            if (host != null) {
                flowInfos.add(buildTxFlowInfoFromHost(host, s));
                flowInfos.add(buildRxFlowInfoFromHost(host, s));
            }
        });
    }
    return flowInfos;
}
Also used : FlowInfo(org.onosproject.openstacktelemetry.api.FlowInfo) DefaultFlowInfo(org.onosproject.openstacktelemetry.api.DefaultFlowInfo) Device(org.onosproject.net.Device) ArrayList(java.util.ArrayList) Host(org.onosproject.net.Host) ConnectPoint(org.onosproject.net.ConnectPoint) PortStatistics(org.onosproject.net.device.PortStatistics)

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