use of org.onosproject.openstacktelemetry.api.StatsFlowRule in project onos by opennetworkinglab.
the class TelemetryVflowAddCommand method doExecute.
@Override
protected void doExecute() {
StatsFlowRuleAdminService statsService = get(StatsFlowRuleAdminService.class);
StatsFlowRule statsFlowRule = DefaultStatsFlowRule.builder().srcIpPrefix(IpPrefix.valueOf(srcIp)).dstIpPrefix(IpPrefix.valueOf(dstIp)).srcTpPort(TpPort.tpPort(Integer.valueOf(srcTpPort))).dstTpPort(TpPort.tpPort(Integer.valueOf(dstTpPort))).ipProtocol(getProtocolTypeFromString(ipProto)).build();
statsService.createStatFlowRule(statsFlowRule);
print("Added the stat flow rule.");
}
use of org.onosproject.openstacktelemetry.api.StatsFlowRule in project onos by opennetworkinglab.
the class OpenstackTelemetryWebResource method readNodeConfiguration.
private Set<StatsFlowRule> readNodeConfiguration(InputStream input) {
log.info("Input JSON Data: \n\t\t{}", input.toString());
Set<StatsFlowRule> flowRuleSet = Sets.newHashSet();
try {
JsonNode jsonTree = readTreeFromStream(mapper().enable(INDENT_OUTPUT), input);
ArrayNode nodes = (ArrayNode) jsonTree.path(JSON_NODE_FLOW_RULE);
nodes.forEach(node -> {
try {
ObjectNode objectNode = node.deepCopy();
log.debug("ObjectNode: {}", objectNode.toString());
StatsFlowRule statsFlowRule = codec(StatsFlowRule.class).decode(objectNode, this);
log.debug("StatsFlowRule: {}", statsFlowRule.toString());
flowRuleSet.add(statsFlowRule);
} catch (Exception ex) {
log.error("Exception Stack:\n{}", ExceptionUtils.getStackTrace(ex));
throw new IllegalArgumentException();
}
});
} catch (Exception ex) {
log.error("Exception Stack:\n{}", ExceptionUtils.getStackTrace(ex));
throw new IllegalArgumentException(ex);
}
return flowRuleSet;
}
use of org.onosproject.openstacktelemetry.api.StatsFlowRule in project onos by opennetworkinglab.
the class TelemetryVflowDeleteCommand method doExecute.
@Override
protected void doExecute() {
StatsFlowRuleAdminService statsService = get(StatsFlowRuleAdminService.class);
StatsFlowRule statsFlowRule = DefaultStatsFlowRule.builder().srcIpPrefix(IpPrefix.valueOf(srcIp)).dstIpPrefix(IpPrefix.valueOf(dstIp)).srcTpPort(TpPort.tpPort(Integer.valueOf(srcTpPort))).dstTpPort(TpPort.tpPort(Integer.valueOf(dstTpPort))).ipProtocol(getProtocolTypeFromString(ipProto)).build();
statsService.deleteStatFlowRule(statsFlowRule);
print("Removed the stat flow rule.");
}
use of org.onosproject.openstacktelemetry.api.StatsFlowRule in project onos by opennetworkinglab.
the class StatsFlowRuleManager method connectTables.
/**
* Installs a flow rule where the source table is fromTable, while destination
* table is toTable.
*
* @param deviceId device identifier
* @param fromTable source table
* @param toTable destination table
* @param statsFlowRule stats flow rule
* @param rulePriority rule priority
* @param install installation flag
*/
private void connectTables(DeviceId deviceId, int fromTable, int toTable, StatsFlowRule statsFlowRule, int rulePriority, boolean install) {
int srcPrefixLength = statsFlowRule.srcIpPrefix().prefixLength();
int dstPrefixLength = statsFlowRule.dstIpPrefix().prefixLength();
int prefixLength = rulePriority + srcPrefixLength + dstPrefixLength;
byte protocol = statsFlowRule.ipProtocol();
TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder().matchEthType(TYPE_IPV4).matchIPSrc(statsFlowRule.srcIpPrefix()).matchIPDst(statsFlowRule.dstIpPrefix());
if (protocol == PROTOCOL_TCP) {
selectorBuilder = selectorBuilder.matchIPProtocol(statsFlowRule.ipProtocol()).matchTcpSrc(statsFlowRule.srcTpPort()).matchTcpDst(statsFlowRule.dstTpPort());
} else if (protocol == PROTOCOL_UDP) {
selectorBuilder = selectorBuilder.matchIPProtocol(statsFlowRule.ipProtocol()).matchUdpSrc(statsFlowRule.srcTpPort()).matchUdpDst(statsFlowRule.dstTpPort());
} else if (protocol == ARBITRARY_PROTOCOL) {
log.debug("IP protocol type is not specified.");
} else {
log.warn("Unsupported protocol {}", statsFlowRule.ipProtocol());
}
TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
treatmentBuilder.transition(toTable);
FlowRule flowRule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(selectorBuilder.build()).withTreatment(treatmentBuilder.build()).withPriority(prefixLength).fromApp(telemetryAppId).makePermanent().forTable(fromTable).build();
applyRule(flowRule, install);
}
use of org.onosproject.openstacktelemetry.api.StatsFlowRule in project onos by opennetworkinglab.
the class StatsFlowRuleManager method setStatFlowRule.
/**
* Installs flow rules for collecting both normal and reverse path flow stats.
*
* @param statsFlowRule flow rule used for collecting stats
* @param install flow rule installation flag
*/
private void setStatFlowRule(StatsFlowRule statsFlowRule, boolean install) {
setStatFlowRuleBase(statsFlowRule, install);
// collecting reverse path vFlow stats
if (reversePathStats) {
StatsFlowRule reverseFlowRule = DefaultStatsFlowRule.builder().srcIpPrefix(statsFlowRule.dstIpPrefix()).dstIpPrefix(statsFlowRule.srcIpPrefix()).ipProtocol(statsFlowRule.ipProtocol()).srcTpPort(statsFlowRule.dstTpPort()).dstTpPort(statsFlowRule.srcTpPort()).build();
setStatFlowRuleBase(reverseFlowRule, install);
}
}
Aggregations