use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow in project openflowplugin by opendaylight.
the class LearningSwitchHandlerSimpleImpl method onSwitchAppeared.
@Override
public synchronized void onSwitchAppeared(InstanceIdentifier<Table> appearedTablePath) {
if (isLearning) {
LOG.debug("already learning a node, skipping {}", nodeId.getValue());
return;
}
LOG.debug("expected table acquired, learning ..");
// disable listening - simple learning handles only one node (switch)
if (registrationPublisher != null) {
LOG.debug("closing dataTreeChangeListenerRegistration");
registrationPublisher.getDataTreeChangeListenerRegistration().close();
}
isLearning = true;
tablePath = appearedTablePath;
nodePath = tablePath.firstIdentifierOf(Node.class);
nodeId = nodePath.firstKeyOf(Node.class, NodeKey.class).getId();
mac2portMapping = new HashMap<>();
// start forwarding all packages to controller
FlowId flowId = new FlowId(String.valueOf(flowIdInc.getAndIncrement()));
FlowKey flowKey = new FlowKey(flowId);
InstanceIdentifier<Flow> flowPath = InstanceIdentifierUtils.createFlowPath(tablePath, flowKey);
int priority = 0;
// create flow in table with id = 0, priority = 4 (other params are
// defaulted in OFDataStoreUtil)
FlowBuilder allToCtrlFlow = FlowUtils.createFwdAllToControllerFlow(InstanceIdentifierUtils.getTableId(tablePath), priority, flowId);
LOG.debug("writing packetForwardToController flow");
dataStoreAccessor.writeFlowToConfig(flowPath, allToCtrlFlow.build());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow 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());
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow 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();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow 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;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow in project openflowplugin by opendaylight.
the class OfToSalTunnelIpv4DstCase method process.
@Override
public Optional<MatchBuilder> process(@Nonnull Ipv4DstCase source, MatchResponseConvertorData data, ConvertorExecutor convertorExecutor) {
final MatchBuilder matchBuilder = data.getMatchBuilder();
final Ipv4MatchBuilder ipv4MatchBuilder = data.getIpv4MatchBuilder();
final TunnelIpv4MatchBuilder tunnelIpv4MatchBuilder = data.getTunnelIpv4MatchBuilder();
Ipv4Dst tunnelIpv4Dst = source.getIpv4Dst();
if (tunnelIpv4Dst != null) {
String ipv4PrefixStr = tunnelIpv4Dst.getIpv4Address().getValue();
byte[] mask = tunnelIpv4Dst.getMask();
ipv4PrefixStr += IpConversionUtil.PREFIX_SEPARATOR + ByteBuffer.wrap(tunnelIpv4Dst.getMask()).getInt();
final Ipv4Prefix ipv4Prefix;
if (mask != null) {
ipv4Prefix = IpConversionUtil.createPrefix(new Ipv4Address(ipv4PrefixStr), mask);
} else {
// Openflow Spec : 1.3.2
// An all-one-bits oxm_mask is equivalent to specifying 0 for oxm_hasmask and omitting oxm_mask.
// So when user specify 32 as a mast, switch omit that mast and we get null as a mask in flow
// statistics response.
ipv4Prefix = IpConversionUtil.createPrefix(new Ipv4Address(ipv4PrefixStr));
}
ipv4MatchBuilder.setIpv4Destination(ipv4Prefix);
matchBuilder.setLayer3Match(tunnelIpv4MatchBuilder.build());
}
return Optional.of(matchBuilder);
}
Aggregations