Search in sources :

Example 6 with VersionConvertorData

use of org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData in project openflowplugin by opendaylight.

the class ConvertorManagerTest method testConvert.

@Test
public void testConvert() throws Exception {
    final ConvertorManager convertorManager = new ConvertorManager(OFConstants.OFP_VERSION_1_3).registerConvertor(OFConstants.OFP_VERSION_1_3, new Convertor<Action, String, VersionConvertorData>() {

        @Override
        public Collection<Class<?>> getTypes() {
            return Collections.singleton(Action.class);
        }

        @Override
        public String convert(Action source, VersionConvertorData data) {
            return String.valueOf(source) + String.valueOf(data);
        }
    });
    final Action source = new ActionBuilder().build();
    final VersionConvertorData data = new VersionConvertorData(OFConstants.OFP_VERSION_1_3);
    final String expectedResult = String.valueOf(source) + String.valueOf(data);
    final Optional<String> result = convertorManager.convert(source, data);
    assertTrue("Failed to convert action to string", result.isPresent());
    assertEquals("Result and expected result do not match", result.get(), expectedResult);
}
Also used : VersionConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData) Action(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action) ActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder) Collection(java.util.Collection) Test(org.junit.Test)

Example 7 with VersionConvertorData

use of org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData in project openflowplugin by opendaylight.

the class GroupDescStatsResponseConvertorTest method test.

/**
 * Test empty GroupDescStats conversion.
 */
@Test
public void test() {
    List<GroupDesc> groupDescStats = new ArrayList<>();
    VersionConvertorData data = new VersionConvertorData(OFConstants.OFP_VERSION_1_3);
    List<GroupDescStats> statsList = convert(groupDescStats, data);
    Assert.assertEquals("Wrong groupDesc stats size", 0, statsList.size());
}
Also used : VersionConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData) GroupDesc(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc._case.multipart.reply.group.desc.GroupDesc) ArrayList(java.util.ArrayList) GroupDescStats(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.desc.stats.reply.GroupDescStats) Test(org.junit.Test)

Example 8 with VersionConvertorData

use of org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData in project openflowplugin by opendaylight.

the class GroupDescStatsResponseConvertorTest method testGroupDescStats.

/**
 * Test single GroupDescStats conversion.
 */
