Search in sources :

Example 1 with StatsFlowRule

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.");
}
Also used : StatsFlowRule(org.onosproject.openstacktelemetry.api.StatsFlowRule) DefaultStatsFlowRule(org.onosproject.openstacktelemetry.api.DefaultStatsFlowRule) StatsFlowRuleAdminService(org.onosproject.openstacktelemetry.api.StatsFlowRuleAdminService)

Example 2 with StatsFlowRule

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;
}
Also used : StatsFlowRule(org.onosproject.openstacktelemetry.api.StatsFlowRule) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 3 with StatsFlowRule

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.");
}
Also used : StatsFlowRule(org.onosproject.openstacktelemetry.api.StatsFlowRule) DefaultStatsFlowRule(org.onosproject.openstacktelemetry.api.DefaultStatsFlowRule) StatsFlowRuleAdminService(org.onosproject.openstacktelemetry.api.StatsFlowRuleAdminService)

Example 4 with StatsFlowRule

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);
}
Also used : TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) DefaultStatsFlowRule(org.onosproject.openstacktelemetry.api.DefaultStatsFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) StatsFlowRule(org.onosproject.openstacktelemetry.api.StatsFlowRule) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 5 with StatsFlowRule

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);
    }
}
Also used : DefaultStatsFlowRule(org.onosproject.openstacktelemetry.api.DefaultStatsFlowRule) StatsFlowRule(org.onosproject.openstacktelemetry.api.StatsFlowRule)

Aggregations

StatsFlowRule (org.onosproject.openstacktelemetry.api.StatsFlowRule)5 DefaultStatsFlowRule (org.onosproject.openstacktelemetry.api.DefaultStatsFlowRule)4 StatsFlowRuleAdminService (org.onosproject.openstacktelemetry.api.StatsFlowRuleAdminService)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ConnectPoint (org.onosproject.net.ConnectPoint)1 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)1 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)1 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)1 FlowRule (org.onosproject.net.flow.FlowRule)1 TrafficSelector (org.onosproject.net.flow.TrafficSelector)1 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)1