Search in sources :

Example 16 with Weight

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.Weight in project bgpcep by opendaylight.

the class SrLinkAttributesParser method parseLanAdjacencySegmentIdentifier.

public static SrLanAdjIds parseLanAdjacencySegmentIdentifier(final ByteBuf buffer, final ProtocolId protocolId) {
    if (!buffer.isReadable()) {
        return new SrLanAdjIdsBuilder().build();
    }
    final SrLanAdjIdsBuilder srLanAdjIdBuilder = new SrLanAdjIdsBuilder();
    final BitArray flags = BitArray.valueOf(buffer, FLAGS_BITS_SIZE);
    srLanAdjIdBuilder.setFlags(parseFlags(flags, protocolId));
    srLanAdjIdBuilder.setWeight(new Weight(buffer.readUnsignedByte()));
    buffer.skipBytes(RESERVED);
    switch(protocolId) {
        case IsisLevel1:
        case IsisLevel2:
            srLanAdjIdBuilder.setIsoSystemId(new IsoSystemIdentifier(ByteArray.readBytes(buffer, ISO_SYSTEM_ID_SIZE)));
            break;
        case Ospf:
        case OspfV3:
            srLanAdjIdBuilder.setNeighborId(Ipv4Util.addressForByteBuf(buffer));
            break;
        default:
            return null;
    }
    // length determines a type of next field, which is used for parsing
    srLanAdjIdBuilder.setSidLabelIndex(SidLabelIndexParser.parseSidLabelIndex(Size.forValue(buffer.readableBytes()), buffer));
    return srLanAdjIdBuilder.build();
}
Also used : SrLanAdjIdsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.attribute.SrLanAdjIdsBuilder) IsoSystemIdentifier(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.IsoSystemIdentifier) BitArray(org.opendaylight.protocol.util.BitArray) Weight(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.Weight)

Example 17 with Weight

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.Weight in project netvirt by opendaylight.

the class NAPTSwitchSelector method constructNAPTSwitches.

private Map<BigInteger, Integer> constructNAPTSwitches() {
    Optional<NaptSwitches> optNaptSwitches = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, getNaptSwitchesIdentifier());
    Map<BigInteger, Integer> switchWeights = new HashMap<>();
    if (optNaptSwitches.isPresent()) {
        NaptSwitches naptSwitches = optNaptSwitches.get();
        List<RouterToNaptSwitch> routerToNaptSwitches = naptSwitches.getRouterToNaptSwitch();
        for (RouterToNaptSwitch naptSwitch : routerToNaptSwitches) {
            BigInteger primarySwitch = naptSwitch.getPrimarySwitchId();
            // update weight
            Integer weight = switchWeights.get(primarySwitch);
            if (weight == null) {
                switchWeights.put(primarySwitch, 1);
            } else {
                switchWeights.put(primarySwitch, ++weight);
            }
        }
    }
    return switchWeights;
}
Also used : BigInteger(java.math.BigInteger) RouterToNaptSwitch(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.napt.switches.RouterToNaptSwitch) HashMap(java.util.HashMap) NaptSwitches(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.NaptSwitches) BigInteger(java.math.BigInteger)

Example 18 with Weight

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.Weight in project openflowplugin by opendaylight.

the class MultipartReplyMessageFactoryTest method testGroupDescSerialize.

