Search in sources :

Example 1 with StatsInfo

use of org.onosproject.openstacktelemetry.api.StatsInfo 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 StatsInfo

use of org.onosproject.openstacktelemetry.api.StatsInfo 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 StatsInfo

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

the class TinaFlowInfoByteBufferCodecTest method setup.

/**
 * Initial setup for this unit test.
 */
@Before
public void setup() {
    StatsInfo statsInfo = new DefaultStatsInfo.DefaultBuilder().build();
    FlowInfo.Builder builder = new DefaultFlowInfo.DefaultBuilder();
    info = builder.withFlowType(FLOW_TYPE).withDeviceId(DEVICE_ID).withInputInterfaceId(INPUT_INTERFACE_ID).withOutputInterfaceId(OUTPUT_INTERFACE_ID).withVlanId(VLAN_ID).withSrcIp(SRC_IP_PREFIX).withDstIp(DST_IP_PREFIX).withSrcPort(SRC_PORT_NUMBER).withDstPort(DST_PORT_NUMBER).withProtocol(PROTOCOL).withSrcMac(SRC_MAC_ADDRESS).withDstMac(DST_MAC_ADDRESS).withStatsInfo(statsInfo).build();
}
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 4 with StatsInfo

use of org.onosproject.openstacktelemetry.api.StatsInfo 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 5 with StatsInfo

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

the class FlowInfoJsonMatcher method matchesSafely.

@Override
protected boolean matchesSafely(JsonNode jsonNode, Description description) {
    // check flow type
    String jsonFlowType = jsonNode.get(FLOW_TYPE).asText();
    String flowType = String.valueOf(flowInfo.flowType());
    if (!jsonFlowType.equals(flowType)) {
        description.appendText("flow type was " + jsonFlowType);
        return false;
    }
    // check device id
    String jsonDeviceId = jsonNode.get(DEVICE_ID).asText();
    String deviceId = flowInfo.deviceId().toString();
    if (!jsonDeviceId.equals(deviceId)) {
        description.appendText("device id was " + jsonDeviceId);
        return false;
    }
    // check input interface id
    int jsonInputInterfaceId = jsonNode.get(INPUT_INTERFACE_ID).asInt();
    int inputInterfaceId = flowInfo.inputInterfaceId();
    if (jsonInputInterfaceId != inputInterfaceId) {
        description.appendText("input interface id was " + jsonInputInterfaceId);
        return false;
    }
    // check output interface id
    int jsonOutputInterfaceId = jsonNode.get(OUTPUT_INTERFACE_ID).asInt();
    int outputInterfaceId = flowInfo.outputInterfaceId();
    if (jsonOutputInterfaceId != outputInterfaceId) {
        description.appendText("output interface id was " + jsonInputInterfaceId);
        return false;
    }
    // check vlan id
    try {
        if (!(jsonNode.get(VLAN_ID).isNull())) {
            String jsonVlanId = jsonNode.get(VLAN_ID).asText();
            String vlanId = flowInfo.vlanId().toString();
            if (!jsonVlanId.equals(vlanId)) {
                description.appendText("VLAN id was " + jsonVlanId);
                return false;
            }
        }
    } catch (NullPointerException ex) {
        description.appendText("VLAN id was null");
    }
    // check source IP
    String jsonSrcIp = jsonNode.get(SRC_IP).asText();
    String srcIp = flowInfo.srcIp().address().toString();
    if (!jsonSrcIp.equals(srcIp)) {
        description.appendText("Source IP was " + jsonSrcIp);
        return false;
    }
    // check destination IP
    String jsonDstIp = jsonNode.get(DST_IP).asText();
    String dstIp = flowInfo.dstIp().address().toString();
    if (!jsonDstIp.equals(dstIp)) {
        description.appendText("Destination IP was " + jsonDstIp);
        return false;
    }
    // check source IP prefix length
    int jsonSrcPrefixLength = jsonNode.get(SRC_IP_PREFIX_LEN).asInt();
    int srcPrefixLength = flowInfo.srcIp().prefixLength();
    if (jsonSrcPrefixLength != srcPrefixLength) {
        description.appendText("Source IP prefix length was " + jsonSrcPrefixLength);
        return false;
    }
    // check destination IP prefix length
    int jsonDstPrefixLength = jsonNode.get(DST_IP_PREFIX_LEN).asInt();
    int dstPrefixLength = flowInfo.dstIp().prefixLength();
    if (jsonDstPrefixLength != dstPrefixLength) {
        description.appendText("Destination IP prefix length was " + jsonDstPrefixLength);
        return false;
    }
    // check source port
    int jsonSrcPort = jsonNode.get(SRC_PORT).asInt();
    int srcPort = flowInfo.srcPort().toInt();
    if (jsonSrcPort != srcPort) {
        description.appendText("Source port was " + jsonSrcPort);
        return false;
    }
    // check destination port
    int jsonDstPort = jsonNode.get(DST_PORT).asInt();
    int dstPort = flowInfo.dstPort().toInt();
    if (jsonDstPort != dstPort) {
        description.appendText("Destination port was " + jsonDstPort);
        return false;
    }
    // check protocol
    String jsonProtocol = jsonNode.get(PROTOCOL).asText();
    String protocol = String.valueOf(flowInfo.protocol());
    if (!jsonProtocol.equals(protocol)) {
        description.appendText("Protocol was " + jsonProtocol);
        return false;
    }
    // check source mac
    String jsonSrcMac = jsonNode.get(SRC_MAC).asText();
    String srcMac = flowInfo.srcMac().toString();
    if (!jsonSrcMac.equals(srcMac)) {
        description.appendText("Source MAC was " + jsonSrcMac);
        return false;
    }
    // check destination mac
    String jsonDstMac = jsonNode.get(DST_MAC).asText();
    String dstMac = flowInfo.dstMac().toString();
    if (!jsonDstMac.equals(dstMac)) {
        description.appendText("Destination MAC was " + jsonDstMac);
        return false;
    }
    // check stats info
    JsonNode jsonStatsInfo = jsonNode.get(STATS_INFO);
    if (jsonStatsInfo != null) {
        StatsInfo statsInfo = flowInfo.statsInfo();
        StatsInfoJsonMatcher infoMatcher = StatsInfoJsonMatcher.matchStatsInfo(statsInfo);
        return infoMatcher.matches(jsonStatsInfo);
    }
    return true;
}
Also used : StatsInfo(org.onosproject.openstacktelemetry.api.StatsInfo) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

StatsInfo (org.onosproject.openstacktelemetry.api.StatsInfo)7 DefaultFlowInfo (org.onosproject.openstacktelemetry.api.DefaultFlowInfo)5 DefaultStatsInfo (org.onosproject.openstacktelemetry.api.DefaultStatsInfo)5 FlowInfo (org.onosproject.openstacktelemetry.api.FlowInfo)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 EqualsTester (com.google.common.testing.EqualsTester)2 Before (org.junit.Before)2 Test (org.junit.Test)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ByteBuffer (java.nio.ByteBuffer)1 VlanId (org.onlab.packet.VlanId)1 FlowInfoJsonMatcher.matchesFlowInfo (org.onosproject.openstacktelemetry.codec.rest.FlowInfoJsonMatcher.matchesFlowInfo)1