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);
}
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;
}
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();
}
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();
}
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;
}
Aggregations