X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fcompatibility%2Fsal-compatibility%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fcompatibility%2Ftest%2FTestToSalConversionsUtils.java;h=7601a7d9cf67ba543d50d8e49b3fb0d6bbe1ae82;hp=ca16c65f5613ac7682a304aa8e171a6701f5675d;hb=17d82f582a6bc13c78be3b19954ff8c021180e93;hpb=f8e5e1a5c2edadc1379a18e706f2258ccc576ed6 diff --git a/opendaylight/md-sal/compatibility/sal-compatibility/src/test/java/org/opendaylight/controller/sal/compatibility/test/TestToSalConversionsUtils.java b/opendaylight/md-sal/compatibility/sal-compatibility/src/test/java/org/opendaylight/controller/sal/compatibility/test/TestToSalConversionsUtils.java index ca16c65f56..7601a7d9cf 100644 --- a/opendaylight/md-sal/compatibility/sal-compatibility/src/test/java/org/opendaylight/controller/sal/compatibility/test/TestToSalConversionsUtils.java +++ b/opendaylight/md-sal/compatibility/sal-compatibility/src/test/java/org/opendaylight/controller/sal/compatibility/test/TestToSalConversionsUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2013-2014 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -22,6 +22,8 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import junit.framework.Assert; + import org.junit.Test; import org.opendaylight.controller.sal.action.Flood; import org.opendaylight.controller.sal.action.FloodAll; @@ -47,6 +49,8 @@ import org.opendaylight.controller.sal.compatibility.ToSalConversionsUtils; import org.opendaylight.controller.sal.core.ConstructionException; import org.opendaylight.controller.sal.core.Node; import org.opendaylight.controller.sal.core.Node.NodeIDType; +import org.opendaylight.controller.sal.core.NodeConnector; +import org.opendaylight.controller.sal.core.NodeConnector.NodeConnectorIDType; import org.opendaylight.controller.sal.flowprogrammer.Flow; import org.opendaylight.controller.sal.match.MatchType; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Dscp; @@ -105,6 +109,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.addr import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv6Builder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowAddedBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.NodeFlow; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match; @@ -114,6 +119,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instru import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId; import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType; import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId; import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp; @@ -147,19 +153,22 @@ public class TestToSalConversionsUtils { // prefix: // od|Od = Open Daylight private enum MtchType { - other, ipv4, ipv6, arp, sctp, tcp, udp + other, untagged, ipv4, ipv6, arp, sctp, tcp, udp } @Test public void testToSalConversion() throws ConstructionException { FlowAddedBuilder odNodeFlowBuilder = new FlowAddedBuilder(); odNodeFlowBuilder = prepareOdFlowCommon(); - + Node node = new Node(NodeIDType.OPENFLOW,(long)1); - + Flow salFlow = ToSalConversionsUtils.toFlow(prepareOdFlow(odNodeFlowBuilder, MtchType.other), node); checkSalMatch(salFlow.getMatch(), MtchType.other); + salFlow = ToSalConversionsUtils.toFlow(prepareOdFlow(odNodeFlowBuilder, MtchType.untagged), node); + checkSalMatch(salFlow.getMatch(), MtchType.untagged); + salFlow = ToSalConversionsUtils.toFlow(prepareOdFlow(odNodeFlowBuilder, MtchType.ipv4), node); checkSalMatch(salFlow.getMatch(), MtchType.ipv4); @@ -181,20 +190,40 @@ public class TestToSalConversionsUtils { checkSalFlow(salFlow); } - private void checkSalMatch(org.opendaylight.controller.sal.match.Match match, MtchType mt) { + /** + * test of {@link ToSalConversionsUtils#fromNodeConnectorRef(Uri, Node)} + * @throws ConstructionException + */ + @Test + public void testFromNodeConnectorRef() throws ConstructionException { + Node node = new Node(NodeIDType.OPENFLOW, 42L); + NodeConnector nodeConnector = ToSalConversionsUtils.fromNodeConnectorRef(new Uri("1"), node); + Assert.assertEquals("OF|1@OF|00:00:00:00:00:00:00:2a", nodeConnector.toString()); + } + + private void checkSalMatch(org.opendaylight.controller.sal.match.Match match, MtchType mt) throws ConstructionException { switch (mt) { case other: - /*assertNotNull("DL_DST isn't equal.", "3C:A9:F4:00:E0:C8", + /*assertNotNull("DL_DST isn't equal.", "3C:A9:F4:00:E0:C8", new String((byte[]) match.getField(MatchType.DL_DST).getValue())); assertEquals("DL_SRC isn't equal.", "24:77:03:7C:C5:F1", new String((byte[]) match.getField(MatchType.DL_SRC).getValue())); */ + Node node = new Node(NodeIDType.OPENFLOW, 12L); + NodeConnector port = new NodeConnector(NodeConnectorIDType.OPENFLOW, Short.valueOf((short)345), node); + assertEquals("IN_PORT isn't equal.", port, match.getField(MatchType.IN_PORT).getValue()); assertEquals("DL_TYPE isn't equal.", (short) 0xffff, (short) match.getField(MatchType.DL_TYPE).getValue()); assertEquals("NW_TOS isn't equal.", (byte) 0x33, (byte) match.getField(MatchType.NW_TOS).getValue()); assertEquals("NW_PROTO isn't equal.", (byte) 0x3f, (byte) match.getField(MatchType.NW_PROTO).getValue()); assertEquals("DL_VLAN isn't equal.", (short) 0xfff, (short) match.getField(MatchType.DL_VLAN).getValue()); assertEquals("DL_VLAN_PR isn't equal.", (byte) 0x7, (byte) match.getField(MatchType.DL_VLAN_PR).getValue()); break; + case untagged: + assertEquals("DL_TYPE isn't equal.", (short) 0xffff, (short) match.getField(MatchType.DL_TYPE).getValue()); + assertEquals("NW_TOS isn't equal.", (byte) 0x33, (byte) match.getField(MatchType.NW_TOS).getValue()); + assertEquals("NW_PROTO isn't equal.", (byte) 0x3f, (byte) match.getField(MatchType.NW_PROTO).getValue()); + assertEquals("DL_VLAN isn't equal.", MatchType.DL_VLAN_NONE, (short) match.getField(MatchType.DL_VLAN).getValue()); + break; case arp: /* assertEquals("DL_SRC isn't equal.", "22:44:66:88:AA:CC", @@ -311,7 +340,7 @@ public class TestToSalConversionsUtils { //assertEquals("Wrong value for action SetDlSrc for MAC address.", "24:77:03:7C:C5:F1", new String( // ((SetDlSrc) action).getDlAddress())); } else if (action instanceof SetDlType) { - assertEquals("Wrong value for action SetDlType for.", 513l, ((SetDlType) action).getDlType()); + assertEquals("Wrong value for action SetDlType for.", 513L, ((SetDlType) action).getDlType()); } else if (action instanceof SetNextHop) { InetAddress inetAddress = ((SetNextHop) action).getAddress(); checkIpAddresses(inetAddress, "192.168.100.100", "2001:db8:85a3::8a2e:370:7334"); @@ -347,7 +376,7 @@ public class TestToSalConversionsUtils { private FlowAddedBuilder prepareOdFlowCommon() { FlowAddedBuilder odNodeFlowBuilder = new FlowAddedBuilder(); - odNodeFlowBuilder.setCookie(new BigInteger("9223372036854775807")); + odNodeFlowBuilder.setCookie(new FlowCookie(new BigInteger("9223372036854775807"))); odNodeFlowBuilder.setHardTimeout(32767); odNodeFlowBuilder.setIdleTimeout(32767); odNodeFlowBuilder.setPriority(32767); @@ -430,14 +459,14 @@ public class TestToSalConversionsUtils { odActions.add(new ActionBuilder().setAction(setVlanPcpActionBuilder.build()).build()); odActions.add(new ActionBuilder().setAction(swPathActionBuilder.build()).build()); - + ApplyActionsCase innerInst = new ApplyActionsCaseBuilder().setApplyActions(new ApplyActionsBuilder().setAction(odActions).build()).build(); Instruction applyActions = new InstructionBuilder().setInstruction(innerInst).build(); List instructions = Collections.singletonList(applyActions ); InstructionsBuilder instBuilder = new InstructionsBuilder(); - + instBuilder.setInstruction(instructions); - + return instBuilder.build(); } @@ -491,7 +520,7 @@ public class TestToSalConversionsUtils { private void prepareActionSetNwDst(List odActions) { // test case for IPv4 - + SetNwDstActionBuilder setNwDstActionBuilderIpv4 = new SetNwDstActionBuilder(); setNwDstActionBuilderIpv4.setAddress(prapareIpv4Address("192.168.100.101")); odActions.add(new ActionBuilder().setAction(new SetNwDstActionCaseBuilder().setSetNwDstAction(setNwDstActionBuilderIpv4.build()).build()).build()); @@ -528,7 +557,7 @@ public class TestToSalConversionsUtils { private void prepareActionSetDlType(SetDlTypeActionCaseBuilder wrapper) { SetDlTypeActionBuilder setDlTypeActionBuilder = new SetDlTypeActionBuilder(); - setDlTypeActionBuilder.setDlType(new EtherType(513l)); + setDlTypeActionBuilder.setDlType(new EtherType(513L)); wrapper.setSetDlTypeAction(setDlTypeActionBuilder.build()); } @@ -563,10 +592,16 @@ public class TestToSalConversionsUtils { MatchBuilder odMatchBuilder = new MatchBuilder(); switch (mt) { case other: + odMatchBuilder.setInPort(new NodeConnectorId("openflow:12:345")); odMatchBuilder.setEthernetMatch(prepEthernetMatch()); odMatchBuilder.setIpMatch(prepIpMatch()); odMatchBuilder.setVlanMatch(prepVlanMatch()); break; + case untagged: + odMatchBuilder.setEthernetMatch(prepEthernetMatch()); + odMatchBuilder.setIpMatch(prepIpMatch()); + odMatchBuilder.setVlanMatch(prepVlanNoneMatch()); + break; case ipv4: odMatchBuilder.setLayer3Match(prepLayer3MatchIpv4()); break; @@ -649,11 +684,20 @@ public class TestToSalConversionsUtils { VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder(); VlanIdBuilder vlanIdBuilder = new VlanIdBuilder().setVlanId(new VlanId(0xfff)); - vlanMatchBuilder.setVlanId(vlanIdBuilder.build()); + vlanMatchBuilder.setVlanId(vlanIdBuilder.setVlanIdPresent(true).build()); vlanMatchBuilder.setVlanPcp(new VlanPcp((short) 0x7)); return vlanMatchBuilder.build(); + } + + private VlanMatch prepVlanNoneMatch() { + VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder(); + VlanIdBuilder vlanIdBuilder = new VlanIdBuilder(). + setVlanIdPresent(false); + vlanMatchBuilder.setVlanId(vlanIdBuilder.build()); + + return vlanMatchBuilder.build(); } private IpMatch prepIpMatch() { @@ -673,7 +717,7 @@ public class TestToSalConversionsUtils { private EthernetType prepEthType() { EthernetTypeBuilder ethTypeBuild = new EthernetTypeBuilder(); - ethTypeBuild.setType(new EtherType(0xffffl)); + ethTypeBuild.setType(new EtherType(0xffffL)); return ethTypeBuild.build(); }