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