@Test
public void testGroupDescSerialize() throws Exception {
    MultipartReplyMessageBuilder builder = new MultipartReplyMessageBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setFlags(new MultipartRequestFlags(true));
    builder.setType(MultipartType.forValue(7));
    MultipartReplyGroupDescCaseBuilder groupCase = new MultipartReplyGroupDescCaseBuilder();
    MultipartReplyGroupDescBuilder group = new MultipartReplyGroupDescBuilder();
    group.setGroupDesc(createGroupDesc());
    groupCase.setMultipartReplyGroupDesc(group.build());
    builder.setMultipartReplyBody(groupCase.build());
    MultipartReplyMessage message = builder.build();
    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    factory.serialize(message, serializedBuffer);
    BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 64);
    Assert.assertEquals("Wrong type", MultipartType.OFPMPGROUPDESC.getIntValue(), serializedBuffer.readShort());
    Assert.assertEquals("Wrong flags", message.getFlags(), createMultipartRequestFlags(serializedBuffer.readShort()));
    serializedBuffer.skipBytes(PADDING);
    MultipartReplyGroupDescCase body = (MultipartReplyGroupDescCase) message.getMultipartReplyBody();
    MultipartReplyGroupDesc messageOutput = body.getMultipartReplyGroupDesc();
    GroupDesc groupDesc = messageOutput.getGroupDesc().get(0);
    Assert.assertEquals("Wrong length", 48, serializedBuffer.readShort());
    Assert.assertEquals("Wrong type", groupDesc.getType().getIntValue(), serializedBuffer.readUnsignedByte());
    serializedBuffer.skipBytes(1);
    Assert.assertEquals("Wrong group id", groupDesc.getGroupId().getValue().intValue(), serializedBuffer.readInt());
    BucketsList bucketList = groupDesc.getBucketsList().get(0);
    Assert.assertEquals("Wrong length", 40, serializedBuffer.readShort());
    Assert.assertEquals("Wrong weight", bucketList.getWeight().intValue(), serializedBuffer.readShort());
    Assert.assertEquals("Wrong watch port", bucketList.getWatchPort().getValue().intValue(), serializedBuffer.readInt());
    Assert.assertEquals("Wrong watch group", bucketList.getWatchGroup().intValue(), serializedBuffer.readInt());
    serializedBuffer.skipBytes(4);
    Assert.assertEquals("Wrong action type", 0, serializedBuffer.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 16, serializedBuffer.readUnsignedShort());
    Assert.assertEquals("Wrong action type", 45, serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong action type", 55, serializedBuffer.readUnsignedShort());
    serializedBuffer.skipBytes(6);
    Assert.assertEquals("Wrong action type", 23, serializedBuffer.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 8, serializedBuffer.readUnsignedShort());
    Assert.assertEquals("Wrong action type", 64, serializedBuffer.readUnsignedByte());
    serializedBuffer.skipBytes(3);
    Assert.assertTrue("Not all data were read", serializedBuffer.readableBytes() == 0);
}
Also used : MultipartReplyMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage) MultipartReplyGroupDescCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupDescCase) MultipartReplyMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder) 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) MultipartReplyGroupDesc(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc._case.MultipartReplyGroupDesc) MultipartReplyGroupDesc(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc._case.MultipartReplyGroupDesc) MultipartRequestFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags) ByteBuf(io.netty.buffer.ByteBuf) BucketsList(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList) MultipartReplyGroupDescCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupDescCaseBuilder) MultipartReplyGroupDescBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc._case.MultipartReplyGroupDescBuilder) Test(org.junit.Test)

Example 19 with Weight

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.Weight in project openflowplugin by opendaylight.

the class GroupMessageDeserializerTest method deserialize.

