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%2FTestFromSalConversionsUtils.java;h=35555daff251abf48a4f0f84dc646489d3c46dcb;hp=81ccb35cd982070bc85a7845dfa10d8787f8e450;hb=9e8add2114ce1c3fd18a860af6e7419270611209;hpb=803d525860fbb1974b65ba5605ba5a9dfe1928a4 diff --git a/opendaylight/md-sal/compatibility/sal-compatibility/src/test/java/org/opendaylight/controller/sal/compatibility/test/TestFromSalConversionsUtils.java b/opendaylight/md-sal/compatibility/sal-compatibility/src/test/java/org/opendaylight/controller/sal/compatibility/test/TestFromSalConversionsUtils.java index 81ccb35cd9..35555daff2 100644 --- a/opendaylight/md-sal/compatibility/sal-compatibility/src/test/java/org/opendaylight/controller/sal/compatibility/test/TestFromSalConversionsUtils.java +++ b/opendaylight/md-sal/compatibility/sal-compatibility/src/test/java/org/opendaylight/controller/sal/compatibility/test/TestFromSalConversionsUtils.java @@ -1,10 +1,10 @@ /* - * Copyright (c) 2013 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, -* and is available at http://www.eclipse.org/legal/epl-v10.html -*/ + * 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, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ package org.opendaylight.controller.sal.compatibility.test; import static org.junit.Assert.assertEquals; @@ -41,6 +41,11 @@ import org.opendaylight.controller.sal.action.SetVlanPcp; import org.opendaylight.controller.sal.action.SwPath; import org.opendaylight.controller.sal.compatibility.MDFlowMapping; 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.Match; import org.opendaylight.controller.sal.match.MatchType; @@ -79,11 +84,11 @@ import com.google.common.net.InetAddresses; public class TestFromSalConversionsUtils { private enum MtchType { - other, ipv4, ipv6, arp, sctp, tcp, udp + other, untagged, ipv4, ipv6, arp, sctp, tcp, udp } @Test - public void testFromSalConversion() { + public void testFromSalConversion() throws ConstructionException { Flow salFlow = prepareSalFlowCommon(); NodeFlow odNodeFlow = MDFlowMapping.flowAdded(salFlow); @@ -93,6 +98,9 @@ public class TestFromSalConversionsUtils { odNodeFlow = MDFlowMapping.flowAdded(prepareSalMatch(salFlow, MtchType.other)); checkOdMatch(odNodeFlow.getMatch(), MtchType.other); + odNodeFlow = MDFlowMapping.flowAdded(prepareSalMatch(salFlow, MtchType.untagged)); + checkOdMatch(odNodeFlow.getMatch(), MtchType.untagged); + odNodeFlow = MDFlowMapping.flowAdded(prepareSalMatch(salFlow, MtchType.arp)); checkOdMatch(odNodeFlow.getMatch(), MtchType.arp); @@ -121,9 +129,9 @@ public class TestFromSalConversionsUtils { Layer3Match layer3Match = match.getLayer3Match(); boolean arpFound = false; if (layer3Match instanceof ArpMatch) { - assertEquals("Source IP address is wrong.", "192.168.100.100", ((ArpMatch) layer3Match) + assertEquals("Source IP address is wrong.", "192.168.100.100/32", ((ArpMatch) layer3Match) .getArpSourceTransportAddress().getValue()); - assertEquals("Destination IP address is wrong.", "192.168.100.101", ((ArpMatch) layer3Match) + assertEquals("Destination IP address is wrong.", "192.168.100.101/32", ((ArpMatch) layer3Match) .getArpTargetTransportAddress().getValue()); assertEquals("Source MAC address is wrong.", "ff:ee:dd:cc:bb:aa", ((ArpMatch) layer3Match) .getArpSourceHardwareAddress().getAddress().getValue()); @@ -139,9 +147,9 @@ public class TestFromSalConversionsUtils { boolean ipv4Found = false; layer3Match = match.getLayer3Match(); if (layer3Match instanceof Ipv4Match) { - assertEquals("Source IP address is wrong.", "192.168.100.102", ((Ipv4Match) layer3Match) + assertEquals("Source IP address is wrong.", "192.168.100.102/32", ((Ipv4Match) layer3Match) .getIpv4Source().getValue()); - assertEquals("Destination IP address is wrong.", "192.168.100.103", ((Ipv4Match) layer3Match) + assertEquals("Destination IP address is wrong.", "192.168.100.103/32", ((Ipv4Match) layer3Match) .getIpv4Destination().getValue()); } assertNotNull("Ipv4 wasn't found", ipv4Found); @@ -152,23 +160,34 @@ public class TestFromSalConversionsUtils { boolean ipv6Found = false; layer3Match = match.getLayer3Match(); if (layer3Match instanceof Ipv6Match) { - assertEquals("Source IP address is wrong.", "2001:db8:85a3::8a2e:370:7335", ((Ipv6Match) layer3Match) + assertEquals("Source IP address is wrong.", "2001:db8:85a3::8a2e:370:7335/128", ((Ipv6Match) layer3Match) .getIpv6Source().getValue()); - assertEquals("Destination IP address is wrong.", "2001:db8:85a3::8a2e:370:7336", + assertEquals("Destination IP address is wrong.", "2001:db8:85a3::8a2e:370:7336/128", ((Ipv6Match) layer3Match).getIpv6Destination().getValue()); } assertNotNull("Ipv6 wasn't found", ipv6Found); break; case other: + assertEquals("Incoming port is wrong.", "openflow:12345:10", match.getInPort().getValue()); assertEquals("Source MAC address is wrong.", "ff:ee:dd:cc:bb:aa", match.getEthernetMatch() .getEthernetSource().getAddress().getValue()); assertEquals("Destinatio MAC address is wrong.", "ff:ee:dd:cc:bb:aa", match.getEthernetMatch() .getEthernetDestination().getAddress().getValue()); + assertEquals("Vlan ID is not present.", Boolean.TRUE, match.getVlanMatch().getVlanId().isVlanIdPresent()); assertEquals("Vlan ID is wrong.", (Integer) 0xfff, match.getVlanMatch().getVlanId().getVlanId().getValue()); assertEquals("Vlan ID priority is wrong.", (short) 0x7, (short) match.getVlanMatch().getVlanPcp() .getValue()); assertEquals("DCSP is wrong.", (short) 0x3f, (short) match.getIpMatch().getIpDscp().getValue()); break; + case untagged: + assertEquals("Source MAC address is wrong.", "ff:ee:dd:cc:bb:aa", match.getEthernetMatch() + .getEthernetSource().getAddress().getValue()); + assertEquals("Destinatio MAC address is wrong.", "ff:ee:dd:cc:bb:aa", match.getEthernetMatch() + .getEthernetDestination().getAddress().getValue()); + assertEquals("Vlan ID is present.", Boolean.FALSE, match.getVlanMatch().getVlanId().isVlanIdPresent()); + assertEquals("Vlan ID is wrong.", Integer.valueOf(0), match.getVlanMatch().getVlanId().getVlanId().getValue()); + assertEquals("DCSP is wrong.", (short) 0x3f, (short) match.getIpMatch().getIpDscp().getValue()); + break; case sctp: boolean sctpFound = false; assertEquals("Wrong protocol", CRUDP, match.getIpMatch().getIpProtocol().byteValue()); @@ -223,45 +242,38 @@ public class TestFromSalConversionsUtils { private void checkOdActions( List actions) { - checkOdAction(actions, FloodActionCase.class, false); - checkOdAction(actions, FloodAllActionCase.class, false); - checkOdAction(actions, HwPathActionCase.class, false); - checkOdAction(actions, LoopbackActionCase.class, false); - checkOdAction(actions, PopVlanActionCase.class, false); - checkOdAction(actions, PushVlanActionCase.class, true); - checkOdAction(actions, SetDlDstActionCase.class, true); - checkOdAction(actions, SetDlSrcActionCase.class, true); - checkOdAction(actions, SetDlTypeActionCase.class, true); - checkOdAction(actions, SetNwTosActionCase.class, true); - checkOdAction(actions, SetNwDstActionCase.class, true); - checkOdAction(actions, SetNwSrcActionCase.class, true); - checkOdAction(actions, SetNextHopActionCase.class, true); - checkOdAction(actions, SetTpDstActionCase.class, true); - checkOdAction(actions, SetTpSrcActionCase.class, true); - checkOdAction(actions, SetVlanCfiActionCase.class, true); - checkOdAction(actions, SetVlanIdActionCase.class, true); - checkOdAction(actions, SetVlanPcpActionCase.class, true); - checkOdAction(actions, SwPathActionCase.class, false); + checkOdAction(actions, FloodActionCase.class); + checkOdAction(actions, FloodAllActionCase.class); + checkOdAction(actions, HwPathActionCase.class); + checkOdAction(actions, LoopbackActionCase.class); + checkOdAction(actions, PopVlanActionCase.class); + checkOdAction(actions, PushVlanActionCase.class); + checkOdAction(actions, SetDlDstActionCase.class); + checkOdAction(actions, SetDlSrcActionCase.class); + checkOdAction(actions, SetDlTypeActionCase.class); + checkOdAction(actions, SetNwTosActionCase.class); + checkOdAction(actions, SetNwDstActionCase.class); + checkOdAction(actions, SetNwSrcActionCase.class); + checkOdAction(actions, SetNextHopActionCase.class); + checkOdAction(actions, SetTpDstActionCase.class); + checkOdAction(actions, SetTpSrcActionCase.class); + checkOdAction(actions, SetVlanCfiActionCase.class); + checkOdAction(actions, SetVlanIdActionCase.class); + checkOdAction(actions, SetVlanPcpActionCase.class); + checkOdAction(actions, SwPathActionCase.class); } private void checkOdAction( - List actions, Class cl, - boolean b) { + List actions, Class cl) { int numOfFoundActions = 0; for (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action action : actions) { - org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action innerAction = action + org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action innerAction = action .getAction(); if (cl.isInstance(innerAction)) { numOfFoundActions++; if (innerAction instanceof PushVlanActionCase) { - assertEquals("Wrong value of cfi in PushVlanAction.", (Integer) 1, ((PushVlanActionCase) innerAction).getPushVlanAction() - .getCfi().getValue()); - assertEquals("Wrong value of pcp in PushVlanAction.", (Integer) 7, - ((PushVlanActionCase) innerAction).getPushVlanAction().getPcp()); assertEquals("Wrong value of tag in PushVlanAction.", (Integer) 0x8100, - ((PushVlanActionCase) innerAction).getPushVlanAction().getTag()); - assertEquals("Wrong value of vlad ID in PushVlanAction.", (Integer) 4095, - ((PushVlanActionCase) innerAction).getPushVlanAction().getVlanId().getValue()); + ((PushVlanActionCase) innerAction).getPushVlanAction().getEthernetType()); } else if (innerAction instanceof SetDlDstActionCase) { assertEquals("Wrong MAC destination address in SetDlDstAction.", "ff:ee:dd:cc:bb:aa", ((SetDlDstActionCase) innerAction).getSetDlDstAction().getAddress().getValue()); @@ -276,18 +288,18 @@ public class TestFromSalConversionsUtils { boolean ipv4AddressFound = false; if (address instanceof Ipv4) { ipv4AddressFound = true; - assertEquals("Wrong IP address type in SetNextHopAction.", "192.168.100.100", ((Ipv4) address) + assertEquals("Wrong IP address type in SetNextHopAction.", "192.168.100.100/32", ((Ipv4) address) .getIpv4Address().getValue()); } assertTrue("Ipv4 address wasn't found.", ipv4AddressFound); } else if (innerAction instanceof SetNwTosActionCase) { - assertEquals("Wrong TOS in SetNwTosAction.", (Integer) 63, ((SetNwTosActionCase) innerAction).getSetNwTosAction().getTos()); + assertEquals("Wrong TOS in SetNwTosAction.", (Integer) 252, ((SetNwTosActionCase) innerAction).getSetNwTosAction().getTos()); } else if (innerAction instanceof SetNwDstActionCase) { Address address = ((SetNwDstActionCase) innerAction).getSetNwDstAction().getAddress(); boolean ipv4AddressFound = false; if (address instanceof Ipv4) { ipv4AddressFound = true; - assertEquals("Wrong IP address type in SetNwDstAction.", "192.168.100.101", ((Ipv4) address) + assertEquals("Wrong IP address type in SetNwDstAction.", "192.168.100.101/32", ((Ipv4) address) .getIpv4Address().getValue()); } assertTrue("Ipv4 address wasn't found.", ipv4AddressFound); @@ -296,7 +308,7 @@ public class TestFromSalConversionsUtils { boolean ipv4AddressFound = false; if (address instanceof Ipv4) { ipv4AddressFound = true; - assertEquals("Wrong IP address type in SetNwSrcAction.", "192.168.100.102", ((Ipv4) address) + assertEquals("Wrong IP address type in SetNwSrcAction.", "192.168.100.102/32", ((Ipv4) address) .getIpv4Address().getValue()); } assertTrue("Ipv4 address wasn't found.", ipv4AddressFound); @@ -334,7 +346,7 @@ public class TestFromSalConversionsUtils { return salFlow; } - private Flow prepareSalMatch(Flow salFlow, MtchType mt) { + private Flow prepareSalMatch(Flow salFlow, MtchType mt) throws ConstructionException { Match salMatch = new Match(); switch (mt) { case arp: @@ -355,12 +367,21 @@ public class TestFromSalConversionsUtils { salMatch.setField(MatchType.NW_DST, InetAddresses.forString("2001:0db8:85a3:0000:0000:8a2e:0370:7336")); break; case other: + Node node = new Node(NodeIDType.OPENFLOW, 12345L); + NodeConnector port = new NodeConnector(NodeConnectorIDType.OPENFLOW, Short.valueOf((short)10), node); + salMatch.setField(MatchType.IN_PORT, port); salMatch.setField(MatchType.DL_SRC, new byte[]{(byte )0xff,(byte )0xee,(byte )0xdd,(byte )0xcc,(byte )0xbb,(byte )0xaa}); salMatch.setField(MatchType.DL_DST, new byte[]{(byte )0xff,(byte )0xee,(byte )0xdd,(byte )0xcc,(byte )0xbb,(byte )0xaa}); salMatch.setField(MatchType.DL_VLAN, (short) 0xfff); salMatch.setField(MatchType.DL_VLAN_PR, (byte) 0x7); salMatch.setField(MatchType.NW_TOS, (byte) 0x3f); break; + case untagged: + salMatch.setField(MatchType.DL_SRC, new byte[]{(byte )0xff,(byte )0xee,(byte )0xdd,(byte )0xcc,(byte )0xbb,(byte )0xaa}); + salMatch.setField(MatchType.DL_DST, new byte[]{(byte )0xff,(byte )0xee,(byte )0xdd,(byte )0xcc,(byte )0xbb,(byte )0xaa}); + salMatch.setField(MatchType.DL_VLAN, MatchType.DL_VLAN_NONE); + salMatch.setField(MatchType.NW_TOS, (byte) 0x3f); + break; case sctp: salMatch.setField(MatchType.NW_PROTO, CRUDP); salMatch.setField(MatchType.TP_SRC, (short) 0xffff); @@ -393,7 +414,7 @@ public class TestFromSalConversionsUtils { salActions.add(new Loopback()); // salActions.add(new Output //TODO: mapping is missing salActions.add(new PopVlan()); - salActions.add(new PushVlan(0x8100, 7, 1, 4095)); + salActions.add(new PushVlan(0x8100)); salActions.add(new SetDlDst(new byte[]{(byte )0xff,(byte )0xee,(byte )0xdd,(byte )0xcc,(byte )0xbb,(byte )0xaa})); salActions.add(new SetDlSrc(new byte[]{(byte )0xff,(byte )0xee,(byte )0xdd,(byte )0xcc,(byte )0xbb,(byte )0xaa})); salActions.add(new SetDlType(513));