use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.protocols.Protocol in project openflowplugin by opendaylight.
the class FlowCreatorUtil method canModifyFlow.
/**
* Determine whether a flow entry can be modified or not.
*
* @param original An original flow entry.
* @param updated An updated flow entry.
* @param version Protocol version.
* @return {@code true} only if a flow entry can be modified.
*/
public static boolean canModifyFlow(OriginalFlow original, UpdatedFlow updated, Short version) {
// flags, and cookie.
if (!Objects.equals(original.getMatch(), updated.getMatch()) || !equalsWithDefault(original.getPriority(), updated.getPriority(), FlowConvertor.DEFAULT_PRIORITY) || !equalsWithDefault(original.getIdleTimeout(), updated.getIdleTimeout(), FlowConvertor.DEFAULT_IDLE_TIMEOUT) || !equalsWithDefault(original.getHardTimeout(), updated.getHardTimeout(), FlowConvertor.DEFAULT_HARD_TIMEOUT) || !equalsFlowModFlags(original.getFlags(), updated.getFlags())) {
return false;
}
if (!Boolean.TRUE.equals(updated.isStrict()) && version != null && version.shortValue() != OFConstants.OFP_VERSION_1_0) {
FlowCookie cookieMask = updated.getCookieMask();
if (cookieMask != null) {
BigInteger mask = cookieMask.getValue();
if (mask != null && !mask.equals(BigInteger.ZERO)) {
// Allow FLOW_MOD with filtering by cookie.
return true;
}
}
}
FlowCookie oc = original.getCookie();
FlowCookie uc = updated.getCookie();
BigInteger orgCookie;
BigInteger updCookie;
if (oc == null) {
if (uc == null) {
return true;
}
orgCookie = OFConstants.DEFAULT_COOKIE;
updCookie = uc.getValue();
} else {
orgCookie = oc.getValue();
updCookie = (uc == null) ? OFConstants.DEFAULT_COOKIE : uc.getValue();
}
return equalsWithDefault(orgCookie, updCookie, OFConstants.DEFAULT_COOKIE);
}
use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.protocols.Protocol in project openflowplugin by opendaylight.
the class SwitchConnectionProviderImpl method createAndConfigureServer.
private ServerFacade createAndConfigureServer() {
LOG.debug("Configuring ..");
ServerFacade server = null;
final ChannelInitializerFactory factory = new ChannelInitializerFactory();
factory.setSwitchConnectionHandler(switchConnectionHandler);
factory.setSwitchIdleTimeout(connConfig.getSwitchIdleTimeout());
factory.setTlsConfig(connConfig.getTlsConfiguration());
factory.setSerializationFactory(serializationFactory);
factory.setDeserializationFactory(deserializationFactory);
factory.setUseBarrier(connConfig.useBarrier());
factory.setChannelOutboundQueueSize(connConfig.getChannelOutboundQueueSize());
final TransportProtocol transportProtocol = (TransportProtocol) connConfig.getTransferProtocol();
// Check if Epoll native transport is available.
// TODO : Add option to disable Epoll.
boolean isEpollEnabled = Epoll.isAvailable();
if (TransportProtocol.TCP.equals(transportProtocol) || TransportProtocol.TLS.equals(transportProtocol)) {
server = new TcpHandler(connConfig.getAddress(), connConfig.getPort());
final TcpChannelInitializer channelInitializer = factory.createPublishingChannelInitializer();
((TcpHandler) server).setChannelInitializer(channelInitializer);
((TcpHandler) server).initiateEventLoopGroups(connConfig.getThreadConfiguration(), isEpollEnabled);
final EventLoopGroup workerGroupFromTcpHandler = ((TcpHandler) server).getWorkerGroup();
connectionInitializer = new TcpConnectionInitializer(workerGroupFromTcpHandler, isEpollEnabled);
connectionInitializer.setChannelInitializer(channelInitializer);
connectionInitializer.run();
} else if (TransportProtocol.UDP.equals(transportProtocol)) {
server = new UdpHandler(connConfig.getAddress(), connConfig.getPort());
((UdpHandler) server).initiateEventLoopGroups(connConfig.getThreadConfiguration(), isEpollEnabled);
((UdpHandler) server).setChannelInitializer(factory.createUdpChannelInitializer());
} else {
throw new IllegalStateException("Unknown transport protocol received: " + transportProtocol);
}
server.setThreadConfig(connConfig.getThreadConfiguration());
return server;
}
use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.protocols.Protocol in project openflowplugin by opendaylight.
the class OFDatagramPacketEncoderTest method startUp.
/**
* Initializes mocks and other objects.
*
* @param version openflow protocol wire version
*/
public void startUp(Short version) {
MockitoAnnotations.initMocks(this);
out = new ArrayList<>();
HelloInputBuilder builder = new HelloInputBuilder();
builder.setVersion(version);
HelloInput hello = builder.build();
wrapper = new UdpMessageListenerWrapper(hello, listener, address);
}
use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.protocols.Protocol in project openflowplugin by opendaylight.
the class MatchResponseConvertor2Test method testWithMatchEntryNoMasks.
/**
* Test {@link MatchResponseConvertor#convert(MatchEntriesGrouping, VersionDatapathIdConvertorData)}.
*/
@Test
public void testWithMatchEntryNoMasks() {
final List<MatchEntry> entries = new ArrayList<>();
MatchEntryBuilder entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.InPort.class);
entriesBuilder.setHasMask(false);
final InPortCaseBuilder caseBuilder = new InPortCaseBuilder();
final InPortBuilder portBuilder = new InPortBuilder();
portBuilder.setPortNumber(new PortNumber(1L));
caseBuilder.setInPort(portBuilder.build());
entriesBuilder.setMatchEntryValue(caseBuilder.build());
entries.add(entriesBuilder.build());
final InPhyPortCaseBuilder inPhyPortCaseBuilder = new InPhyPortCaseBuilder();
entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.InPhyPort.class);
entriesBuilder.setHasMask(false);
final InPhyPortBuilder inPhyPortBuilder = new InPhyPortBuilder();
inPhyPortBuilder.setPortNumber(new PortNumber(2L));
inPhyPortCaseBuilder.setInPhyPort(inPhyPortBuilder.build());
entriesBuilder.setMatchEntryValue(inPhyPortCaseBuilder.build());
entries.add(entriesBuilder.build());
entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Metadata.class);
entriesBuilder.setHasMask(false);
final MetadataCaseBuilder metadataCaseBuilder = new MetadataCaseBuilder();
final org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.metadata._case.MetadataBuilder metadataBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.metadata._case.MetadataBuilder();
metadataBuilder.setMetadata(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 });
metadataCaseBuilder.setMetadata(metadataBuilder.build());
entriesBuilder.setMatchEntryValue(metadataCaseBuilder.build());
entries.add(entriesBuilder.build());
entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(EthDst.class);
entriesBuilder.setHasMask(false);
final EthDstCaseBuilder ethDstCaseBuilder = new EthDstCaseBuilder();
final EthDstBuilder ethDstBuilder = new EthDstBuilder();
ethDstBuilder.setMacAddress(new MacAddress("00:00:00:00:00:01"));
ethDstCaseBuilder.setEthDst(ethDstBuilder.build());
entriesBuilder.setMatchEntryValue(ethDstCaseBuilder.build());
entries.add(entriesBuilder.build());
entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(EthSrc.class);
entriesBuilder.setHasMask(false);
final EthSrcCaseBuilder ethSrcCaseBuilder = new EthSrcCaseBuilder();
final EthSrcBuilder ethSrcBuilder = new EthSrcBuilder();
ethSrcBuilder.setMacAddress(new MacAddress("00:00:00:00:00:02"));
ethSrcCaseBuilder.setEthSrc(ethSrcBuilder.build());
entriesBuilder.setMatchEntryValue(ethSrcCaseBuilder.build());
entries.add(entriesBuilder.build());
entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(EthType.class);
entriesBuilder.setHasMask(false);
final EthTypeCaseBuilder ethTypeCaseBuilder = new EthTypeCaseBuilder();
final EthTypeBuilder ethTypeBuilder = new EthTypeBuilder();
ethTypeBuilder.setEthType(new EtherType(3));
ethTypeCaseBuilder.setEthType(ethTypeBuilder.build());
entriesBuilder.setMatchEntryValue(ethTypeCaseBuilder.build());
entries.add(entriesBuilder.build());
entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(VlanVid.class);
final VlanVidCaseBuilder vlanVidCaseBuilder = new VlanVidCaseBuilder();
entriesBuilder.setHasMask(false);
final VlanVidBuilder vlanVidBuilder = new VlanVidBuilder();
vlanVidBuilder.setVlanVid(4);
vlanVidBuilder.setCfiBit(true);
vlanVidCaseBuilder.setVlanVid(vlanVidBuilder.build());
entriesBuilder.setMatchEntryValue(vlanVidCaseBuilder.build());
entries.add(entriesBuilder.build());
entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(VlanPcp.class);
final VlanPcpCaseBuilder vlanPcpCaseBuilder = new VlanPcpCaseBuilder();
entriesBuilder.setHasMask(false);
final VlanPcpBuilder vlanPcpBuilder = new VlanPcpBuilder();
vlanPcpBuilder.setVlanPcp((short) 5);
vlanPcpCaseBuilder.setVlanPcp(vlanPcpBuilder.build());
entriesBuilder.setMatchEntryValue(vlanPcpCaseBuilder.build());
entries.add(entriesBuilder.build());
entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(IpDscp.class);
entriesBuilder.setHasMask(false);
final IpDscpCaseBuilder ipDscpCaseBuilder = new IpDscpCaseBuilder();
final IpDscpBuilder ipDscpBuilder = new IpDscpBuilder();
ipDscpBuilder.setDscp(new Dscp((short) 6));
ipDscpCaseBuilder.setIpDscp(ipDscpBuilder.build());
entriesBuilder.setMatchEntryValue(ipDscpCaseBuilder.build());
entries.add(entriesBuilder.build());
entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(IpEcn.class);
entriesBuilder.setHasMask(false);
final IpEcnCaseBuilder ipEcnCaseBuilder = new IpEcnCaseBuilder();
final IpEcnBuilder ipEcnBuilder = new IpEcnBuilder();
ipEcnBuilder.setEcn((short) 7);
ipEcnCaseBuilder.setIpEcn(ipEcnBuilder.build());
entriesBuilder.setMatchEntryValue(ipEcnCaseBuilder.build());
entries.add(entriesBuilder.build());
entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(IpProto.class);
final IpProtoCaseBuilder ipProtoCaseBuilder = new IpProtoCaseBuilder();
entriesBuilder.setHasMask(false);
final IpProtoBuilder ipProtoBuilder = new IpProtoBuilder();
ipProtoBuilder.setProtocolNumber((short) 8);
ipProtoCaseBuilder.setIpProto(ipProtoBuilder.build());
entriesBuilder.setMatchEntryValue(ipProtoCaseBuilder.build());
entries.add(entriesBuilder.build());
entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(Ipv4Src.class);
entriesBuilder.setHasMask(false);
final Ipv4SrcCaseBuilder ipv4AddressBuilder = new Ipv4SrcCaseBuilder();
final Ipv4SrcBuilder ipv4SrcBuilder = new Ipv4SrcBuilder();
ipv4SrcBuilder.setIpv4Address(new Ipv4Address("10.0.0.1"));
ipv4AddressBuilder.setIpv4Src(ipv4SrcBuilder.build());
entriesBuilder.setMatchEntryValue(ipv4AddressBuilder.build());
entries.add(entriesBuilder.build());
entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(Ipv4Dst.class);
entriesBuilder.setHasMask(false);
final Ipv4DstCaseBuilder ipv4DstCaseBuilder = new Ipv4DstCaseBuilder();
final Ipv4DstBuilder ipv4DstBuilder = new Ipv4DstBuilder();
ipv4DstBuilder.setIpv4Address(new Ipv4Address("10.0.0.2"));
ipv4DstCaseBuilder.setIpv4Dst(ipv4DstBuilder.build());
entriesBuilder.setMatchEntryValue(ipv4DstCaseBuilder.build());
entries.add(entriesBuilder.build());
entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(TcpSrc.class);
entriesBuilder.setHasMask(false);
final TcpSrcCaseBuilder tcpSrcCaseBuilder = new TcpSrcCaseBuilder();
final TcpSrcBuilder tcpSrcBuilder = new TcpSrcBuilder();
tcpSrcBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(9));
tcpSrcCaseBuilder.setTcpSrc(tcpSrcBuilder.build());
entriesBuilder.setMatchEntryValue(tcpSrcCaseBuilder.build());
entries.add(entriesBuilder.build());
entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(TcpDst.class);
entriesBuilder.setHasMask(false);
final TcpDstCaseBuilder tcpDstCaseBuilder = new TcpDstCaseBuilder();
final TcpDstBuilder tcpDstBuilder = new TcpDstBuilder();
tcpDstBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(10));
tcpDstCaseBuilder.setTcpDst(tcpDstBuilder.build());
entriesBuilder.setMatchEntryValue(tcpDstCaseBuilder.build());
entries.add(entriesBuilder.build());
entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(Icmpv4Type.class);
entriesBuilder.setHasMask(false);
final Icmpv4TypeCaseBuilder icmpv4TypeCaseBuilder = new Icmpv4TypeCaseBuilder();
final Icmpv4TypeBuilder icmpv4TypeBuilder = new Icmpv4TypeBuilder();
icmpv4TypeBuilder.setIcmpv4Type((short) 15);
icmpv4TypeCaseBuilder.setIcmpv4Type(icmpv4TypeBuilder.build());
entriesBuilder.setMatchEntryValue(icmpv4TypeCaseBuilder.build());
entries.add(entriesBuilder.build());
entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(Icmpv4Code.class);
entriesBuilder.setHasMask(false);
final Icmpv4CodeCaseBuilder icmpv4CodeCaseBuilder = new Icmpv4CodeCaseBuilder();
final Icmpv4CodeBuilder icmpv4CodeBuilder = new Icmpv4CodeBuilder();
icmpv4CodeBuilder.setIcmpv4Code((short) 16);
icmpv4CodeCaseBuilder.setIcmpv4Code(icmpv4CodeBuilder.build());
entriesBuilder.setMatchEntryValue(icmpv4CodeCaseBuilder.build());
entries.add(entriesBuilder.build());
entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(Icmpv6Type.class);
entriesBuilder.setHasMask(false);
final Icmpv6TypeCaseBuilder icmpv6TypeCaseBuilder = new Icmpv6TypeCaseBuilder();
final Icmpv6TypeBuilder icmpv6TypeBuilder = new Icmpv6TypeBuilder();
icmpv6TypeBuilder.setIcmpv6Type((short) 19);
icmpv6TypeCaseBuilder.setIcmpv6Type(icmpv6TypeBuilder.build());
entriesBuilder.setMatchEntryValue(icmpv6TypeCaseBuilder.build());
entries.add(entriesBuilder.build());
entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(Icmpv6Code.class);
entriesBuilder.setHasMask(false);
final Icmpv6CodeCaseBuilder icmpv6CodeCaseBuilder = new Icmpv6CodeCaseBuilder();
final Icmpv6CodeBuilder icmpv6CodeBuilder = new Icmpv6CodeBuilder();
icmpv6CodeBuilder.setIcmpv6Code((short) 20);
icmpv6CodeCaseBuilder.setIcmpv6Code(icmpv6CodeBuilder.build());
entriesBuilder.setMatchEntryValue(icmpv6CodeCaseBuilder.build());
entries.add(entriesBuilder.build());
entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(MplsLabel.class);
entriesBuilder.setHasMask(false);
final MplsLabelCaseBuilder mplsLabelCaseBuilder = new MplsLabelCaseBuilder();
final MplsLabelBuilder mplsLabelBuilder = new MplsLabelBuilder();
mplsLabelBuilder.setMplsLabel(21L);
mplsLabelCaseBuilder.setMplsLabel(mplsLabelBuilder.build());
entriesBuilder.setMatchEntryValue(mplsLabelCaseBuilder.build());
entries.add(entriesBuilder.build());
entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(MplsTc.class);
entriesBuilder.setHasMask(false);
final MplsTcCaseBuilder mplsTcCaseBuilder = new MplsTcCaseBuilder();
final MplsTcBuilder mplsTcBuilder = new MplsTcBuilder();
mplsTcBuilder.setTc((short) 22);
mplsTcCaseBuilder.setMplsTc(mplsTcBuilder.build());
entriesBuilder.setMatchEntryValue(mplsTcCaseBuilder.build());
entries.add(entriesBuilder.build());
entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(MplsBos.class);
entriesBuilder.setHasMask(false);
final MplsBosCaseBuilder mplsBosCaseBuilder = new MplsBosCaseBuilder();
final MplsBosBuilder mplsBosBuilder = new MplsBosBuilder();
mplsBosBuilder.setBos(true);
mplsBosCaseBuilder.setMplsBos(mplsBosBuilder.build());
entriesBuilder.setMatchEntryValue(mplsBosCaseBuilder.build());
entries.add(entriesBuilder.build());
entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(PbbIsid.class);
entriesBuilder.setHasMask(false);
final PbbIsidCaseBuilder pbbIsidCaseBuilder = new PbbIsidCaseBuilder();
final PbbIsidBuilder pbbIsidBuilder = new PbbIsidBuilder();
pbbIsidBuilder.setIsid(23L);
pbbIsidCaseBuilder.setPbbIsid(pbbIsidBuilder.build());
entriesBuilder.setMatchEntryValue(pbbIsidCaseBuilder.build());
entries.add(entriesBuilder.build());
entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(TunnelId.class);
entriesBuilder.setHasMask(false);
final TunnelIdCaseBuilder tunnelIdCaseBuilder = new TunnelIdCaseBuilder();
final TunnelIdBuilder tunnelIdBuilder = new TunnelIdBuilder();
tunnelIdBuilder.setTunnelId(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 });
tunnelIdCaseBuilder.setTunnelId(tunnelIdBuilder.build());
entriesBuilder.setMatchEntryValue(tunnelIdCaseBuilder.build());
entries.add(entriesBuilder.build());
final MatchBuilder builder = new MatchBuilder();
builder.setMatchEntry(entries);
final Match match = builder.build();
final VersionDatapathIdConvertorData datapathIdConvertorData = new VersionDatapathIdConvertorData(OFConstants.OFP_VERSION_1_3);
datapathIdConvertorData.setDatapathId(new BigInteger("42"));
final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder salMatch = convert(match, datapathIdConvertorData);
final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match builtMatch = salMatch.build();
Assert.assertEquals("Wrong in port", "openflow:42:1", builtMatch.getInPort().getValue());
Assert.assertEquals("Wrong in phy port", "openflow:42:2", builtMatch.getInPhyPort().getValue());
Assert.assertEquals("Wrong metadata", new BigInteger(1, new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 }), builtMatch.getMetadata().getMetadata());
Assert.assertEquals("Wrong eth dst", new MacAddress("00:00:00:00:00:01"), builtMatch.getEthernetMatch().getEthernetDestination().getAddress());
Assert.assertEquals("Wrong eth src", new MacAddress("00:00:00:00:00:02"), builtMatch.getEthernetMatch().getEthernetSource().getAddress());
Assert.assertEquals("Wrong eth type", 3, builtMatch.getEthernetMatch().getEthernetType().getType().getValue().intValue());
Assert.assertEquals("Wrong vlan id", 4, builtMatch.getVlanMatch().getVlanId().getVlanId().getValue().intValue());
Assert.assertEquals("Wrong vlan id entries", true, builtMatch.getVlanMatch().getVlanId().isVlanIdPresent());
Assert.assertEquals("Wrong vlan pcp", 5, builtMatch.getVlanMatch().getVlanPcp().getValue().intValue());
Assert.assertEquals("Wrong ip dscp", 6, builtMatch.getIpMatch().getIpDscp().getValue().intValue());
Assert.assertEquals("Wrong ip ecn", 7, builtMatch.getIpMatch().getIpEcn().intValue());
Assert.assertEquals("Wrong ip proto", null, builtMatch.getIpMatch().getIpProto());
Assert.assertEquals("Wrong ip protocol", 8, builtMatch.getIpMatch().getIpProtocol().intValue());
final TcpMatch tcpMatch = (TcpMatch) builtMatch.getLayer4Match();
Assert.assertEquals("Wrong tcp src port", 9, tcpMatch.getTcpSourcePort().getValue().intValue());
Assert.assertEquals("Wrong tcp dst port", 10, tcpMatch.getTcpDestinationPort().getValue().intValue());
Assert.assertEquals("Wrong icmpv4 type", 15, builtMatch.getIcmpv4Match().getIcmpv4Type().intValue());
Assert.assertEquals("Wrong icmpv4 code", 16, builtMatch.getIcmpv4Match().getIcmpv4Code().intValue());
Assert.assertEquals("Wrong icmpv6 type", 19, builtMatch.getIcmpv6Match().getIcmpv6Type().intValue());
Assert.assertEquals("Wrong icmpv6 code", 20, builtMatch.getIcmpv6Match().getIcmpv6Code().intValue());
final Ipv4Match ipv4Match = (Ipv4Match) builtMatch.getLayer3Match();
Assert.assertEquals("Wrong ipv4 src address", "10.0.0.1/32", ipv4Match.getIpv4Source().getValue());
Assert.assertEquals("Wrong ipv4 dst address", "10.0.0.2/32", ipv4Match.getIpv4Destination().getValue());
Assert.assertEquals("Wrong mpls label", 21, builtMatch.getProtocolMatchFields().getMplsLabel().intValue());
Assert.assertEquals("Wrong mpls bos", 1, builtMatch.getProtocolMatchFields().getMplsBos().intValue());
Assert.assertEquals("Wrong mpls tc", 22, builtMatch.getProtocolMatchFields().getMplsTc().intValue());
Assert.assertEquals("Wrong pbb isid", 23, builtMatch.getProtocolMatchFields().getPbb().getPbbIsid().intValue());
Assert.assertEquals("Wrong tunnel id", new BigInteger(1, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }), builtMatch.getTunnel().getTunnelId());
}
use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.protocols.Protocol in project openflowplugin by opendaylight.
the class MatchV10ResponseConvertorTest method testIcmpv4Match.
/**
* ICMPv4 match test for {@link MatchV10ResponseConvertor#convert(MatchV10, VersionDatapathIdConvertorData)}.
*/
@Test
public void testIcmpv4Match() {
// NW_PROTO, TP_SRC, TP_DST are wildcarded.
Long dlType = 0x800L;
FlowWildcardsV10 wc = new FlowWildcardsV10(true, true, false, true, true, true, true, true, true, true);
MatchV10Builder builder = new MatchV10Builder().setWildcards(wc).setDlType(dlType.intValue());
MatchV10 match = builder.build();
BigInteger dpid = BigInteger.valueOf(12345L);
final VersionDatapathIdConvertorData datapathIdConvertorData = new VersionDatapathIdConvertorData(OFConstants.OFP_VERSION_1_0);
datapathIdConvertorData.setDatapathId(dpid);
Match salMatch = convert(match, datapathIdConvertorData).build();
EthernetMatch etherMatch = salMatch.getEthernetMatch();
Assert.assertEquals("Wrong in port", null, salMatch.getInPort());
Assert.assertEquals("Wrong dl src", null, etherMatch.getEthernetSource());
Assert.assertEquals("Wrong dl dst", null, etherMatch.getEthernetDestination());
Assert.assertEquals("Wrong dl type", dlType, etherMatch.getEthernetType().getType().getValue());
Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());
Assert.assertEquals("Wrong IP match", null, salMatch.getIpMatch());
Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());
Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());
Assert.assertEquals("Wrong ICMPv4 match", null, salMatch.getIcmpv4Match());
// NW_PROTO is not wildcarded but null.
wc = new FlowWildcardsV10(true, true, false, true, true, true, false, true, true, true);
match = builder.setWildcards(wc).build();
salMatch = convert(match, datapathIdConvertorData).build();
etherMatch = salMatch.getEthernetMatch();
Assert.assertEquals("Wrong in port", null, salMatch.getInPort());
Assert.assertEquals("Wrong dl src", null, etherMatch.getEthernetSource());
Assert.assertEquals("Wrong dl dst", null, etherMatch.getEthernetDestination());
Assert.assertEquals("Wrong dl type", dlType, etherMatch.getEthernetType().getType().getValue());
Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());
Assert.assertEquals("Wrong IP match", null, salMatch.getIpMatch());
Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());
Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());
Assert.assertEquals("Wrong ICMPv4 match", null, salMatch.getIcmpv4Match());
// Specify ICMPv4 protocol.
Short ipProto = 1;
match = builder.setNwProto(ipProto).build();
salMatch = convert(match, datapathIdConvertorData).build();
etherMatch = salMatch.getEthernetMatch();
IpMatch ipMatch = salMatch.getIpMatch();
Assert.assertEquals("Wrong in port", null, salMatch.getInPort());
Assert.assertEquals("Wrong dl src", null, etherMatch.getEthernetSource());
Assert.assertEquals("Wrong dl dst", null, etherMatch.getEthernetDestination());
Assert.assertEquals("Wrong dl type", dlType, etherMatch.getEthernetType().getType().getValue());
Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());
Assert.assertEquals("Wrong ip protocol", ipProto, ipMatch.getIpProtocol());
Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());
Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());
Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());
Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());
Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());
Assert.assertEquals("Wrong ICMPv4 match", null, salMatch.getIcmpv4Match());
// TP_SRC is not wildcarded but null.
wc = new FlowWildcardsV10(true, true, false, true, true, true, false, true, true, false);
match = builder.setWildcards(wc).build();
salMatch = convert(match, datapathIdConvertorData).build();
etherMatch = salMatch.getEthernetMatch();
ipMatch = salMatch.getIpMatch();
Assert.assertEquals("Wrong in port", null, salMatch.getInPort());
Assert.assertEquals("Wrong dl src", null, etherMatch.getEthernetSource());
Assert.assertEquals("Wrong dl dst", null, etherMatch.getEthernetDestination());
Assert.assertEquals("Wrong dl type", dlType, etherMatch.getEthernetType().getType().getValue());
Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());
Assert.assertEquals("Wrong ip protocol", ipProto, ipMatch.getIpProtocol());
Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());
Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());
Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());
Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());
Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());
Assert.assertEquals("Wrong ICMPv4 match", null, salMatch.getIcmpv4Match());
// Specify ICMPv4 type.
Short icmpType = 10;
match = builder.setTpSrc(icmpType.intValue()).build();
salMatch = convert(match, datapathIdConvertorData).build();
etherMatch = salMatch.getEthernetMatch();
ipMatch = salMatch.getIpMatch();
Icmpv4Match icmpv4Match = salMatch.getIcmpv4Match();
Assert.assertEquals("Wrong in port", null, salMatch.getInPort());
Assert.assertEquals("Wrong dl src", null, etherMatch.getEthernetSource());
Assert.assertEquals("Wrong dl dst", null, etherMatch.getEthernetDestination());
Assert.assertEquals("Wrong dl type", dlType, etherMatch.getEthernetType().getType().getValue());
Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());
Assert.assertEquals("Wrong ip protocol", ipProto, ipMatch.getIpProtocol());
Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());
Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());
Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());
Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());
Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());
Assert.assertEquals("Wrong ICMPv4 type", icmpType, icmpv4Match.getIcmpv4Type());
Assert.assertEquals("Wrong ICMPv4 code", null, icmpv4Match.getIcmpv4Code());
// TP_DST is not wildcarded but null.
wc = new FlowWildcardsV10(true, true, false, true, true, true, false, true, false, false);
match = builder.setWildcards(wc).build();
salMatch = convert(match, datapathIdConvertorData).build();
etherMatch = salMatch.getEthernetMatch();
ipMatch = salMatch.getIpMatch();
icmpv4Match = salMatch.getIcmpv4Match();
Assert.assertEquals("Wrong in port", null, salMatch.getInPort());
Assert.assertEquals("Wrong dl src", null, etherMatch.getEthernetSource());
Assert.assertEquals("Wrong dl dst", null, etherMatch.getEthernetDestination());
Assert.assertEquals("Wrong dl type", dlType, etherMatch.getEthernetType().getType().getValue());
Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());
Assert.assertEquals("Wrong ip protocol", ipProto, ipMatch.getIpProtocol());
Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());
Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());
Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());
Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());
Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());
Assert.assertEquals("Wrong ICMPv4 type", icmpType, icmpv4Match.getIcmpv4Type());
Assert.assertEquals("Wrong ICMPv4 code", null, icmpv4Match.getIcmpv4Code());
// Specify ICMPv4 code only.
Short icmpCode = 33;
match = builder.setTpSrc(null).setTpDst(icmpCode.intValue()).build();
salMatch = convert(match, datapathIdConvertorData).build();
etherMatch = salMatch.getEthernetMatch();
ipMatch = salMatch.getIpMatch();
icmpv4Match = salMatch.getIcmpv4Match();
Assert.assertEquals("Wrong in port", null, salMatch.getInPort());
Assert.assertEquals("Wrong dl src", null, etherMatch.getEthernetSource());
Assert.assertEquals("Wrong dl dst", null, etherMatch.getEthernetDestination());
Assert.assertEquals("Wrong dl type", dlType, etherMatch.getEthernetType().getType().getValue());
Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());
Assert.assertEquals("Wrong ip protocol", ipProto, ipMatch.getIpProtocol());
Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());
Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());
Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());
Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());
Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());
Assert.assertEquals("Wrong ICMPv4 type", null, icmpv4Match.getIcmpv4Type());
Assert.assertEquals("Wrong ICMPv4 code", icmpCode, icmpv4Match.getIcmpv4Code());
// Specify both ICMPv4 type and code.
icmpType = 0;
icmpCode = 8;
match = builder.setTpSrc(icmpType.intValue()).setTpDst(icmpCode.intValue()).build();
salMatch = convert(match, datapathIdConvertorData).build();
etherMatch = salMatch.getEthernetMatch();
ipMatch = salMatch.getIpMatch();
icmpv4Match = salMatch.getIcmpv4Match();
Assert.assertEquals("Wrong in port", null, salMatch.getInPort());
Assert.assertEquals("Wrong dl src", null, etherMatch.getEthernetSource());
Assert.assertEquals("Wrong dl dst", null, etherMatch.getEthernetDestination());
Assert.assertEquals("Wrong dl type", dlType, etherMatch.getEthernetType().getType().getValue());
Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());
Assert.assertEquals("Wrong ip protocol", ipProto, ipMatch.getIpProtocol());
Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());
Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());
Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());
Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());
Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());
Assert.assertEquals("Wrong ICMPv4 type", icmpType, icmpv4Match.getIcmpv4Type());
Assert.assertEquals("Wrong ICMPv4 code", icmpCode, icmpv4Match.getIcmpv4Code());
}
Aggregations