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