@Test
public void deserialize() throws Exception {
    // Group header
    buffer.writeByte(TYPE);
    buffer.writeShort(EncodeConstants.EMPTY_LENGTH);
    buffer.writeInt(XID);
    buffer.writeShort(COMMAND.getIntValue());
    buffer.writeByte(GROUP_TYPE.getIntValue());
    buffer.writeZero(PADDING);
    buffer.writeInt(GROUP_ID);
    // Buckets header
    int index = buffer.writerIndex();
    buffer.writeShort(EncodeConstants.EMPTY_LENGTH);
    buffer.writeShort(WEIGHT);
    buffer.writeInt(WATCH_PORT);
    buffer.writeInt(WATCH_GROUP);
    buffer.writeZero(PADDING_IN_BUCKETS_HEADER);
    // POP PBB action
    buffer.writeShort(ActionConstants.POP_PBB_CODE);
    buffer.writeShort(ActionConstants.GENERAL_ACTION_LENGTH);
    buffer.writeZero(ActionConstants.PADDING_IN_ACTION_HEADER);
    // Count total length of buckets
    buffer.setShort(index, buffer.writerIndex() - index);
    // Deserialize and check everything
    final GroupMessage message = (GroupMessage) getFactory().deserialize(buffer, EncodeConstants.OF13_VERSION_ID);
    assertEquals(XID, message.getXid().intValue());
    assertEquals(COMMAND.getIntValue(), message.getCommand().getIntValue());
    assertEquals(GROUP_TYPE.getIntValue(), message.getGroupType().getIntValue());
    assertEquals(1, message.getBuckets().getBucket().size());
    final Bucket bucket = message.getBuckets().getBucket().get(0);
    assertEquals(WEIGHT, bucket.getWeight().shortValue());
    assertEquals(WATCH_PORT, bucket.getWatchPort().intValue());
    assertEquals(WATCH_GROUP, bucket.getWatchGroup().intValue());
    assertEquals(1, bucket.getAction().size());
    assertEquals(PopPbbActionCase.class, bucket.getAction().get(0).getAction().getImplementedInterface());
}
Also used : Bucket(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket) GroupMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupMessage) Test(org.junit.Test) AbstractDeserializerTest(org.opendaylight.openflowplugin.impl.protocol.deserialization.AbstractDeserializerTest)

Example 20 with Weight

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.Weight in project openflowplugin by opendaylight.

the class MultipartReplyGroupDescDeserializerTest method deserialize.

@Test
public void deserialize() throws Exception {
    ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    buffer.writeShort(ITEM_LENGTH);
    buffer.writeByte(GROUP_TYPE);
    buffer.writeZero(PADDING_IN_GROUP_DESC_HEADER);
    buffer.writeInt(GROUP_ID);
    buffer.writeShort(BUCKET_LENGTH);
    buffer.writeShort(WEIGHT);
    buffer.writeInt(WATCH_PORT);
    buffer.writeInt(WATCH_GROUP);
    buffer.writeZero(PADDING_IN_BUCKETS_HEADER);
    // POP PBB action
    buffer.writeShort(ActionConstants.POP_PBB_CODE);
    buffer.writeShort(ActionConstants.GENERAL_ACTION_LENGTH);
    buffer.writeZero(ActionConstants.PADDING_IN_ACTION_HEADER);
    final MultipartReplyGroupDesc reply = (MultipartReplyGroupDesc) deserializeMultipart(buffer);
    assertEquals(GROUP_ID, reply.getGroupDescStats().get(0).getGroupId().getValue().intValue());
    assertEquals(WEIGHT, reply.getGroupDescStats().get(0).getBuckets().getBucket().get(0).getWeight().intValue());
    assertEquals(WATCH_PORT, reply.getGroupDescStats().get(0).getBuckets().getBucket().get(0).getWatchPort().intValue());
    assertEquals(WATCH_GROUP, reply.getGroupDescStats().get(0).getBuckets().getBucket().get(0).getWatchGroup().intValue());
    assertEquals(GROUP_TYPE, reply.getGroupDescStats().get(0).getGroupType().getIntValue());
    assertEquals(0, buffer.readableBytes());
}
Also used : MultipartReplyGroupDesc(org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.multipart.reply.multipart.reply.body.MultipartReplyGroupDesc) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)20 Weight (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.Weight)9 ByteBuf (io.netty.buffer.ByteBuf)7 MapRegister (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRegister)7 ByteBuffer (java.nio.ByteBuffer)4 BitArray (org.opendaylight.protocol.util.BitArray)3 MapNotify (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapNotify)3 MappingRecord (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord)3 SrLanAdjIdsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.attribute.SrLanAdjIdsBuilder)3 ArrayList (java.util.ArrayList)2 AddMapping (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.AddMapping)2 LocatorRecord (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord)2 MappingRecordItem (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem)2 BucketsList (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList)2 SrAdjIdsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.attribute.SrAdjIdsBuilder)2 Ipv6AddressCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.sid.label.index.sid.label.index.Ipv6AddressCaseBuilder)2 BigInteger (java.math.BigInteger)1 HashMap (java.util.HashMap)1 Before (org.junit.Before)1 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)1