Search in sources :

Example 1 with FlowCookie

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie in project netvirt by opendaylight.

the class AclLiveStatisticsHelper method getAclPortStats.

/**
 * Gets the acl port stats.
 *
 * @param direction the direction
 * @param interfaceNames the interface names
 * @param odlDirectStatsService the odl direct stats service
 * @param dataBroker the data broker
 * @return the acl port stats
 */
public static List<AclPortStats> getAclPortStats(Direction direction, List<String> interfaceNames, OpendaylightDirectStatisticsService odlDirectStatsService, DataBroker dataBroker) {
    LOG.trace("Get ACL port stats for direction {} and interfaces {}", direction, interfaceNames);
    List<AclPortStats> lstAclPortStats = new ArrayList<>();
    Short tableId = getTableId(direction);
    FlowCookie aclDropFlowCookie = new FlowCookie(AclConstants.COOKIE_ACL_DROP_FLOW);
    FlowCookie aclDropFlowCookieMask = new FlowCookie(COOKIE_ACL_DROP_FLOW_MASK);
    for (String interfaceName : interfaceNames) {
        AclPortStatsBuilder aclStatsBuilder = new AclPortStatsBuilder().setInterfaceName(interfaceName);
        Interface interfaceState = AclServiceUtils.getInterfaceStateFromOperDS(dataBroker, interfaceName);
        if (interfaceState == null) {
            String errMsg = "Interface not found in datastore.";
            addError(lstAclPortStats, aclStatsBuilder, errMsg);
            continue;
        }
        BigInteger dpId = AclServiceUtils.getDpIdFromIterfaceState(interfaceState);
        if (dpId == null) {
            String errMsg = "Failed to find device for the interface.";
            addError(lstAclPortStats, aclStatsBuilder, errMsg);
            continue;
        }
        NodeRef nodeRef = buildNodeRef(dpId);
        Integer lportTag = interfaceState.getIfIndex();
        Match metadataMatch = buildMetadataMatch(lportTag);
        GetFlowStatisticsInputBuilder input = new GetFlowStatisticsInputBuilder().setNode(nodeRef).setCookie(aclDropFlowCookie).setCookieMask(aclDropFlowCookieMask).setMatch(metadataMatch).setStoreStats(false);
        if (direction != Direction.Both) {
            input.setTableId(tableId);
        }
        Future<RpcResult<GetFlowStatisticsOutput>> rpcResultFuture = odlDirectStatsService.getFlowStatistics(input.build());
        RpcResult<GetFlowStatisticsOutput> rpcResult = null;
        try {
            rpcResult = rpcResultFuture.get();
        } catch (InterruptedException | ExecutionException e) {
            String errMsg = "Unable to retrieve drop counts due to error: " + e.getMessage();
            addError(lstAclPortStats, aclStatsBuilder, errMsg);
            LOG.error("Exception occurred during get flow statistics for interface {}", interfaceName, e);
        }
        if (rpcResult != null && rpcResult.isSuccessful() && rpcResult.getResult() != null) {
            GetFlowStatisticsOutput flowStatsOutput = rpcResult.getResult();
            getAclDropStats(direction, aclStatsBuilder, flowStatsOutput);
            lstAclPortStats.add(aclStatsBuilder.build());
        } else {
            handleRpcErrors(lstAclPortStats, aclStatsBuilder, rpcResult);
        }
    }
    return lstAclPortStats;
}
Also used : AclPortStatsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.acl.stats.output.AclPortStatsBuilder) ArrayList(java.util.ArrayList) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) Match(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match) BigInteger(java.math.BigInteger) NodeRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef) FlowCookie(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie) GetFlowStatisticsInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsInputBuilder) AclPortStats(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.acl.stats.output.AclPortStats) BigInteger(java.math.BigInteger) GetFlowStatisticsOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsOutput) ExecutionException(java.util.concurrent.ExecutionException) Interface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface)

Example 2 with FlowCookie

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie in project openflowplugin by opendaylight.

the class LearningSwitchHandlerSimpleImpl method addBridgeFlow.

