package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match;\r
\r
import java.math.BigInteger;\r
+import java.util.Optional;\r
import org.junit.Assert;\r
import org.junit.Before;\r
import org.junit.Test;\r
-import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;\r
+import org.opendaylight.openflowplugin.api.OFConstants;\r
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager;\r
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData;\r
import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;\r
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;\r
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4Match;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatch;\r
* @author michal.polkorab\r
*\r
*/\r
-public class MatchConvertorImplV10Test {\r
+public class MatchV10ResponseConvertorTest {\r
\r
/**\r
* Initializes OpenflowPortsUtil\r
}\r
\r
/**\r
- * Test {@link MatchConvertorImpl#fromOFMatchV10ToSALMatch(MatchV10, BigInteger, OpenflowVersion)}\r
+ * Test {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchV10ResponseConvertor#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10, org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData)}\r
*/\r
@Test\r
public void test() {\r
builder.setTpDst(4096);\r
MatchV10 match = builder.build();\r
\r
- Match salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(match, new BigInteger("42"), OpenflowVersion.OF10).build();\r
+ final VersionDatapathIdConvertorData datapathIdConvertorData = new VersionDatapathIdConvertorData(OFConstants.OFP_VERSION_1_0);\r
+ datapathIdConvertorData.setDatapathId(new BigInteger("42"));\r
+\r
+ final Match salMatch = convert(match, datapathIdConvertorData).build();\r
\r
Assert.assertEquals("Wrong in port", "openflow:42:6653", salMatch.getInPort().getValue());\r
Assert.assertEquals("Wrong dl src", new MacAddress("01:01:01:01:01:01"), salMatch.getEthernetMatch()\r
}\r
\r
/**\r
- * Test {@link MatchConvertorImpl#fromOFMatchV10ToSALMatch(MatchV10, BigInteger, OpenflowVersion)}\r
+ * Test {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchV10ResponseConvertor#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10, org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData)}\r
*/\r
@Test\r
public void testWildcardedMatch() {\r
builder.setTpDst(4096);\r
MatchV10 match = builder.build();\r
\r
- Match salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(match, new BigInteger("42"), OpenflowVersion.OF10).build();\r
+ final VersionDatapathIdConvertorData datapathIdConvertorData = new VersionDatapathIdConvertorData(OFConstants.OFP_VERSION_1_0);\r
+ datapathIdConvertorData.setDatapathId(new BigInteger("42"));\r
+\r
+ final Match salMatch = convert(match, datapathIdConvertorData).build();\r
\r
Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
Assert.assertEquals("Wrong dl match", null, salMatch.getEthernetMatch());\r
}\r
\r
/**\r
- * Test {@link MatchConvertorImpl#fromOFMatchV10ToSALMatch(MatchV10, BigInteger, OpenflowVersion)}\r
+ * Test {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchV10ResponseConvertor#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10, org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData)}\r
*/\r
@Test\r
public void testWildcardedMatchWithNoValuesSet() {\r
true, true, true, true, true, true));\r
MatchV10 match = builder.build();\r
\r
- Match salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(match, new BigInteger("42"), OpenflowVersion.OF10).build();\r
+ final VersionDatapathIdConvertorData datapathIdConvertorData = new VersionDatapathIdConvertorData(OFConstants.OFP_VERSION_1_0);\r
+ datapathIdConvertorData.setDatapathId(new BigInteger("42"));\r
+\r
+ final Match salMatch = convert(match, datapathIdConvertorData).build();\r
\r
Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
Assert.assertEquals("Wrong dl match", null, salMatch.getEthernetMatch());\r
}\r
\r
/**\r
- * Test {@link MatchConvertorImpl#fromOFMatchV10ToSALMatch(MatchV10, BigInteger, OpenflowVersion)}\r
+ * Test {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchV10ResponseConvertor#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10, org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData)}\r
*/\r
@Test\r
public void testMatchWithValuesUnset() {\r
builder.setTpDst(4096);\r
MatchV10 match = builder.build();\r
\r
- Match salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(match, new BigInteger("42"), OpenflowVersion.OF10).build();\r
+ final VersionDatapathIdConvertorData datapathIdConvertorData = new VersionDatapathIdConvertorData(OFConstants.OFP_VERSION_1_0);\r
+ datapathIdConvertorData.setDatapathId(new BigInteger("42"));\r
+\r
+ final Match salMatch = convert(match, datapathIdConvertorData).build();\r
\r
Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
Assert.assertEquals("Wrong dl match", null, salMatch.getEthernetMatch());\r
}\r
\r
/**\r
- * Test {@link MatchConvertorImpl#fromOFMatchV10ToSALMatch(MatchV10, BigInteger, OpenflowVersion)}\r
+ * Test {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchV10ResponseConvertor#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10, org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData)}\r
*/\r
@Test(expected=NullPointerException.class)\r
public void testEmptyMatch() {\r
MatchV10Builder builder = new MatchV10Builder();\r
MatchV10 match = builder.build();\r
\r
- MatchConvertorImpl.fromOFMatchV10ToSALMatch(match, new BigInteger("42"), OpenflowVersion.OF10);\r
+ final VersionDatapathIdConvertorData datapathIdConvertorData = new VersionDatapathIdConvertorData(OFConstants.OFP_VERSION_1_0);\r
+ datapathIdConvertorData.setDatapathId(new BigInteger("42"));\r
+\r
+ final Match salMatch = convert(match, datapathIdConvertorData).build();\r
}\r
\r
/**\r
- * ICMPv4 match test for\r
- * {@link MatchConvertorImpl#fromOFMatchV10ToSALMatch(MatchV10, BigInteger, OpenflowVersion)}.\r
+ * ICMPv4 match test for {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchV10ResponseConvertor#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10, org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData)}\r
*/\r
@Test\r
public void testIcmpv4Match() {\r
MatchV10 match = builder.build();\r
\r
BigInteger dpid = BigInteger.valueOf(12345L);\r
- Match salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10).build();\r
+ final VersionDatapathIdConvertorData datapathIdConvertorData = new VersionDatapathIdConvertorData(OFConstants.OFP_VERSION_1_0);\r
+ datapathIdConvertorData.setDatapathId(dpid);\r
+\r
+ Match salMatch = convert(match, datapathIdConvertorData).build();\r
+\r
EthernetMatch etherMatch = salMatch.getEthernetMatch();\r
Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
Assert.assertEquals("Wrong dl src",\r
wc = new FlowWildcardsV10(\r
true, true, false, true, true, true, false, true, true, true);\r
match = builder.setWildcards(wc).build();\r
- salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10).build();\r
+\r
+ salMatch = convert(match, datapathIdConvertorData).build();\r
etherMatch = salMatch.getEthernetMatch();\r
Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
Assert.assertEquals("Wrong dl src",\r
// Specify ICMPv4 protocol.\r
Short ipProto = 1;\r
match = builder.setNwProto(ipProto).build();\r
- salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10).build();\r
+ salMatch = convert(match, datapathIdConvertorData).build();\r
etherMatch = salMatch.getEthernetMatch();\r
IpMatch ipMatch = salMatch.getIpMatch();\r
Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
wc = new FlowWildcardsV10(\r
true, true, false, true, true, true, false, true, true, false);\r
match = builder.setWildcards(wc).build();\r
- salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10).build();\r
+ salMatch = convert(match, datapathIdConvertorData).build();\r
etherMatch = salMatch.getEthernetMatch();\r
ipMatch = salMatch.getIpMatch();\r
Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
// Specify ICMPv4 type.\r
Short icmpType = 10;\r
match = builder.setTpSrc(icmpType.intValue()).build();\r
- salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10).build();\r
+ salMatch = convert(match, datapathIdConvertorData).build();\r
etherMatch = salMatch.getEthernetMatch();\r
ipMatch = salMatch.getIpMatch();\r
Icmpv4Match icmpv4Match = salMatch.getIcmpv4Match();\r
wc = new FlowWildcardsV10(\r
true, true, false, true, true, true, false, true, false, false);\r
match = builder.setWildcards(wc).build();\r
- salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10).build();\r
+ salMatch = convert(match, datapathIdConvertorData).build();\r
etherMatch = salMatch.getEthernetMatch();\r
ipMatch = salMatch.getIpMatch();\r
icmpv4Match = salMatch.getIcmpv4Match();\r
// Specify ICMPv4 code only.\r
Short icmpCode = 33;\r
match = builder.setTpSrc(null).setTpDst(icmpCode.intValue()).build();\r
- salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10).build();\r
+ salMatch = convert(match, datapathIdConvertorData).build();\r
etherMatch = salMatch.getEthernetMatch();\r
ipMatch = salMatch.getIpMatch();\r
icmpv4Match = salMatch.getIcmpv4Match();\r
icmpCode = 8;\r
match = builder.setTpSrc(icmpType.intValue()).\r
setTpDst(icmpCode.intValue()).build();\r
- salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10).build();\r
+ salMatch = convert(match, datapathIdConvertorData).build();\r
etherMatch = salMatch.getEthernetMatch();\r
ipMatch = salMatch.getIpMatch();\r
icmpv4Match = salMatch.getIcmpv4Match();\r
}\r
\r
/**\r
- * TCP match test for\r
- * {@link MatchConvertorImpl#fromOFMatchV10ToSALMatch(MatchV10, BigInteger, OpenflowVersion)}.\r
+ * TCP match test for {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchV10ResponseConvertor#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10, org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData)}\r
*/\r
@Test\r
public void testTcpMatch() {\r
MatchV10 match = builder.build();\r
\r
BigInteger dpid = BigInteger.valueOf(12345L);\r
- Match salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10).build();\r
+ final VersionDatapathIdConvertorData datapathIdConvertorData = new VersionDatapathIdConvertorData(OFConstants.OFP_VERSION_1_0);\r
+ datapathIdConvertorData.setDatapathId(dpid);\r
+\r
+ Match salMatch = convert(match, datapathIdConvertorData).build();\r
EthernetMatch etherMatch = salMatch.getEthernetMatch();\r
Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
Assert.assertEquals("Wrong dl src",\r
// Specify TCP protocol.\r
Short ipProto = 6;\r
match = builder.setNwProto(ipProto).build();\r
- salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10).build();\r
+ salMatch = convert(match, datapathIdConvertorData).build();\r
etherMatch = salMatch.getEthernetMatch();\r
IpMatch ipMatch = salMatch.getIpMatch();\r
Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
wc = new FlowWildcardsV10(\r
true, true, false, true, true, true, false, true, true, false);\r
match = builder.setWildcards(wc).build();\r
- salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10).build();\r
+ salMatch = convert(match, datapathIdConvertorData).build();\r
etherMatch = salMatch.getEthernetMatch();\r
ipMatch = salMatch.getIpMatch();\r
Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
// Specify TCP source port.\r
Integer srcPort = 60000;\r
match = builder.setTpSrc(srcPort).build();\r
- salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10).build();\r
+ salMatch = convert(match, datapathIdConvertorData).build();\r
etherMatch = salMatch.getEthernetMatch();\r
ipMatch = salMatch.getIpMatch();\r
TcpMatch tcpMatch = (TcpMatch)salMatch.getLayer4Match();\r
wc = new FlowWildcardsV10(\r
true, true, false, true, true, true, false, true, false, false);\r
match = builder.setWildcards(wc).build();\r
- salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10).build();\r
+ salMatch = convert(match, datapathIdConvertorData).build();\r
etherMatch = salMatch.getEthernetMatch();\r
ipMatch = salMatch.getIpMatch();\r
tcpMatch = (TcpMatch)salMatch.getLayer4Match();\r
// Specify TCP destination port only.\r
Integer dstPort = 6653;\r
match = builder.setTpSrc(null).setTpDst(dstPort).build();\r
- salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10).build();\r
+ salMatch = convert(match, datapathIdConvertorData).build();\r
etherMatch = salMatch.getEthernetMatch();\r
ipMatch = salMatch.getIpMatch();\r
tcpMatch = (TcpMatch)salMatch.getLayer4Match();\r
srcPort = 32767;\r
dstPort = 9999;\r
match = builder.setTpSrc(srcPort).setTpDst(dstPort).build();\r
- salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10).build();\r
+ salMatch = convert(match, datapathIdConvertorData).build();\r
etherMatch = salMatch.getEthernetMatch();\r
ipMatch = salMatch.getIpMatch();\r
tcpMatch = (TcpMatch)salMatch.getLayer4Match();\r
}\r
\r
/**\r
- * UDP match test for\r
- * {@link MatchConvertorImpl#fromOFMatchV10ToSALMatch(MatchV10, BigInteger, OpenflowVersion)}.\r
+ * UDP match test for {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchV10ResponseConvertor#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10, org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData)}\r
*/\r
@Test\r
public void testUdpMatch() {\r
MatchV10 match = builder.build();\r
\r
BigInteger dpid = BigInteger.valueOf(12345L);\r
- Match salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10).build();\r
+ final VersionDatapathIdConvertorData datapathIdConvertorData = new VersionDatapathIdConvertorData(OFConstants.OFP_VERSION_1_0);\r
+ datapathIdConvertorData.setDatapathId(dpid);\r
+\r
+ Match salMatch = convert(match, datapathIdConvertorData).build();\r
EthernetMatch etherMatch = salMatch.getEthernetMatch();\r
Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
Assert.assertEquals("Wrong dl src",\r
// Specify UDP protocol.\r
Short ipProto = 17;\r
match = builder.setNwProto(ipProto).build();\r
- salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10).build();\r
+ salMatch = convert(match, datapathIdConvertorData).build();\r
etherMatch = salMatch.getEthernetMatch();\r
IpMatch ipMatch = salMatch.getIpMatch();\r
Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
wc = new FlowWildcardsV10(\r
true, true, false, true, true, true, false, true, true, false);\r
match = builder.setWildcards(wc).build();\r
- salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10).build();\r
+ salMatch = convert(match, datapathIdConvertorData).build();\r
etherMatch = salMatch.getEthernetMatch();\r
ipMatch = salMatch.getIpMatch();\r
Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
// Specify UDP source port.\r
Integer srcPort = 60000;\r
match = builder.setTpSrc(srcPort).build();\r
- salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10).build();\r
+ salMatch = convert(match, datapathIdConvertorData).build();\r
etherMatch = salMatch.getEthernetMatch();\r
ipMatch = salMatch.getIpMatch();\r
UdpMatch udpMatch = (UdpMatch)salMatch.getLayer4Match();\r
wc = new FlowWildcardsV10(\r
true, true, false, true, true, true, false, true, false, false);\r
match = builder.setWildcards(wc).build();\r
- salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10).build();\r
+ salMatch = convert(match, datapathIdConvertorData).build();\r
etherMatch = salMatch.getEthernetMatch();\r
ipMatch = salMatch.getIpMatch();\r
udpMatch = (UdpMatch)salMatch.getLayer4Match();\r
// Specify UDP destination port only.\r
Integer dstPort = 6653;\r
match = builder.setTpSrc(null).setTpDst(dstPort).build();\r
- salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10).build();\r
+ salMatch = convert(match, datapathIdConvertorData).build();\r
etherMatch = salMatch.getEthernetMatch();\r
ipMatch = salMatch.getIpMatch();\r
udpMatch = (UdpMatch)salMatch.getLayer4Match();\r
srcPort = 32767;\r
dstPort = 9999;\r
match = builder.setTpSrc(srcPort).setTpDst(dstPort).build();\r
- salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10).build();\r
+ salMatch = convert(match, datapathIdConvertorData).build();\r
etherMatch = salMatch.getEthernetMatch();\r
ipMatch = salMatch.getIpMatch();\r
udpMatch = (UdpMatch)salMatch.getLayer4Match();\r
Assert.assertEquals("Wrong ICMPv4 match",\r
null, salMatch.getIcmpv4Match());\r
}\r
+\r
+ private MatchBuilder convert(MatchV10 match, VersionDatapathIdConvertorData data) {\r
+ final Optional<MatchBuilder> salMatchOptional = ConvertorManager.getInstance().convert(match, data);\r
+\r
+ return salMatchOptional.orElse(new MatchBuilder());\r
+ }\r
}\r