use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder in project openflowplugin by opendaylight.
the class ActionConvertorV13Test method testGetActions.
/**
* Test {@link ActionConvertor#convert(List, ActionConvertorData)} }.
*/
@Test
public void testGetActions() {
org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder actionBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder();
SetVlanPcpActionCaseBuilder vlanPcpCaseBuilder = new SetVlanPcpActionCaseBuilder();
SetVlanPcpActionBuilder pcpBuilder = new SetVlanPcpActionBuilder();
pcpBuilder.setVlanPcp(new VlanPcp((short) 7));
vlanPcpCaseBuilder.setSetVlanPcpAction(pcpBuilder.build());
actionBuilder.setAction(vlanPcpCaseBuilder.build());
actionBuilder.setOrder(0);
List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> salActions = new ArrayList<>();
salActions.add(actionBuilder.build());
actionBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder();
StripVlanActionCaseBuilder stripCaseBuilder = new StripVlanActionCaseBuilder();
StripVlanActionBuilder stripBuilder = new StripVlanActionBuilder();
stripCaseBuilder.setStripVlanAction(stripBuilder.build());
actionBuilder.setAction(stripCaseBuilder.build());
actionBuilder.setOrder(1);
salActions.add(actionBuilder.build());
actionBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder();
SetDlDstActionCaseBuilder dlDstCaseBuilder = new SetDlDstActionCaseBuilder();
SetDlDstActionBuilder dlDstBuilder = new SetDlDstActionBuilder();
dlDstBuilder.setAddress(new MacAddress("00:00:00:00:00:06"));
dlDstCaseBuilder.setSetDlDstAction(dlDstBuilder.build());
actionBuilder.setAction(dlDstCaseBuilder.build());
actionBuilder.setOrder(2);
salActions.add(actionBuilder.build());
actionBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder();
SetDlSrcActionCaseBuilder dlSrcCaseBuilder = new SetDlSrcActionCaseBuilder();
SetDlSrcActionBuilder dlSrcBuilder = new SetDlSrcActionBuilder();
dlSrcBuilder.setAddress(new MacAddress("00:00:00:00:00:05"));
dlSrcCaseBuilder.setSetDlSrcAction(dlSrcBuilder.build());
actionBuilder.setAction(dlSrcCaseBuilder.build());
actionBuilder.setOrder(3);
salActions.add(actionBuilder.build());
actionBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder();
SetNwSrcActionCaseBuilder nwSrcCaseBuilder = new SetNwSrcActionCaseBuilder();
SetNwSrcActionBuilder nwSrcBuilder = new SetNwSrcActionBuilder();
Ipv4Builder ipv4Builder = new Ipv4Builder();
/* Correct canonical form for v4 prefix!!! */
ipv4Builder.setIpv4Address(new Ipv4Prefix("10.0.0.0/24"));
nwSrcBuilder.setAddress(ipv4Builder.build());
nwSrcCaseBuilder.setSetNwSrcAction(nwSrcBuilder.build());
actionBuilder.setAction(nwSrcCaseBuilder.build());
actionBuilder.setOrder(4);
salActions.add(actionBuilder.build());
actionBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder();
SetNwDstActionBuilder nwDstBuilder = new SetNwDstActionBuilder();
ipv4Builder = new Ipv4Builder();
ipv4Builder.setIpv4Address(new Ipv4Prefix("10.0.0.2/32"));
nwDstBuilder.setAddress(ipv4Builder.build());
SetNwDstActionCaseBuilder nwDstCaseBuilder = new SetNwDstActionCaseBuilder();
nwDstCaseBuilder.setSetNwDstAction(nwDstBuilder.build());
actionBuilder.setAction(nwDstCaseBuilder.build());
actionBuilder.setOrder(5);
salActions.add(actionBuilder.build());
actionBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder();
SetTpSrcActionCaseBuilder tpSrcCaseBuilder = new SetTpSrcActionCaseBuilder();
SetTpSrcActionBuilder tpSrcBuilder = new SetTpSrcActionBuilder();
tpSrcBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(54));
tpSrcCaseBuilder.setSetTpSrcAction(tpSrcBuilder.build());
actionBuilder.setAction(tpSrcCaseBuilder.build());
actionBuilder.setOrder(6);
salActions.add(actionBuilder.build());
actionBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder();
SetTpDstActionCaseBuilder tpDstCaseBuilder = new SetTpDstActionCaseBuilder();
SetTpDstActionBuilder tpDstBuilder = new SetTpDstActionBuilder();
tpDstBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(45));
tpDstCaseBuilder.setSetTpDstAction(tpDstBuilder.build());
actionBuilder.setAction(tpDstCaseBuilder.build());
actionBuilder.setOrder(7);
salActions.add(actionBuilder.build());
actionBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder();
SetNwTosActionCaseBuilder tosCaseBuilder = new SetNwTosActionCaseBuilder();
SetNwTosActionBuilder tosBuilder = new SetNwTosActionBuilder();
tosBuilder.setTos(16);
tosCaseBuilder.setSetNwTosAction(tosBuilder.build());
actionBuilder.setAction(tosCaseBuilder.build());
actionBuilder.setOrder(8);
salActions.add(actionBuilder.build());
actionBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder();
SetVlanIdActionCaseBuilder vlanIdCaseBuilder = new SetVlanIdActionCaseBuilder();
SetVlanIdActionBuilder vlanIdBuilder = new SetVlanIdActionBuilder();
vlanIdBuilder.setVlanId(new VlanId(22));
vlanIdCaseBuilder.setSetVlanIdAction(vlanIdBuilder.build());
actionBuilder.setAction(vlanIdCaseBuilder.build());
actionBuilder.setOrder(9);
salActions.add(actionBuilder.build());
actionBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder();
nwSrcCaseBuilder = new SetNwSrcActionCaseBuilder();
nwSrcBuilder = new SetNwSrcActionBuilder();
Ipv6Builder ipv6Builder = new Ipv6Builder();
/* Use canonical form, 00:00:0000 is not a valid v6 notation */
ipv6Builder.setIpv6Address(new Ipv6Prefix("::5/128"));
nwSrcBuilder.setAddress(ipv6Builder.build());
nwSrcCaseBuilder.setSetNwSrcAction(nwSrcBuilder.build());
actionBuilder.setAction(nwSrcCaseBuilder.build());
actionBuilder.setOrder(10);
salActions.add(actionBuilder.build());
actionBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder();
nwDstCaseBuilder = new SetNwDstActionCaseBuilder();
nwDstBuilder = new SetNwDstActionBuilder();
ipv6Builder = new Ipv6Builder();
/* Use canonical form, 00:00:0006/64 is not a valid v6 notation - this equates to ::/64 */
ipv6Builder.setIpv6Address(new Ipv6Prefix("::/64"));
nwDstBuilder.setAddress(ipv6Builder.build());
nwDstCaseBuilder.setSetNwDstAction(nwDstBuilder.build());
actionBuilder.setAction(nwDstCaseBuilder.build());
actionBuilder.setOrder(11);
salActions.add(actionBuilder.build());
IpMatchBuilder ipMatchBld = new IpMatchBuilder().setIpProtocol((short) 6);
MatchBuilder matchBld = new MatchBuilder().setIpMatch(ipMatchBld.build());
FlowBuilder flowBld = new FlowBuilder().setMatch(matchBld.build());
Flow flow = flowBld.build();
ActionConvertorData data = new ActionConvertorData(OFConstants.OFP_VERSION_1_3);
data.setDatapathId(new BigInteger("42"));
data.setIpProtocol(FlowConvertorUtil.getIpProtocolFromFlow(flow));
Optional<List<Action>> actionsOptional = convertorManager.convert(salActions, data);
List<Action> actions = actionsOptional.orElse(Collections.emptyList());
Assert.assertEquals("Wrong number of actions", 12, actions.size());
Action action = actions.get(0);
Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common" + ".action.rev150203.action.grouping.action.choice.SetFieldCase", action.getActionChoice().getImplementedInterface().getName());
org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCase setFieldCase = (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCase) action.getActionChoice();
MatchEntry entry = setFieldCase.getSetFieldAction().getMatchEntry().get(0);
checkEntryHeader(entry, org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.VlanPcp.class, false);
Assert.assertEquals("Wrong vlan pcp", 7, ((VlanPcpCase) entry.getMatchEntryValue()).getVlanPcp().getVlanPcp().intValue());
action = actions.get(1);
Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common" + ".action.rev150203.action.grouping.action.choice.SetFieldCase", action.getActionChoice().getImplementedInterface().getName());
setFieldCase = (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCase) action.getActionChoice();
entry = setFieldCase.getSetFieldAction().getMatchEntry().get(0);
checkEntryHeader(entry, org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.VlanVid.class, false);
Assert.assertEquals("Wrong vlan vid", 0, ((VlanVidCase) entry.getMatchEntryValue()).getVlanVid().getVlanVid().intValue());
Assert.assertEquals("Wrong cfi bit", true, ((VlanVidCase) entry.getMatchEntryValue()).getVlanVid().isCfiBit());
action = actions.get(2);
Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common" + ".action.rev150203.action.grouping.action.choice.SetFieldCase", action.getActionChoice().getImplementedInterface().getName());
setFieldCase = (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCase) action.getActionChoice();
entry = setFieldCase.getSetFieldAction().getMatchEntry().get(0);
checkEntryHeader(entry, org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.EthDst.class, false);
Assert.assertEquals("Wrong dl dst", "00:00:00:00:00:06", ((EthDstCase) entry.getMatchEntryValue()).getEthDst().getMacAddress().getValue());
action = actions.get(3);
setFieldCase = (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCase) action.getActionChoice();
Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common" + ".action.rev150203.action.grouping.action.choice.SetFieldCase", action.getActionChoice().getImplementedInterface().getName());
entry = setFieldCase.getSetFieldAction().getMatchEntry().get(0);
checkEntryHeader(entry, org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.EthSrc.class, false);
Assert.assertEquals("Wrong dl src", "00:00:00:00:00:05", ((EthSrcCase) entry.getMatchEntryValue()).getEthSrc().getMacAddress().getValue());
action = actions.get(4);
setFieldCase = (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCase) action.getActionChoice();
Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common" + ".action.rev150203.action.grouping.action.choice.SetFieldCase", action.getActionChoice().getImplementedInterface().getName());
entry = setFieldCase.getSetFieldAction().getMatchEntry().get(0);
checkEntryHeader(entry, org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv4Src.class, false);
Assert.assertEquals("Wrong ipv4 src", "10.0.0.0", ((Ipv4SrcCase) entry.getMatchEntryValue()).getIpv4Src().getIpv4Address().getValue());
action = actions.get(5);
setFieldCase = (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCase) action.getActionChoice();
Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common" + ".action.rev150203.action.grouping.action.choice.SetFieldCase", action.getActionChoice().getImplementedInterface().getName());
entry = setFieldCase.getSetFieldAction().getMatchEntry().get(0);
checkEntryHeader(entry, org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv4Dst.class, false);
Assert.assertEquals("Wrong ipv4 dst", "10.0.0.2", ((Ipv4DstCase) entry.getMatchEntryValue()).getIpv4Dst().getIpv4Address().getValue());
action = actions.get(6);
setFieldCase = (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCase) action.getActionChoice();
Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common" + ".action.rev150203.action.grouping.action.choice.SetFieldCase", action.getActionChoice().getImplementedInterface().getName());
entry = setFieldCase.getSetFieldAction().getMatchEntry().get(0);
checkEntryHeader(entry, org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.TcpSrc.class, false);
Assert.assertEquals("Wrong tcp src", 54, ((TcpSrcCase) entry.getMatchEntryValue()).getTcpSrc().getPort().getValue().intValue());
action = actions.get(7);
setFieldCase = (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCase) action.getActionChoice();
Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common" + ".action.rev150203.action.grouping.action.choice.SetFieldCase", action.getActionChoice().getImplementedInterface().getName());
entry = setFieldCase.getSetFieldAction().getMatchEntry().get(0);
checkEntryHeader(entry, org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.TcpDst.class, false);
Assert.assertEquals("Wrong tcp dst", 45, ((TcpDstCase) entry.getMatchEntryValue()).getTcpDst().getPort().getValue().intValue());
action = actions.get(8);
setFieldCase = (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCase) action.getActionChoice();
Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common" + ".action.rev150203.action.grouping.action.choice.SetFieldCase", action.getActionChoice().getImplementedInterface().getName());
entry = setFieldCase.getSetFieldAction().getMatchEntry().get(0);
checkEntryHeader(entry, org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.IpDscp.class, false);
Assert.assertEquals("Wrong ip dscp", 4, ((IpDscpCase) entry.getMatchEntryValue()).getIpDscp().getDscp().getValue().intValue());
action = actions.get(9);
setFieldCase = (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCase) action.getActionChoice();
Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common" + ".action.rev150203.action.grouping.action.choice.SetFieldCase", action.getActionChoice().getImplementedInterface().getName());
entry = setFieldCase.getSetFieldAction().getMatchEntry().get(0);
checkEntryHeader(entry, org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.VlanVid.class, false);
Assert.assertEquals("Wrong vlan id", 22, ((VlanVidCase) entry.getMatchEntryValue()).getVlanVid().getVlanVid().intValue());
Assert.assertEquals("Wrong cfi bit", true, ((VlanVidCase) entry.getMatchEntryValue()).getVlanVid().isCfiBit());
action = actions.get(10);
setFieldCase = (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCase) action.getActionChoice();
Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common" + ".action.rev150203.action.grouping.action.choice.SetFieldCase", action.getActionChoice().getImplementedInterface().getName());
entry = setFieldCase.getSetFieldAction().getMatchEntry().get(0);
checkEntryHeader(entry, org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv6Src.class, false);
Assert.assertEquals("Wrong ipv6 src", "::5", ((Ipv6SrcCase) entry.getMatchEntryValue()).getIpv6Src().getIpv6Address().getValue());
action = actions.get(11);
setFieldCase = (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCase) action.getActionChoice();
Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common" + ".action.rev150203.action.grouping.action.choice.SetFieldCase", action.getActionChoice().getImplementedInterface().getName());
entry = setFieldCase.getSetFieldAction().getMatchEntry().get(0);
checkEntryHeader(entry, org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv6Dst.class, false);
Assert.assertEquals("Wrong ipv6 dst", "::", ((Ipv6DstCase) entry.getMatchEntryValue()).getIpv6Dst().getIpv6Address().getValue());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder in project openflowplugin by opendaylight.
the class MatchConvertorTest method testConversionWithMasks.
@Test
public void testConversionWithMasks() {
MatchBuilder builder = new MatchBuilder();
MetadataBuilder metadataBuilder = new MetadataBuilder();
metadataBuilder.setMetadata(new BigInteger("3"));
metadataBuilder.setMetadataMask(new BigInteger("15"));
builder.setMetadata(metadataBuilder.build());
EthernetMatchBuilder ethernetBuilder = new EthernetMatchBuilder();
EthernetSourceBuilder ethSrcBuilder = new EthernetSourceBuilder();
ethSrcBuilder.setAddress(new MacAddress("00:00:00:00:00:05"));
ethSrcBuilder.setMask(new MacAddress("00:00:00:00:00:08"));
ethernetBuilder.setEthernetSource(ethSrcBuilder.build());
EthernetDestinationBuilder ethDstBuilder = new EthernetDestinationBuilder();
ethDstBuilder.setAddress(new MacAddress("00:00:00:00:00:06"));
ethDstBuilder.setMask(new MacAddress("00:00:00:00:00:09"));
ethernetBuilder.setEthernetDestination(ethDstBuilder.build());
builder.setEthernetMatch(ethernetBuilder.build());
VlanMatchBuilder vlanBuilder = new VlanMatchBuilder();
VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
vlanIdBuilder.setVlanId(new VlanId(0));
vlanIdBuilder.setVlanIdPresent(true);
vlanBuilder.setVlanId(vlanIdBuilder.build());
builder.setVlanMatch(vlanBuilder.build());
ProtocolMatchFieldsBuilder protoBuilder = new ProtocolMatchFieldsBuilder();
PbbBuilder pbbBuilder = new PbbBuilder();
pbbBuilder.setPbbIsid(20L);
pbbBuilder.setPbbMask(8L);
protoBuilder.setPbb(pbbBuilder.build());
builder.setProtocolMatchFields(protoBuilder.build());
TunnelBuilder tunnelBuilder = new TunnelBuilder();
tunnelBuilder.setTunnelId(new BigInteger("21"));
tunnelBuilder.setTunnelMask(new BigInteger("14"));
builder.setTunnel(tunnelBuilder.build());
Ipv4MatchBuilder ipv4MatchBuilder = new Ipv4MatchBuilder();
ipv4MatchBuilder.setIpv4Source(new Ipv4Prefix("10.0.0.0/24"));
ipv4MatchBuilder.setIpv4Destination(new Ipv4Prefix("10.0.0.0/8"));
builder.setLayer3Match(ipv4MatchBuilder.build());
Match match = builder.build();
Optional<List<MatchEntry>> entriesOptional = converterManager.convert(match, new VersionConvertorData(OFConstants.OFP_VERSION_1_3));
List<MatchEntry> entries = entriesOptional.get();
Assert.assertEquals("Wrong entries size", 8, entries.size());
MatchEntry entry = entries.get(0);
checkEntryHeader(entry, Metadata.class, true);
Assert.assertArrayEquals("Wrong metadata", new byte[] { 0, 0, 0, 0, 0, 0, 0, 3 }, ((MetadataCase) entry.getMatchEntryValue()).getMetadata().getMetadata());
Assert.assertArrayEquals("Wrong metadata mask", new byte[] { 0, 0, 0, 0, 0, 0, 0, 15 }, ((MetadataCase) entry.getMatchEntryValue()).getMetadata().getMask());
entry = entries.get(1);
checkEntryHeader(entry, EthDst.class, true);
Assert.assertEquals("Wrong eth dst", new MacAddress("00:00:00:00:00:06"), ((EthDstCase) entry.getMatchEntryValue()).getEthDst().getMacAddress());
Assert.assertArrayEquals("Wrong eth dst mask", new byte[] { 0, 0, 0, 0, 0, 9 }, ((EthDstCase) entry.getMatchEntryValue()).getEthDst().getMask());
entry = entries.get(2);
checkEntryHeader(entry, EthSrc.class, true);
Assert.assertEquals("Wrong eth src", new MacAddress("00:00:00:00:00:05"), ((EthSrcCase) entry.getMatchEntryValue()).getEthSrc().getMacAddress());
Assert.assertArrayEquals("Wrong eth src mask", new byte[] { 0, 0, 0, 0, 0, 8 }, ((EthSrcCase) entry.getMatchEntryValue()).getEthSrc().getMask());
entry = entries.get(3);
checkEntryHeader(entry, VlanVid.class, true);
Assert.assertEquals("Wrong vlan id", 0, ((VlanVidCase) entry.getMatchEntryValue()).getVlanVid().getVlanVid().intValue());
Assert.assertEquals("Wrong cfi bit", true, ((VlanVidCase) entry.getMatchEntryValue()).getVlanVid().isCfiBit());
Assert.assertArrayEquals("Wrong vlanId mask", new byte[] { 16, 0 }, ((VlanVidCase) entry.getMatchEntryValue()).getVlanVid().getMask());
entry = entries.get(4);
checkEntryHeader(entry, Ipv4Src.class, true);
Assert.assertEquals("Wrong ipv4 src", "10.0.0.0", ((Ipv4SrcCase) entry.getMatchEntryValue()).getIpv4Src().getIpv4Address().getValue());
Assert.assertArrayEquals("Wrong ipv4 src mask", new byte[] { (byte) 255, (byte) 255, (byte) 255, 0 }, ((Ipv4SrcCase) entry.getMatchEntryValue()).getIpv4Src().getMask());
entry = entries.get(5);
checkEntryHeader(entry, Ipv4Dst.class, true);
Assert.assertEquals("Wrong ipv4 dst", "10.0.0.0", ((Ipv4DstCase) entry.getMatchEntryValue()).getIpv4Dst().getIpv4Address().getValue());
Assert.assertArrayEquals("Wrong ipv4 dst mask", new byte[] { (byte) 255, 0, 0, 0 }, ((Ipv4DstCase) entry.getMatchEntryValue()).getIpv4Dst().getMask());
entry = entries.get(6);
checkEntryHeader(entry, PbbIsid.class, true);
Assert.assertEquals("Wrong pbb isid", 20, ((PbbIsidCase) entry.getMatchEntryValue()).getPbbIsid().getIsid().intValue());
Assert.assertArrayEquals("Wrong pbb isid mask", new byte[] { 0, 0, 8 }, ((PbbIsidCase) entry.getMatchEntryValue()).getPbbIsid().getMask());
entry = entries.get(7);
checkEntryHeader(entry, TunnelId.class, true);
Assert.assertArrayEquals("Wrong tunnel id", new byte[] { 0, 0, 0, 0, 0, 0, 0, 21 }, ((TunnelIdCase) entry.getMatchEntryValue()).getTunnelId().getTunnelId());
Assert.assertArrayEquals("Wrong tunnel id mask", new byte[] { 0, 0, 0, 0, 0, 0, 0, 14 }, ((TunnelIdCase) entry.getMatchEntryValue()).getTunnelId().getMask());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder in project openflowplugin by opendaylight.
the class MatchConvertorTest method testConversion.
@Test
public void testConversion() {
MatchBuilder builder = new MatchBuilder();
builder.setInPort(new NodeConnectorId("openflow:42:1"));
builder.setInPhyPort(new NodeConnectorId("openflow:42:2"));
MetadataBuilder metadataBuilder = new MetadataBuilder();
metadataBuilder.setMetadata(new BigInteger("3"));
builder.setMetadata(metadataBuilder.build());
EthernetMatchBuilder ethernetBuilder = new EthernetMatchBuilder();
EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
ethTypeBuilder.setType(new EtherType(4L));
ethernetBuilder.setEthernetType(ethTypeBuilder.build());
EthernetSourceBuilder ethSrcBuilder = new EthernetSourceBuilder();
ethSrcBuilder.setAddress(new MacAddress("00:00:00:00:00:05"));
ethernetBuilder.setEthernetSource(ethSrcBuilder.build());
EthernetDestinationBuilder ethDstBuilder = new EthernetDestinationBuilder();
ethDstBuilder.setAddress(new MacAddress("00:00:00:00:00:06"));
ethernetBuilder.setEthernetDestination(ethDstBuilder.build());
builder.setEthernetMatch(ethernetBuilder.build());
VlanMatchBuilder vlanBuilder = new VlanMatchBuilder();
VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
vlanIdBuilder.setVlanId(new VlanId(7));
vlanIdBuilder.setVlanIdPresent(true);
vlanBuilder.setVlanId(vlanIdBuilder.build());
vlanBuilder.setVlanPcp(new VlanPcp((short) 7));
builder.setVlanMatch(vlanBuilder.build());
IpMatchBuilder ipMatchBuilder = new IpMatchBuilder();
ipMatchBuilder.setIpDscp(new Dscp((short) 8));
ipMatchBuilder.setIpEcn((short) 9);
ipMatchBuilder.setIpProtocol((short) 10);
builder.setIpMatch(ipMatchBuilder.build());
TcpMatchBuilder tcpMatchBuilder = new TcpMatchBuilder();
tcpMatchBuilder.setTcpSourcePort(new PortNumber(11));
tcpMatchBuilder.setTcpDestinationPort(new PortNumber(12));
builder.setLayer4Match(tcpMatchBuilder.build());
Icmpv4MatchBuilder icmpv4Builder = new Icmpv4MatchBuilder();
icmpv4Builder.setIcmpv4Type((short) 13);
icmpv4Builder.setIcmpv4Code((short) 14);
builder.setIcmpv4Match(icmpv4Builder.build());
Icmpv6MatchBuilder icmpv6Builder = new Icmpv6MatchBuilder();
icmpv6Builder.setIcmpv6Type((short) 15);
icmpv6Builder.setIcmpv6Code((short) 16);
builder.setIcmpv6Match(icmpv6Builder.build());
ProtocolMatchFieldsBuilder protoBuilder = new ProtocolMatchFieldsBuilder();
protoBuilder.setMplsLabel(17L);
protoBuilder.setMplsTc((short) 18);
protoBuilder.setMplsBos((short) 19);
PbbBuilder pbbBuilder = new PbbBuilder();
pbbBuilder.setPbbIsid(20L);
protoBuilder.setPbb(pbbBuilder.build());
builder.setProtocolMatchFields(protoBuilder.build());
TunnelBuilder tunnelBuilder = new TunnelBuilder();
tunnelBuilder.setTunnelId(new BigInteger("21"));
builder.setTunnel(tunnelBuilder.build());
Ipv4MatchBuilder ipv4MatchBuilder = new Ipv4MatchBuilder();
ipv4MatchBuilder.setIpv4Source(new Ipv4Prefix("10.0.0.1/32"));
ipv4MatchBuilder.setIpv4Destination(new Ipv4Prefix("10.0.0.2/32"));
builder.setLayer3Match(ipv4MatchBuilder.build());
Match match = builder.build();
Optional<List<MatchEntry>> entriesOptional = converterManager.convert(match, new VersionConvertorData(OFConstants.OFP_VERSION_1_3));
List<MatchEntry> entries = entriesOptional.get();
Assert.assertEquals("Wrong entries size", 24, entries.size());
MatchEntry entry = entries.get(0);
checkEntryHeader(entry, InPort.class, false);
Assert.assertEquals("Wrong in port", 1, ((InPortCase) entry.getMatchEntryValue()).getInPort().getPortNumber().getValue().intValue());
entry = entries.get(1);
checkEntryHeader(entry, InPhyPort.class, false);
Assert.assertEquals("Wrong in phy port", 2, ((InPhyPortCase) entry.getMatchEntryValue()).getInPhyPort().getPortNumber().getValue().intValue());
entry = entries.get(2);
checkEntryHeader(entry, Metadata.class, false);
Assert.assertArrayEquals("Wrong metadata", new byte[] { 0, 0, 0, 0, 0, 0, 0, 3 }, ((MetadataCase) entry.getMatchEntryValue()).getMetadata().getMetadata());
entry = entries.get(3);
checkEntryHeader(entry, EthDst.class, false);
Assert.assertEquals("Wrong eth dst", new MacAddress("00:00:00:00:00:06"), ((EthDstCase) entry.getMatchEntryValue()).getEthDst().getMacAddress());
entry = entries.get(4);
checkEntryHeader(entry, EthSrc.class, false);
Assert.assertEquals("Wrong eth src", new MacAddress("00:00:00:00:00:05"), ((EthSrcCase) entry.getMatchEntryValue()).getEthSrc().getMacAddress());
entry = entries.get(5);
checkEntryHeader(entry, EthType.class, false);
Assert.assertEquals("Wrong eth type", 4, ((EthTypeCase) entry.getMatchEntryValue()).getEthType().getEthType().getValue().intValue());
entry = entries.get(6);
checkEntryHeader(entry, VlanVid.class, false);
Assert.assertEquals("Wrong vlan id", 7, ((VlanVidCase) entry.getMatchEntryValue()).getVlanVid().getVlanVid().intValue());
Assert.assertEquals("Wrong cfi bit", true, ((VlanVidCase) entry.getMatchEntryValue()).getVlanVid().isCfiBit());
entry = entries.get(7);
checkEntryHeader(entry, org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.VlanPcp.class, false);
Assert.assertEquals("Wrong vlan pcp", 7, ((VlanPcpCase) entry.getMatchEntryValue()).getVlanPcp().getVlanPcp().intValue());
entry = entries.get(8);
checkEntryHeader(entry, IpDscp.class, false);
Assert.assertEquals("Wrong ip dscp", 8, ((IpDscpCase) entry.getMatchEntryValue()).getIpDscp().getDscp().getValue().intValue());
entry = entries.get(9);
checkEntryHeader(entry, IpEcn.class, false);
Assert.assertEquals("Wrong ip ecn", 9, ((IpEcnCase) entry.getMatchEntryValue()).getIpEcn().getEcn().intValue());
entry = entries.get(10);
checkEntryHeader(entry, IpProto.class, false);
Assert.assertEquals("Wrong ip proto", 10, ((IpProtoCase) entry.getMatchEntryValue()).getIpProto().getProtocolNumber().intValue());
entry = entries.get(11);
checkEntryHeader(entry, TcpSrc.class, false);
Assert.assertEquals("Wrong tcp src", 11, ((TcpSrcCase) entry.getMatchEntryValue()).getTcpSrc().getPort().getValue().intValue());
entry = entries.get(12);
checkEntryHeader(entry, TcpDst.class, false);
Assert.assertEquals("Wrong tcp dst", 12, ((TcpDstCase) entry.getMatchEntryValue()).getTcpDst().getPort().getValue().intValue());
entry = entries.get(13);
checkEntryHeader(entry, Icmpv4Type.class, false);
Assert.assertEquals("Wrong icmpv4 type", 13, ((Icmpv4TypeCase) entry.getMatchEntryValue()).getIcmpv4Type().getIcmpv4Type().intValue());
entry = entries.get(14);
checkEntryHeader(entry, Icmpv4Code.class, false);
Assert.assertEquals("Wrong icmpv4 code", 14, ((Icmpv4CodeCase) entry.getMatchEntryValue()).getIcmpv4Code().getIcmpv4Code().intValue());
entry = entries.get(15);
checkEntryHeader(entry, Icmpv6Type.class, false);
Assert.assertEquals("Wrong icmpv6 type", 15, ((Icmpv6TypeCase) entry.getMatchEntryValue()).getIcmpv6Type().getIcmpv6Type().intValue());
entry = entries.get(16);
checkEntryHeader(entry, Icmpv6Code.class, false);
Assert.assertEquals("Wrong icmpv6 code", 16, ((Icmpv6CodeCase) entry.getMatchEntryValue()).getIcmpv6Code().getIcmpv6Code().intValue());
entry = entries.get(17);
checkEntryHeader(entry, Ipv4Src.class, false);
Assert.assertEquals("Wrong ipv4 src", "10.0.0.1", ((Ipv4SrcCase) entry.getMatchEntryValue()).getIpv4Src().getIpv4Address().getValue());
entry = entries.get(18);
checkEntryHeader(entry, Ipv4Dst.class, false);
Assert.assertEquals("Wrong ipv4 dst", "10.0.0.2", ((Ipv4DstCase) entry.getMatchEntryValue()).getIpv4Dst().getIpv4Address().getValue());
entry = entries.get(19);
checkEntryHeader(entry, MplsLabel.class, false);
Assert.assertEquals("Wrong mpls label", 17, ((MplsLabelCase) entry.getMatchEntryValue()).getMplsLabel().getMplsLabel().intValue());
entry = entries.get(20);
checkEntryHeader(entry, MplsBos.class, false);
Assert.assertEquals("Wrong mpls bos", true, ((MplsBosCase) entry.getMatchEntryValue()).getMplsBos().isBos());
entry = entries.get(21);
checkEntryHeader(entry, MplsTc.class, false);
Assert.assertEquals("Wrong mpls tc", 18, ((MplsTcCase) entry.getMatchEntryValue()).getMplsTc().getTc().intValue());
entry = entries.get(22);
checkEntryHeader(entry, PbbIsid.class, false);
Assert.assertEquals("Wrong pbb isid", 20, ((PbbIsidCase) entry.getMatchEntryValue()).getPbbIsid().getIsid().intValue());
entry = entries.get(23);
checkEntryHeader(entry, TunnelId.class, false);
Assert.assertArrayEquals("Wrong tunnel id", new byte[] { 0, 0, 0, 0, 0, 0, 0, 21 }, ((TunnelIdCase) entry.getMatchEntryValue()).getTunnelId().getTunnelId());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder in project openflowplugin by opendaylight.
the class MatchV10ResponseConvertor method convert.
@Override
public MatchBuilder convert(MatchV10 source, VersionDatapathIdConvertorData datapathIdConvertorData) {
MatchBuilder matchBuilder = new MatchBuilder();
EthernetMatchBuilder ethMatchBuilder = new EthernetMatchBuilder();
VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder();
Ipv4MatchBuilder ipv4MatchBuilder = new Ipv4MatchBuilder();
IpMatchBuilder ipMatchBuilder = new IpMatchBuilder();
OpenflowVersion ofVersion = OpenflowVersion.get(datapathIdConvertorData.getVersion());
BigInteger datapathid = datapathIdConvertorData.getDatapathId();
if (!source.getWildcards().isINPORT() && source.getInPort() != null) {
matchBuilder.setInPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathid, (long) source.getInPort(), ofVersion));
}
if (!source.getWildcards().isDLSRC() && source.getDlSrc() != null) {
EthernetSourceBuilder ethSrcBuilder = new EthernetSourceBuilder();
ethSrcBuilder.setAddress(source.getDlSrc());
ethMatchBuilder.setEthernetSource(ethSrcBuilder.build());
matchBuilder.setEthernetMatch(ethMatchBuilder.build());
}
if (!source.getWildcards().isDLDST() && source.getDlDst() != null) {
EthernetDestinationBuilder ethDstBuilder = new EthernetDestinationBuilder();
ethDstBuilder.setAddress(source.getDlDst());
ethMatchBuilder.setEthernetDestination(ethDstBuilder.build());
matchBuilder.setEthernetMatch(ethMatchBuilder.build());
}
if (!source.getWildcards().isDLTYPE() && source.getDlType() != null) {
EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
ethTypeBuilder.setType(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType((long) source.getDlType()));
ethMatchBuilder.setEthernetType(ethTypeBuilder.build());
matchBuilder.setEthernetMatch(ethMatchBuilder.build());
}
if (!source.getWildcards().isDLVLAN() && source.getDlVlan() != null) {
VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
int vlanId = source.getDlVlan() == 0xffff ? 0 : source.getDlVlan();
vlanIdBuilder.setVlanId(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId(vlanId));
vlanIdBuilder.setVlanIdPresent(vlanId != 0);
vlanMatchBuilder.setVlanId(vlanIdBuilder.build());
matchBuilder.setVlanMatch(vlanMatchBuilder.build());
}
if (!source.getWildcards().isDLVLANPCP() && source.getDlVlanPcp() != null) {
vlanMatchBuilder.setVlanPcp(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp(source.getDlVlanPcp()));
matchBuilder.setVlanMatch(vlanMatchBuilder.build());
}
if (!source.getWildcards().isDLTYPE() && source.getNwSrc() != null) {
final Ipv4Prefix prefix;
if (source.getNwSrcMask() != null) {
prefix = IetfInetUtil.INSTANCE.ipv4PrefixFor(source.getNwSrc(), source.getNwSrcMask());
} else {
// Openflow Spec : 1.3.2
// An all-one-bits oxm_mask is equivalent to specifying 0 for oxm_hasmask and omitting oxm_mask.
// So when user specify 32 as a mast, switch omit that mast and we get null as a mask in flow
// statistics response.
prefix = IetfInetUtil.INSTANCE.ipv4PrefixFor(source.getNwSrc());
}
if (!NO_IP.equals(prefix.getValue())) {
ipv4MatchBuilder.setIpv4Source(prefix);
matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
}
}
if (!source.getWildcards().isDLTYPE() && source.getNwDst() != null) {
final Ipv4Prefix prefix;
if (source.getNwDstMask() != null) {
prefix = IetfInetUtil.INSTANCE.ipv4PrefixFor(source.getNwDst(), source.getNwDstMask());
} else {
// Openflow Spec : 1.3.2
// An all-one-bits oxm_mask is equivalent to specifying 0 for oxm_hasmask and omitting oxm_mask.
// So when user specify 32 as a mast, switch omit that mast and we get null as a mask in flow
// statistics response.
prefix = IetfInetUtil.INSTANCE.ipv4PrefixFor(source.getNwDst());
}
if (!NO_IP.equals(prefix.getValue())) {
ipv4MatchBuilder.setIpv4Destination(prefix);
matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
}
}
if (!source.getWildcards().isNWPROTO() && source.getNwProto() != null) {
Short nwProto = source.getNwProto();
ipMatchBuilder.setIpProtocol(nwProto);
matchBuilder.setIpMatch(ipMatchBuilder.build());
int proto = nwProto.intValue();
if (proto == PROTO_TCP) {
TcpMatchBuilder tcpMatchBuilder = new TcpMatchBuilder();
boolean hasTcp = false;
if (!source.getWildcards().isTPSRC() && source.getTpSrc() != null) {
tcpMatchBuilder.setTcpSourcePort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(source.getTpSrc()));
hasTcp = true;
}
if (!source.getWildcards().isTPDST() && source.getTpDst() != null) {
tcpMatchBuilder.setTcpDestinationPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(source.getTpDst()));
hasTcp = true;
}
if (hasTcp) {
matchBuilder.setLayer4Match(tcpMatchBuilder.build());
}
} else if (proto == PROTO_UDP) {
UdpMatchBuilder udpMatchBuilder = new UdpMatchBuilder();
boolean hasUdp = false;
if (!source.getWildcards().isTPSRC() && source.getTpSrc() != null) {
udpMatchBuilder.setUdpSourcePort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(source.getTpSrc()));
hasUdp = true;
}
if (!source.getWildcards().isTPDST() && source.getTpDst() != null) {
udpMatchBuilder.setUdpDestinationPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(source.getTpDst()));
hasUdp = true;
}
if (hasUdp) {
matchBuilder.setLayer4Match(udpMatchBuilder.build());
}
} else if (proto == PROTO_ICMPV4) {
Icmpv4MatchBuilder icmpv4MatchBuilder = new Icmpv4MatchBuilder();
boolean hasIcmpv4 = false;
if (!source.getWildcards().isTPSRC()) {
Integer type = source.getTpSrc();
if (type != null) {
icmpv4MatchBuilder.setIcmpv4Type(type.shortValue());
hasIcmpv4 = true;
}
}
if (!source.getWildcards().isTPDST()) {
Integer code = source.getTpDst();
if (code != null) {
icmpv4MatchBuilder.setIcmpv4Code(code.shortValue());
hasIcmpv4 = true;
}
}
if (hasIcmpv4) {
matchBuilder.setIcmpv4Match(icmpv4MatchBuilder.build());
}
}
}
if (!source.getWildcards().isNWTOS() && source.getNwTos() != null) {
Short dscp = ActionUtil.tosToDscp(source.getNwTos());
ipMatchBuilder.setIpDscp(new Dscp(dscp));
matchBuilder.setIpMatch(ipMatchBuilder.build());
}
return matchBuilder;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder in project openflowplugin by opendaylight.
the class FlowConvertor method handleSetVlanIdForOF13.
/**
* A) If user provided flow's match includes vlan match and action has set_vlan_field
* Install following rules.
* 1) match on (OFPVID_PRESENT |value) without mask + action [set_field]
* <p/>
* B) if user provided flow's match doesn't include vlan match but action has set_vlan field
* 1) Match on (OFPVID_NONE ) without mask + action [push vlan tag + set_field]
* 2) Match on (OFPVID_PRESENT) with mask (OFPVID_PRESENT ) + action [ set_field]
*/
private List<FlowModInputBuilder> handleSetVlanIdForOF13(Flow srcFlow, VersionDatapathIdConvertorData versionDatapathIdConverterData) {
List<FlowModInputBuilder> list = new ArrayList<>(2);
final Match srcMatch = Preconditions.checkNotNull(srcFlow.getMatch());
final VlanMatch srcVlanMatch = srcMatch.getVlanMatch();
if (srcVlanMatch != null) {
// create flow with setfield and match
// match on vlan tag or vlanid with no mask
VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder(srcVlanMatch);
VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
vlanIdBuilder.setVlanIdPresent(srcVlanMatch.getVlanId().isVlanIdPresent());
vlanIdBuilder.setVlanId(srcVlanMatch.getVlanId().getVlanId());
vlanMatchBuilder.setVlanId(vlanIdBuilder.build());
Match match = new MatchBuilder(srcMatch).setVlanMatch(vlanMatchBuilder.build()).build();
Optional<? extends Flow> optional = injectMatchToFlow(srcFlow, match);
if (optional.isPresent()) {
list.add(toFlowModInput(optional.get(), versionDatapathIdConverterData));
}
} else {
// create 2 flows
// flow 1
// match on no vlan tag with no mask
Match match1 = new MatchBuilder(srcMatch).setVlanMatch(VLAN_MATCH_FALSE).build();
Optional<? extends Flow> optional1 = injectMatchAndAction(srcFlow, match1);
if (optional1.isPresent()) {
list.add(toFlowModInput(optional1.get(), versionDatapathIdConverterData));
}
// flow2
// match on vlan tag with mask
Match match2 = new MatchBuilder(srcMatch).setVlanMatch(VLAN_MATCH_TRUE).build();
Optional<? extends Flow> optional2 = injectMatchToFlow(srcFlow, match2);
if (optional2.isPresent()) {
list.add(toFlowModInput(optional2.get(), versionDatapathIdConverterData));
}
}
return list;
}
Aggregations