use of org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData in project openflowplugin by opendaylight.
the class MatchConvertorV10Test method testConvert.
@Test
public void testConvert() {
Optional<MatchV10> matchV10Optional = converterManager.convert(createL4UdpMatch().build(), new VersionConvertorData(OFConstants.OFP_VERSION_1_0));
MatchV10 matchV10 = matchV10Optional.get();
assertEquals(ZERO_MAC, matchV10.getDlDst());
assertEquals(FF_MAC, matchV10.getDlSrc());
assertEquals(0, matchV10.getDlType().intValue());
assertEquals(0xffff, matchV10.getDlVlan().intValue());
assertEquals(DEFAULT_PORT.getValue().intValue(), matchV10.getTpSrc().intValue());
assertEquals(DEFAULT_PORT.getValue().intValue(), matchV10.getTpDst().intValue());
assertEquals(Integer.parseInt(NODE_CONNECTOR_ID), matchV10.getInPort().intValue());
assertEquals(DEFAULT_IPV4_ADDRESS.getValue(), matchV10.getNwDst().getValue());
assertEquals(DEFAULT_MASK, matchV10.getNwDstMask().shortValue());
assertEquals(0, matchV10.getNwTos().shortValue());
assertEquals(DEFAULT_PORT.getValue().intValue(), matchV10.getTpSrc().intValue());
assertEquals(DEFAULT_PORT.getValue().intValue(), matchV10.getTpDst().intValue());
matchV10Optional = converterManager.convert(createL4TcpMatch().build(), new VersionConvertorData(OFConstants.OFP_VERSION_1_0));
matchV10 = matchV10Optional.get();
assertEquals(DEFAULT_PORT.getValue().intValue(), matchV10.getTpSrc().intValue());
assertEquals(DEFAULT_PORT.getValue().intValue(), matchV10.getTpDst().intValue());
matchV10Optional = converterManager.convert(createVlanTcpMatch().build(), new VersionConvertorData(OFConstants.OFP_VERSION_1_0));
matchV10 = matchV10Optional.get();
assertEquals(DEFAULT_VLAN_ID.getValue().intValue(), matchV10.getDlVlan().intValue());
}
use of org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData in project openflowplugin by opendaylight.
the class MatchConvertorV10Test method testConvertIcmpv4.
@Test
public void testConvertIcmpv4() {
MatchBuilder matchBuilder = createMatchBuilderWithDefaults();
Match match = matchBuilder.build();
Optional<MatchV10> matchV10Optional = converterManager.convert(match, new VersionConvertorData(OFConstants.OFP_VERSION_1_0));
MatchV10 matchV10 = matchV10Optional.get();
final Integer zero = 0;
assertEquals(ZERO_MAC, matchV10.getDlDst());
assertEquals(FF_MAC, matchV10.getDlSrc());
assertEquals(0, matchV10.getDlType().intValue());
assertEquals(0xffff, matchV10.getDlVlan().intValue());
assertEquals(Integer.parseInt(NODE_CONNECTOR_ID), matchV10.getInPort().intValue());
assertEquals(DEFAULT_IPV4_ADDRESS.getValue(), matchV10.getNwDst().getValue());
assertEquals(DEFAULT_MASK, matchV10.getNwDstMask().shortValue());
assertEquals(0, matchV10.getNwTos().shortValue());
assertEquals(zero, matchV10.getTpSrc());
assertEquals(zero, matchV10.getTpDst());
boolean wcTpSrc = true;
boolean wcTpDst = true;
FlowWildcardsV10 wc = new FlowWildcardsV10(false, false, false, true, true, false, false, false, wcTpDst, wcTpSrc);
assertEquals(wc, matchV10.getWildcards());
// Specify ICMP type only.
Integer icmpType = 55;
Icmpv4MatchBuilder icmpv4MatchBuilder = new Icmpv4MatchBuilder().setIcmpv4Type(icmpType.shortValue());
wcTpSrc = false;
wc = new FlowWildcardsV10(false, false, false, true, true, false, false, false, wcTpDst, wcTpSrc);
match = matchBuilder.setIcmpv4Match(icmpv4MatchBuilder.build()).build();
matchV10Optional = converterManager.convert(match, new VersionConvertorData(OFConstants.OFP_VERSION_1_0));
matchV10 = matchV10Optional.get();
assertEquals(ZERO_MAC, matchV10.getDlDst());
assertEquals(FF_MAC, matchV10.getDlSrc());
assertEquals(0, matchV10.getDlType().intValue());
assertEquals(0xffff, matchV10.getDlVlan().intValue());
assertEquals(Integer.parseInt(NODE_CONNECTOR_ID), matchV10.getInPort().intValue());
assertEquals(DEFAULT_IPV4_ADDRESS.getValue(), matchV10.getNwDst().getValue());
assertEquals(DEFAULT_MASK, matchV10.getNwDstMask().shortValue());
assertEquals(0, matchV10.getNwTos().shortValue());
assertEquals(icmpType, matchV10.getTpSrc());
assertEquals(zero, matchV10.getTpDst());
assertEquals(wc, matchV10.getWildcards());
// Specify ICMP code only.
Integer icmpCode = 31;
icmpv4MatchBuilder = new Icmpv4MatchBuilder().setIcmpv4Type(null).setIcmpv4Code(icmpCode.shortValue());
wcTpSrc = true;
wcTpDst = false;
wc = new FlowWildcardsV10(false, false, false, true, true, false, false, false, wcTpDst, wcTpSrc);
match = matchBuilder.setIcmpv4Match(icmpv4MatchBuilder.build()).build();
matchV10Optional = converterManager.convert(match, new VersionConvertorData(OFConstants.OFP_VERSION_1_0));
matchV10 = matchV10Optional.get();
assertEquals(ZERO_MAC, matchV10.getDlDst());
assertEquals(FF_MAC, matchV10.getDlSrc());
assertEquals(0, matchV10.getDlType().intValue());
assertEquals(0xffff, matchV10.getDlVlan().intValue());
assertEquals(Integer.parseInt(NODE_CONNECTOR_ID), matchV10.getInPort().intValue());
assertEquals(DEFAULT_IPV4_ADDRESS.getValue(), matchV10.getNwDst().getValue());
assertEquals(DEFAULT_MASK, matchV10.getNwDstMask().shortValue());
assertEquals(0, matchV10.getNwTos().shortValue());
assertEquals(zero, matchV10.getTpSrc());
assertEquals(icmpCode, matchV10.getTpDst());
assertEquals(wc, matchV10.getWildcards());
// Specify both ICMP type and code.
icmpType = 11;
icmpCode = 22;
icmpv4MatchBuilder = new Icmpv4MatchBuilder().setIcmpv4Type(icmpType.shortValue()).setIcmpv4Code(icmpCode.shortValue());
wcTpSrc = false;
wcTpDst = false;
wc = new FlowWildcardsV10(false, false, false, true, true, false, false, false, wcTpDst, wcTpSrc);
match = matchBuilder.setIcmpv4Match(icmpv4MatchBuilder.build()).build();
matchV10Optional = converterManager.convert(match, new VersionConvertorData(OFConstants.OFP_VERSION_1_0));
matchV10 = matchV10Optional.get();
assertEquals(ZERO_MAC, matchV10.getDlDst());
assertEquals(FF_MAC, matchV10.getDlSrc());
assertEquals(0, matchV10.getDlType().intValue());
assertEquals(0xffff, matchV10.getDlVlan().intValue());
assertEquals(Integer.parseInt(NODE_CONNECTOR_ID), matchV10.getInPort().intValue());
assertEquals(DEFAULT_IPV4_ADDRESS.getValue(), matchV10.getNwDst().getValue());
assertEquals(DEFAULT_MASK, matchV10.getNwDstMask().shortValue());
assertEquals(0, matchV10.getNwTos().shortValue());
assertEquals(icmpType, matchV10.getTpSrc());
assertEquals(icmpCode, matchV10.getTpDst());
assertEquals(wc, matchV10.getWildcards());
}
use of org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData in project openflowplugin by opendaylight.
the class TableFeaturesConvertorTest method testToTableFeaturesRequest.
@Test
public void testToTableFeaturesRequest() throws Exception {
List<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures> tableFeaturesList = new ArrayList<>();
org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeaturesBuilder tableFeaturesBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeaturesBuilder();
for (int i = 0; i < 10; i++) {
tableFeaturesBuilder.setTableId((short) i);
tableFeaturesBuilder.setName(String.format("table:%d", i));
tableFeaturesBuilder.setMetadataMatch(BigInteger.ONE);
tableFeaturesBuilder.setMetadataWrite(BigInteger.ONE);
tableFeaturesBuilder.setMaxEntries((long) 1 + 10 * i);
tableFeaturesBuilder.setConfig(new TableConfig(false));
tableFeaturesBuilder.setTableProperties(getTableProperties());
tableFeaturesList.add(tableFeaturesBuilder.build());
}
TableFeatures tableFeatures = new UpdatedTableBuilder().setTableFeatures(tableFeaturesList).build();
final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();
Optional<List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features._case.multipart.request.table.features.TableFeatures>> tableFeaturesesOptional = convertorManager.convert(tableFeatures, new VersionConvertorData(OFConstants.OFP_VERSION_1_3));
assertNotNull(tableFeatures);
assertEquals(10, tableFeatures.getTableFeatures().size());
List<TableFeatureProperties> tableFeaturePropertieses = tableFeatures.getTableFeatures().get(0).getTableProperties().getTableFeatureProperties();
assertEquals(AUGMENTATIONS_MAP.size() + 1, tableFeaturePropertieses.size());
org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.ApplyActionsMiss applyActionsMiss = null;
for (int i = 0; i < tableFeaturePropertieses.size(); i++) {
if (tableFeaturePropertieses.get(i).getTableFeaturePropType().getImplementedInterface().isAssignableFrom(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.ApplyActionsMiss.class)) {
applyActionsMiss = (org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.ApplyActionsMiss) tableFeaturePropertieses.get(i).getTableFeaturePropType();
break;
}
}
assertNotNull(applyActionsMiss);
assertEquals(ACTIONS.size(), applyActionsMiss.getApplyActionsMiss().getAction().size());
}
use of org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData in project openflowplugin by opendaylight.
the class FlowStatsResponseConvertorTest method testToSALInstruction.
/**
* Test method for {@link FlowInstructionResponseConvertor#convert(List, VersionConvertorData)} }.
*/
@Test
public void testToSALInstruction() {
List<Instruction> instructionsList = new ArrayList<>();
InstructionBuilder instructionBuilder = new InstructionBuilder();
for (int i = 0; i < PRESET_COUNT; i++) {
ApplyActionsCaseBuilder applyActionsCaseBuilder = new ApplyActionsCaseBuilder();
ApplyActionsBuilder applyActionsBuilder = new ApplyActionsBuilder();
ActionBuilder actionBuilder = new ActionBuilder();
List<Action> actions = new ArrayList<>();
for (int j = 0; j < PRESET_COUNT; j++) {
actions.add(actionBuilder.build());
}
applyActionsBuilder.setAction(actions);
applyActionsCaseBuilder.setApplyActions(applyActionsBuilder.build());
instructionBuilder.setInstructionChoice(applyActionsCaseBuilder.build());
instructionsList.add(instructionBuilder.build());
}
Instructions instructions;
VersionConvertorData data = new VersionConvertorData(OFConstants.OFP_VERSION_1_3);
instructions = convert(instructionsList, data);
assertNotNull(instructions);
assertEquals(PRESET_COUNT, instructions.getInstruction().size());
instructionsList = new ArrayList<>();
for (int i = 0; i < PRESET_COUNT; i++) {
GotoTableCaseBuilder gotoTableCaseBuilder = new GotoTableCaseBuilder();
GotoTableBuilder gotoTableBuilder = new GotoTableBuilder();
gotoTableBuilder.setTableId((short) i);
gotoTableCaseBuilder.setGotoTable(gotoTableBuilder.build());
instructionBuilder.setInstructionChoice(gotoTableCaseBuilder.build());
instructionsList.add(instructionBuilder.build());
}
instructions = convert(instructionsList, data);
assertNotNull(instructions);
assertEquals(PRESET_COUNT, instructions.getInstruction().size());
instructionsList = new ArrayList<>();
for (int i = 0; i < PRESET_COUNT; i++) {
MeterCaseBuilder meterCaseBuilder = new MeterCaseBuilder();
MeterBuilder meterBuilder = new MeterBuilder();
meterBuilder.setMeterId((long) i);
meterCaseBuilder.setMeter(meterBuilder.build());
instructionBuilder.setInstructionChoice(meterCaseBuilder.build());
instructionsList.add(instructionBuilder.build());
}
instructions = convert(instructionsList, data);
assertNotNull(instructions);
assertEquals(PRESET_COUNT, instructions.getInstruction().size());
instructionsList = new ArrayList<>();
for (int i = 0; i < PRESET_COUNT; i++) {
WriteActionsCaseBuilder writeActionsCaseBuilder = new WriteActionsCaseBuilder();
WriteActionsBuilder writeActionsBuilder = new WriteActionsBuilder();
ActionBuilder actionBuilder = new ActionBuilder();
List<Action> actions = new ArrayList<>();
for (int j = 0; j < PRESET_COUNT; j++) {
actions.add(actionBuilder.build());
}
writeActionsBuilder.setAction(actions);
writeActionsCaseBuilder.setWriteActions(writeActionsBuilder.build());
instructionBuilder.setInstructionChoice(writeActionsCaseBuilder.build());
instructionsList.add(instructionBuilder.build());
}
instructions = convert(instructionsList, data);
assertNotNull(instructions);
assertEquals(PRESET_COUNT, instructions.getInstruction().size());
instructionsList = new ArrayList<>();
for (int i = 0; i < PRESET_COUNT; i++) {
ClearActionsCaseBuilder clearActionsCaseBuilder = new ClearActionsCaseBuilder();
instructionBuilder.setInstructionChoice(clearActionsCaseBuilder.build());
instructionsList.add(instructionBuilder.build());
}
instructions = convert(instructionsList, data);
assertNotNull(instructions);
int instructionSize = instructions.getInstruction().size();
assertEquals(PRESET_COUNT, instructionSize);
instructionsList = new ArrayList<>();
for (int i = 0; i < PRESET_COUNT; i++) {
WriteMetadataCaseBuilder metadataCaseBuilder = new WriteMetadataCaseBuilder();
WriteMetadataBuilder metadataBuilder = new WriteMetadataBuilder();
metadataBuilder.setMetadata(BigInteger.TEN.setBit(i).toByteArray());
metadataBuilder.setMetadataMask(BigInteger.ONE.setBit(i).toByteArray());
metadataCaseBuilder.setWriteMetadata(metadataBuilder.build());
instructionBuilder.setInstructionChoice(metadataCaseBuilder.build());
instructionsList.add(instructionBuilder.build());
}
instructions = convert(instructionsList, data);
assertNotNull(instructions);
assertEquals(PRESET_COUNT, instructions.getInstruction().size());
}
use of org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData in project openflowplugin by opendaylight.
the class MatchConvertorTest method testUdpMatchConversion.
@Test
public void testUdpMatchConversion() {
MatchBuilder builder = new MatchBuilder();
UdpMatchBuilder udpMatchBuilder = new UdpMatchBuilder();
udpMatchBuilder.setUdpSourcePort(new PortNumber(11));
udpMatchBuilder.setUdpDestinationPort(new PortNumber(12));
builder.setLayer4Match(udpMatchBuilder.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", 2, entries.size());
MatchEntry entry = entries.get(0);
checkEntryHeader(entry, UdpSrc.class, false);
Assert.assertEquals("Wrong udp src", 11, ((UdpSrcCase) entry.getMatchEntryValue()).getUdpSrc().getPort().getValue().intValue());
entry = entries.get(1);
checkEntryHeader(entry, UdpDst.class, false);
Assert.assertEquals("Wrong udp dst", 12, ((UdpDstCase) entry.getMatchEntryValue()).getUdpDst().getPort().getValue().intValue());
}
Aggregations