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();
}
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;
}
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);
}
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());
}
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());
}
Aggregations