@Test
public void testGroupDescStats() {
    // **********************************************
    // First group desc
    // **********************************************
    GroupDescBuilder builder = new GroupDescBuilder();
    builder.setType(GroupType.OFPGTFF);
    builder.setGroupId(new GroupId(42L));
    // Buckets for first group desc
    BucketsListBuilder bucketsBuilder = new BucketsListBuilder();
    bucketsBuilder.setWeight(16);
    bucketsBuilder.setWatchPort(new PortNumber(84L));
    bucketsBuilder.setWatchGroup(168L);
    // Actions for buckets for first group desc
    List<Action> actions = new ArrayList<>();
    ActionBuilder actionBuilder = new ActionBuilder();
    actionBuilder.setActionChoice(new CopyTtlInCaseBuilder().build());
    actions.add(actionBuilder.build());
    // Build bucket with actions
    bucketsBuilder.setAction(actions);
    List<BucketsList> bucketsList = new ArrayList<>();
    bucketsList.add(bucketsBuilder.build());
    // Build first group desc
    builder.setBucketsList(bucketsList);
    List<GroupDesc> groupDescStats = new ArrayList<>();
    groupDescStats.add(builder.build());
    // **********************************************
    // Second group desc
    // **********************************************
    builder = new GroupDescBuilder();
    builder.setType(GroupType.OFPGTINDIRECT);
    builder.setGroupId(new GroupId(50L));
    // First buckets for second group desc
    bucketsList = new ArrayList<>();
    bucketsBuilder = new BucketsListBuilder();
    bucketsBuilder.setWeight(100);
    bucketsBuilder.setWatchPort(new PortNumber(200L));
    bucketsBuilder.setWatchGroup(400L);
    // Actions for first buckets for second group desc
    actions = new ArrayList<>();
    actionBuilder = new ActionBuilder();
    actionBuilder.setActionChoice(new CopyTtlOutCaseBuilder().build());
    actions.add(actionBuilder.build());
    actionBuilder = new ActionBuilder();
    actionBuilder.setActionChoice(new DecNwTtlCaseBuilder().build());
    actions.add(actionBuilder.build());
    actionBuilder = new ActionBuilder();
    actionBuilder.setActionChoice(new PopPbbCaseBuilder().build());
    actions.add(actionBuilder.build());
    // Build first bucket with actions
    bucketsBuilder.setAction(actions);
    bucketsList.add(bucketsBuilder.build());
    // Second buckets for second group desc
    bucketsBuilder = new BucketsListBuilder();
    bucketsBuilder.setWeight(5);
    bucketsBuilder.setWatchPort(new PortNumber(10L));
    bucketsBuilder.setWatchGroup(15L);
    // Actions for second buckets for second group desc
    actions = new ArrayList<>();
    // Build second bucket with actions
    bucketsBuilder.setAction(actions);
    bucketsList.add(bucketsBuilder.build());
    // Build second group desc
    builder.setBucketsList(bucketsList);
    groupDescStats.add(builder.build());
    VersionConvertorData data = new VersionConvertorData(OFConstants.OFP_VERSION_1_3);
    List<GroupDescStats> statsList = convert(groupDescStats, data);
    Assert.assertEquals("Wrong groupDesc stats size", 2, statsList.size());
    // **********************************************
    // Test first group desc
    // **********************************************
    GroupDescStats stat = statsList.get(0);
    Assert.assertEquals("Wrong type", GroupTypes.GroupFf, stat.getGroupType());
    Assert.assertEquals("Wrong group-id", 42, stat.getGroupId().getValue().intValue());
    Assert.assertEquals("Wrong key", 42, stat.getKey().getGroupId().getValue().intValue());
    Assert.assertEquals("Wrong buckets size", 1, stat.getBuckets().getBucket().size());
    // Test first bucket for first group desc
    Bucket bucket = stat.getBuckets().getBucket().get(0);
    Assert.assertEquals("Wrong type", 0, bucket.getKey().getBucketId().getValue().intValue());
    Assert.assertEquals("Wrong type", 0, bucket.getBucketId().getValue().intValue());
    Assert.assertEquals("Wrong type", 16, bucket.getWeight().intValue());
    Assert.assertEquals("Wrong type", 168, bucket.getWatchGroup().intValue());
    Assert.assertEquals("Wrong type", 84, bucket.getWatchPort().intValue());
    Assert.assertEquals("Wrong type", 1, bucket.getAction().size());
    // Test first action for first bucket for first group desc
    org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action action = bucket.getAction().get(0);
    Assert.assertEquals("Wrong type", 0, action.getOrder().intValue());
    Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112" + ".action.action.CopyTtlInCase", action.getAction().getImplementedInterface().getName());
    // **********************************************
    // Test second group desc
    // **********************************************
    stat = statsList.get(1);
    Assert.assertEquals("Wrong type", GroupTypes.GroupIndirect, stat.getGroupType());
    Assert.assertEquals("Wrong group-id", 50, stat.getGroupId().getValue().intValue());
    Assert.assertEquals("Wrong key", 50, stat.getKey().getGroupId().getValue().intValue());
    Assert.assertEquals("Wrong buckets size", 2, stat.getBuckets().getBucket().size());
    // Test first bucket for second group desc
    bucket = stat.getBuckets().getBucket().get(0);
    Assert.assertEquals("Wrong type", 0, bucket.getKey().getBucketId().getValue().intValue());
    Assert.assertEquals("Wrong type", 0, bucket.getBucketId().getValue().intValue());
    Assert.assertEquals("Wrong type", 100, bucket.getWeight().intValue());
    Assert.assertEquals("Wrong type", 400, bucket.getWatchGroup().intValue());
    Assert.assertEquals("Wrong type", 200, bucket.getWatchPort().intValue());
    Assert.assertEquals("Wrong type", 3, bucket.getAction().size());
    // Test first action for first bucket of second group desc
    action = bucket.getAction().get(0);
    Assert.assertEquals("Wrong type", 0, action.getOrder().intValue());
    Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112" + ".action.action.CopyTtlOutCase", action.getAction().getImplementedInterface().getName());
    // Test second action for first bucket of second group desc
    action = bucket.getAction().get(1);
    Assert.assertEquals("Wrong type", 1, action.getOrder().intValue());
    Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112" + ".action.action.DecNwTtlCase", action.getAction().getImplementedInterface().getName());
    // Test third action for first bucket of second group desc
    action = bucket.getAction().get(2);
    Assert.assertEquals("Wrong type", 2, action.getOrder().intValue());
    Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112" + ".action.action.PopPbbActionCase", action.getAction().getImplementedInterface().getName());
    // Test second bucket for second group desc
    bucket = stat.getBuckets().getBucket().get(1);
    Assert.assertEquals("Wrong type", 1, bucket.getKey().getBucketId().getValue().intValue());
    Assert.assertEquals("Wrong type", 1, bucket.getBucketId().getValue().intValue());
    Assert.assertEquals("Wrong type", 5, bucket.getWeight().intValue());
    Assert.assertEquals("Wrong type", 15, bucket.getWatchGroup().intValue());
    Assert.assertEquals("Wrong type", 10, bucket.getWatchPort().intValue());
    Assert.assertEquals("Wrong type", 0, bucket.getAction().size());
}
Also used : Action(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action) ActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder) PopPbbCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopPbbCaseBuilder) ArrayList(java.util.ArrayList) GroupDesc(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc._case.multipart.reply.group.desc.GroupDesc) GroupDescBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc._case.multipart.reply.group.desc.GroupDescBuilder) GroupDescStats(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.desc.stats.reply.GroupDescStats) BucketsListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsListBuilder) CopyTtlInCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.CopyTtlInCaseBuilder) DecNwTtlCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.DecNwTtlCaseBuilder) GroupId(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId) VersionConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData) Bucket(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket) PortNumber(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber) BucketsList(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList) CopyTtlOutCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.CopyTtlOutCaseBuilder) Test(org.junit.Test)

