/*
- * 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,
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;
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;
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;
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;
// 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);
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",
// be defined
} else if (action instanceof PushVlan) {
assertEquals("Wrong value for action PushVlan for tag.", 0x8100, ((PushVlan) action).getTag());
- assertEquals("Wrong value for action PushVlan for pcp.", 7, ((PushVlan) action).getPcp());
- assertEquals("Wrong value for action PushVlan for cfi.", 1, ((PushVlan) action).getCfi());
- assertEquals("Wrong value for action PushVlan for vlanID.", 4095, ((PushVlan) action).getVlanId());
} else if (action instanceof SetDlDst) {
//assertEquals("Wrong value for action SetDlDst for MAC address.", "3C:A9:F4:00:E0:C8", new String(
// ((SetDlDst) action).getDlAddress()));
//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");
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);
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<Instruction> instructions = Collections.singletonList(applyActions );
InstructionsBuilder instBuilder = new InstructionsBuilder();
-
+
instBuilder.setInstruction(instructions);
-
+
return instBuilder.build();
}
private void prepareActionSetNwTos(SetNwTosActionCaseBuilder wrapper) {
SetNwTosActionBuilder setNwTosActionBuilder = new SetNwTosActionBuilder();
- setNwTosActionBuilder.setTos(63);
+ setNwTosActionBuilder.setTos(252);
wrapper.setSetNwTosAction(setNwTosActionBuilder.build());
}
private void prepareActionSetNwDst(List<Action> 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());
private void prepareActionSetDlType(SetDlTypeActionCaseBuilder wrapper) {
SetDlTypeActionBuilder setDlTypeActionBuilder = new SetDlTypeActionBuilder();
- setDlTypeActionBuilder.setDlType(new EtherType(513l));
+ setDlTypeActionBuilder.setDlType(new EtherType(513L));
wrapper.setSetDlTypeAction(setDlTypeActionBuilder.build());
}
private void prepareActionPushVlan(PushVlanActionCaseBuilder wrapper) {
PushVlanActionBuilder pushVlanActionBuilder = new PushVlanActionBuilder();
- pushVlanActionBuilder.setPcp(7); // 3 bits
- pushVlanActionBuilder.setCfi(new VlanCfi(1)); // 1 bit
- pushVlanActionBuilder.setVlanId(new VlanId(4095));
pushVlanActionBuilder.setTag(0x8100); // 12 bit
wrapper.setPushVlanAction(pushVlanActionBuilder.build());
}
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;
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() {
private EthernetType prepEthType() {
EthernetTypeBuilder ethTypeBuild = new EthernetTypeBuilder();
- ethTypeBuild.setType(new EtherType(0xffffl));
+ ethTypeBuild.setType(new EtherType(0xffffL));
return ethTypeBuild.build();
}