private void addBridgeFlow(MacAddress srcMac, MacAddress dstMac, NodeConnectorRef destNodeConnector) {
    synchronized (coveredMacPaths) {
        String macPath = srcMac.toString() + dstMac.toString();
        if (!coveredMacPaths.contains(macPath)) {
            LOG.debug("covering mac path: {} by [{}]", macPath, destNodeConnector.getValue().firstKeyOf(NodeConnector.class, NodeConnectorKey.class).getId());
            coveredMacPaths.add(macPath);
            FlowId flowId = new FlowId(String.valueOf(flowIdInc.getAndIncrement()));
            FlowKey flowKey = new FlowKey(flowId);
            /**
             * Path to the flow we want to program.
             */
            InstanceIdentifier<Flow> flowPath = InstanceIdentifierUtils.createFlowPath(tablePath, flowKey);
            Short tableId = InstanceIdentifierUtils.getTableId(tablePath);
            FlowBuilder srcToDstFlow = FlowUtils.createDirectMacToMacFlow(tableId, DIRECT_FLOW_PRIORITY, srcMac, dstMac, destNodeConnector);
            srcToDstFlow.setCookie(new FlowCookie(BigInteger.valueOf(flowCookieInc.getAndIncrement())));
            dataStoreAccessor.writeFlowToConfig(flowPath, srcToDstFlow.build());
        }
    }
}
Also used : FlowId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId) FlowKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey) FlowCookie(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie) FlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)

Example 3 with FlowCookie

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie in project openflowplugin by opendaylight.

the class Activator method createFlow.

private static Flow createFlow(String flowId, long groupId, int priority, short tableId) {
    MatchBuilder matchBuilder = new MatchBuilder();
    matchBuilder.setEthernetMatch(new EthernetMatchBuilder().setEthernetType(new EthernetTypeBuilder().setType(new EtherType(2048L)).build()).build());
    FlowBuilder flowBuilder = new FlowBuilder();
    flowBuilder.setMatch(matchBuilder.build());
    flowBuilder.setInstructions(createGroupInstructions(groupId).build());
    flowBuilder.setPriority(priority);
    flowBuilder.setCookie(new FlowCookie(new BigInteger(flowId + "" + priority)));
    FlowKey key = new FlowKey(new FlowId(flowId));
    flowBuilder.setHardTimeout(0);
    flowBuilder.setIdleTimeout(0);
    flowBuilder.setStrict(false);
    flowBuilder.setContainerName(null);
    flowBuilder.setId(new FlowId(flowId));
    flowBuilder.setTableId(tableId);
    flowBuilder.setKey(key);
    flowBuilder.setFlowName("FlowWithGroupInstruction");
    return flowBuilder.build();
}
Also used : FlowId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId) FlowCookie(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie) FlowKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey) FlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder) EthernetTypeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder) BigInteger(java.math.BigInteger) EtherType(org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType) EthernetMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder) Ipv4MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder) EthernetMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder)

Example 4 with FlowCookie

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie in project openflowplugin by opendaylight.

the class FlowStatsResponseConvertor method convert.