Example 9 with VersionConvertorData

use of org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData in project openflowplugin by opendaylight.

the class GroupDescStatsResponseConvertorTest method testSingleGroupDescStat.

/**
 * Test single GroupDescStat conversion without buckets.
 */
@Test
public void testSingleGroupDescStat() {
    GroupDescBuilder builder = new GroupDescBuilder();
    builder.setType(GroupType.OFPGTALL);
    builder.setGroupId(new GroupId(42L));
    builder.setBucketsList(new ArrayList<>());
    List<GroupDesc> groupDescStats = new ArrayList<>();
    groupDescStats.add(builder.build());
    VersionConvertorData data = new VersionConvertorData(OFConstants.OFP_VERSION_1_3);
    List<GroupDescStats> statsList = convert(groupDescStats, data);
    Assert.assertEquals("Wrong groupDesc stats size", 1, statsList.size());
    GroupDescStats stat = statsList.get(0);
    Assert.assertEquals("Wrong type", GroupTypes.GroupAll, stat.getGroupType());
    Assert.assertEquals("Wrong group-id", 42, stat.getGroupId().getValue().intValue());
    Assert.assertEquals("Wrong key", 42, stat.getKey().getGroupId().getValue().intValue());
    Assert.assertEquals("Wrong buckets size", 0, stat.getBuckets().getBucket().size());
}
Also used : VersionConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData) GroupDesc(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc._case.multipart.reply.group.desc.GroupDesc) ArrayList(java.util.ArrayList) GroupDescBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc._case.multipart.reply.group.desc.GroupDescBuilder) GroupDescStats(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.desc.stats.reply.GroupDescStats) GroupId(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId) Test(org.junit.Test)

Example 10 with VersionConvertorData

use of org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData in project openflowplugin by opendaylight.

the class MeterConfigStatsResponseConvertorTest method testToSALMeterConfigList.

@Test
public /**
 * Test of basic mapping functionality of {@link MeterConfigStatsResponseConvertor#convert(java.util.List)} }
 */
void testToSALMeterConfigList() {
    final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();
    Optional<List<MeterConfigStats>> meterConfigsOptional = convertorManager.convert(createMeterConfigList(), new VersionConvertorData(OFConstants.OFP_VERSION_1_3));
    List<MeterConfigStats> meterConfigs = meterConfigsOptional.orElse(Collections.emptyList());
    assertEquals(PRESET_COUNT, meterConfigs.size());
    int cnt = 0;
    for (MeterConfigStats meterConfigStats : meterConfigs) {
        assertEquals(new Long(cnt), meterConfigStats.getMeterId().getValue());
        assertTrue(meterConfigStats.getFlags().isMeterBurst());
        assertFalse(meterConfigStats.getFlags().isMeterKbps());
        assertTrue(meterConfigStats.getFlags().isMeterPktps());
        assertFalse(meterConfigStats.getFlags().isMeterStats());
        cnt++;
    }
}
Also used : VersionConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData) ArrayList(java.util.ArrayList) List(java.util.List) MeterConfigStats(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.config.stats.reply.MeterConfigStats) Test(org.junit.Test)

Aggregations

VersionConvertorData (org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData)38 Test (org.junit.Test)33 List (java.util.List)25 ArrayList (java.util.ArrayList)19 Match (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match)15 MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)15 EthernetMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder)14 Icmpv4MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4MatchBuilder)14 IpMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder)14 VlanMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder)14 Ipv4MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder)14 TcpMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder)14 UdpMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder)14 Icmpv6MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder)13 ArpMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatchBuilder)13 Ipv6MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder)13 TunnelIpv4MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.TunnelIpv4MatchBuilder)13 SctpMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.SctpMatchBuilder)13 MatchEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry)13 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)6