@Override
public List<FlowAndStatisticsMapList> convert(List<FlowStats> source, FlowStatsResponseConvertorData data) {
    final List<FlowAndStatisticsMapList> result = new ArrayList<>();
    for (FlowStats flowStats : source) {
        // Convert Openflow switch specific flow statistics to the MD-SAL format flow statistics
        FlowAndStatisticsMapListBuilder salFlowStatsBuilder = new FlowAndStatisticsMapListBuilder();
        salFlowStatsBuilder.setByteCount(new Counter64(flowStats.getByteCount()));
        if (flowStats.getCookie() != null) {
            salFlowStatsBuilder.setCookie(new FlowCookie(flowStats.getCookie()));
        }
        DurationBuilder time = new DurationBuilder();
        time.setSecond(new Counter32(flowStats.getDurationSec()));
        time.setNanosecond(new Counter32(flowStats.getDurationNsec()));
        salFlowStatsBuilder.setDuration(time.build());
        salFlowStatsBuilder.setHardTimeout(flowStats.getHardTimeout());
        salFlowStatsBuilder.setIdleTimeout(flowStats.getIdleTimeout());
        salFlowStatsBuilder.setPacketCount(new Counter64(flowStats.getPacketCount()));
        salFlowStatsBuilder.setPriority(flowStats.getPriority());
        salFlowStatsBuilder.setTableId(flowStats.getTableId());
        Short ipProtocol = null;
        if (flowStats.getMatchV10() != null) {
            final Optional<MatchBuilder> matchBuilderOptional = getConvertorExecutor().convert(flowStats.getMatchV10(), data);
            if (matchBuilderOptional.isPresent()) {
                if (Objects.nonNull(matchBuilderOptional.get().getIpMatch())) {
                    ipProtocol = matchBuilderOptional.get().getIpMatch().getIpProtocol();
                }
                salFlowStatsBuilder.setMatch(matchBuilderOptional.get().build());
            }
            if (flowStats.getAction() != null && flowStats.getAction().size() != 0) {
                salFlowStatsBuilder.setInstructions(wrapOF10ActionsToInstruction(flowStats.getAction(), data.getVersion(), ipProtocol));
            }
        }
        if (flowStats.getMatch() != null) {
            final Optional<MatchBuilder> matchBuilderOptional = getConvertorExecutor().convert(flowStats.getMatch(), data);
            if (matchBuilderOptional.isPresent()) {
                final MatchBuilder matchBuilder = matchBuilderOptional.get();
                final AugmentTuple<Match> matchExtensionWrap = MatchExtensionHelper.processAllExtensions(flowStats.getMatch().getMatchEntry(), OpenflowVersion.get(data.getVersion()), data.getMatchPath());
                if (matchExtensionWrap != null) {
                    matchBuilder.addAugmentation(matchExtensionWrap.getAugmentationClass(), matchExtensionWrap.getAugmentationObject());
                }
                salFlowStatsBuilder.setMatch(matchBuilder.build());
            }
            salFlowStatsBuilder.setFlags(new FlowModFlags(flowStats.getFlags().isOFPFFCHECKOVERLAP(), flowStats.getFlags().isOFPFFRESETCOUNTS(), flowStats.getFlags().isOFPFFNOPKTCOUNTS(), flowStats.getFlags().isOFPFFNOBYTCOUNTS(), flowStats.getFlags().isOFPFFSENDFLOWREM()));
        }
        if (flowStats.getInstruction() != null) {
            final VersionConvertorData simpleConvertorData = new VersionConvertorData(data.getVersion());
            final Optional<Instructions> instructions = getConvertorExecutor().convert(flowStats.getInstruction(), simpleConvertorData);
            salFlowStatsBuilder.setInstructions(instructions.orElse(new InstructionsBuilder().setInstruction(Collections.emptyList()).build()));
        }
        result.add(salFlowStatsBuilder.build());
    }
    return result;
}
Also used : FlowModFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags) ArrayList(java.util.ArrayList) Instructions(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions) FlowAndStatisticsMapList(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList) Match(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match) InstructionsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder) FlowStats(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStats) FlowAndStatisticsMapListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapListBuilder) Counter32(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32) Counter64(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64) VersionConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData) FlowCookie(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder) DurationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.duration.DurationBuilder)

Example 5 with FlowCookie

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie in project openflowplugin by opendaylight.

the class LLDPPacketPuntEnforcer method createFlow.

static Flow createFlow() {
    FlowBuilder flowBuilder = new FlowBuilder();
    flowBuilder.setMatch(new MatchBuilder().build());
    flowBuilder.setInstructions(createSendToControllerInstructions().build());
    flowBuilder.setPriority(0);
    FlowKey key = new FlowKey(new FlowId(DEFAULT_FLOW_ID));
    flowBuilder.setBarrier(Boolean.FALSE);
    flowBuilder.setBufferId(OFConstants.OFP_NO_BUFFER);
    BigInteger value = BigInteger.valueOf(10L);
    flowBuilder.setCookie(new FlowCookie(value));
    flowBuilder.setCookieMask(new FlowCookie(value));
    flowBuilder.setHardTimeout(0);
    flowBuilder.setIdleTimeout(0);
    flowBuilder.setInstallHw(false);
    flowBuilder.setStrict(false);
    flowBuilder.setContainerName(null);
    flowBuilder.setFlags(new FlowModFlags(false, false, false, false, true));
    flowBuilder.setId(new FlowId("12"));
    flowBuilder.setTableId(TABLE_ID);
    flowBuilder.setKey(key);
    flowBuilder.setFlowName(LLDP_PUNT_WHOLE_PACKET_FLOW);
    return flowBuilder.build();
}
Also used : FlowId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId) FlowKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey) FlowCookie(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie) FlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder) FlowModFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags) BigInteger(java.math.BigInteger) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)

Aggregations

FlowCookie (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie)26 BigInteger (java.math.BigInteger)15 FlowBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder)14 FlowId (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId)13 FlowKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey)11 FlowModFlags (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags)11 MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)9 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)4 FlowRegistryKey (org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey)4 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)4 Ipv4MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder)4 InstructionsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder)3 FlowDescriptor (org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowDescriptor)2 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)2 Counter32 (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32)2 Counter64 (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64)2 Table (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table)2 FlowAndStatisticsMapListBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapListBuilder)2 Match (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match)2