List of usage examples for io.netty.buffer Unpooled copyMedium
public static ByteBuf copyMedium(int... values)
From source file:org.opendaylight.protocol.bgp.linkstate.attribute.LinkAttributesParser.java
License:Open Source License
static void serializeLinkAttributes(final LinkAttributesCase linkAttributesCase, final ByteBuf byteAggregator) { final LinkAttributes linkAttributes = linkAttributesCase.getLinkAttributes(); LOG.trace("Started serializing Link Attributes"); if (linkAttributes.getLocalIpv4RouterId() != null) { TlvUtil.writeTLV(TlvUtil.LOCAL_IPV4_ROUTER_ID, Ipv4Util.byteBufForAddress(linkAttributes.getLocalIpv4RouterId()), byteAggregator); }//from www. j a v a 2s . c o m if (linkAttributes.getLocalIpv6RouterId() != null) { TlvUtil.writeTLV(TlvUtil.LOCAL_IPV6_ROUTER_ID, Ipv6Util.byteBufForAddress(linkAttributes.getLocalIpv6RouterId()), byteAggregator); } if (linkAttributes.getRemoteIpv4RouterId() != null) { TlvUtil.writeTLV(REMOTE_IPV4_ROUTER_ID, Ipv4Util.byteBufForAddress(linkAttributes.getRemoteIpv4RouterId()), byteAggregator); } if (linkAttributes.getRemoteIpv6RouterId() != null) { TlvUtil.writeTLV(REMOTE_IPV6_ROUTER_ID, Ipv6Util.byteBufForAddress(linkAttributes.getRemoteIpv6RouterId()), byteAggregator); } if (linkAttributes.getAdminGroup() != null) { TlvUtil.writeTLV(ADMIN_GROUP, Unpooled.copyInt(linkAttributes.getAdminGroup().getValue().intValue()), byteAggregator); } if (linkAttributes.getMaxLinkBandwidth() != null) { TlvUtil.writeTLV(MAX_BANDWIDTH, Unpooled.wrappedBuffer(linkAttributes.getMaxLinkBandwidth().getValue()), byteAggregator); } if (linkAttributes.getMaxReservableBandwidth() != null) { TlvUtil.writeTLV(MAX_RESERVABLE_BANDWIDTH, Unpooled.wrappedBuffer(linkAttributes.getMaxReservableBandwidth().getValue()), byteAggregator); } serializeUnreservedBw(linkAttributes.getUnreservedBandwidth(), byteAggregator); if (linkAttributes.getTeMetric() != null) { TlvUtil.writeTLV(TE_METRIC, Unpooled.copyLong(linkAttributes.getTeMetric().getValue().longValue()), byteAggregator); } if (linkAttributes.getLinkProtection() != null) { TlvUtil.writeTLV(LINK_PROTECTION_TYPE, Unpooled.copyShort(linkAttributes.getLinkProtection().getIntValue()), byteAggregator); } serializeMplsProtocolMask(linkAttributes.getMplsProtocol(), byteAggregator); if (linkAttributes.getMetric() != null) { // size of metric can be 1,2 or 3 depending on the protocol TlvUtil.writeTLV(METRIC, Unpooled.copyMedium(linkAttributes.getMetric().getValue().intValue()), byteAggregator); } serializeSrlg(linkAttributes.getSharedRiskLinkGroups(), byteAggregator); if (linkAttributes.getLinkName() != null) { TlvUtil.writeTLV(LINK_NAME, Unpooled.wrappedBuffer(Charsets.UTF_8.encode(linkAttributes.getLinkName())), byteAggregator); } if (linkAttributes.getSrAdjIds() != null) { SrLinkAttributesParser.serializeAdjacencySegmentIdentifiers(linkAttributes.getSrAdjIds(), SR_ADJ_ID, byteAggregator); } if (linkAttributes.getSrLanAdjIds() != null) { SrLinkAttributesParser.serializeLanAdjacencySegmentIdentifiers(linkAttributes.getSrLanAdjIds(), SR_LAN_ADJ_ID, byteAggregator); } if (linkAttributes.getPeerNodeSid() != null) { TlvUtil.writeTLV(PEER_NODE_SID_CODE, SrLinkAttributesParser.serializeAdjacencySegmentIdentifier(linkAttributes.getPeerNodeSid()), byteAggregator); } if (linkAttributes.getPeerAdjSid() != null) { TlvUtil.writeTLV(PEER_ADJ_SID_CODE, SrLinkAttributesParser.serializeAdjacencySegmentIdentifier(linkAttributes.getPeerAdjSid()), byteAggregator); } if (linkAttributes.getPeerSetSids() != null) { SrLinkAttributesParser.serializeAdjacencySegmentIdentifiers(linkAttributes.getPeerSetSids(), PEER_SET_SID_CODE, byteAggregator); } LOG.trace("Finished serializing Link Attributes"); }
From source file:org.opendaylight.protocol.bgp.linkstate.attribute.sr.SidLabelIndexParser.java
License:Open Source License
static ByteBuf serializeSidValue(final SidLabelIndex tlv) { if (tlv instanceof Ipv6AddressCase) { return Ipv6Util.byteBufForAddress(((Ipv6AddressCase) tlv).getIpv6Address()); } else if (tlv instanceof LocalLabelCase) { return Unpooled.copyMedium(((LocalLabelCase) tlv).getLocalLabel().getValue().intValue() & LABEL_MASK); } else if (tlv instanceof SidCase) { return Unpooled.copyInt(((SidCase) tlv).getSid().intValue()); }//from www . j a va 2 s . c o m return null; }
From source file:org.opendaylight.protocol.bgp.linkstate.impl.attribute.LinkAttributesParser.java
License:Open Source License
static void serializeLinkAttributes(final LinkAttributesCase linkAttributesCase, final ByteBuf output) { final LinkAttributes linkAttributes = linkAttributesCase.getLinkAttributes(); LOG.trace("Started serializing Link Attributes"); ifPresentApply(linkAttributes.getLocalIpv4RouterId(), value -> TlvUtil .writeTLV(TlvUtil.LOCAL_IPV4_ROUTER_ID, Ipv4Util.byteBufForAddress((Ipv4Address) value), output)); ifPresentApply(linkAttributes.getLocalIpv6RouterId(), value -> TlvUtil .writeTLV(TlvUtil.LOCAL_IPV6_ROUTER_ID, Ipv6Util.byteBufForAddress((Ipv6Address) value), output)); ifPresentApply(linkAttributes.getRemoteIpv4RouterId(), value -> TlvUtil.writeTLV(REMOTE_IPV4_ROUTER_ID, Ipv4Util.byteBufForAddress((Ipv4Address) value), output)); ifPresentApply(linkAttributes.getRemoteIpv6RouterId(), value -> TlvUtil.writeTLV(REMOTE_IPV6_ROUTER_ID, Ipv6Util.byteBufForAddress((Ipv6Address) value), output)); ifPresentApply(linkAttributes.getAdminGroup(), value -> TlvUtil.writeTLV(ADMIN_GROUP, Unpooled.copyInt((((AdministrativeGroup) value).getValue()).intValue()), output)); ifPresentApply(linkAttributes.getMaxLinkBandwidth(), value -> TlvUtil.writeTLV(MAX_BANDWIDTH, Unpooled.wrappedBuffer(((Bandwidth) value).getValue()), output)); ifPresentApply(linkAttributes.getMaxReservableBandwidth(), value -> TlvUtil.writeTLV(MAX_RESERVABLE_BANDWIDTH, Unpooled.wrappedBuffer(((Bandwidth) value).getValue()), output)); serializeUnreservedBw(linkAttributes.getUnreservedBandwidth(), output); ifPresentApply(linkAttributes.getTeMetric(), value -> TlvUtil.writeTLV(TE_METRIC, Unpooled.copyLong(((TeMetric) value).getValue()), output)); ifPresentApply(linkAttributes.getLinkProtection(), value -> TlvUtil.writeTLV(LINK_PROTECTION_TYPE, Unpooled.copyShort(((LinkProtectionType) value).getIntValue()), output)); serializeMplsProtocolMask(linkAttributes.getMplsProtocol(), output); ifPresentApply(linkAttributes.getMetric(), value -> TlvUtil.writeTLV(METRIC, Unpooled.copyMedium(((Metric) value).getValue().intValue()), output)); serializeSrlg(linkAttributes.getSharedRiskLinkGroups(), output); ifPresentApply(linkAttributes.getLinkName(), value -> TlvUtil.writeTLV(LINK_NAME, Unpooled.wrappedBuffer(StandardCharsets.UTF_8.encode((String) value)), output)); ifPresentApply(linkAttributes.getSrAdjIds(), value -> SrLinkAttributesParser .serializeAdjacencySegmentIdentifiers((List<SrAdjIds>) value, SR_ADJ_ID, output)); ifPresentApply(linkAttributes.getSrLanAdjIds(), value -> SrLinkAttributesParser .serializeLanAdjacencySegmentIdentifiers((List<SrLanAdjIds>) value, output)); ifPresentApply(linkAttributes.getPeerNodeSid(), value -> TlvUtil.writeTLV(PEER_NODE_SID_CODE, SrLinkAttributesParser.serializeAdjacencySegmentIdentifier((PeerNodeSid) value), output)); ifPresentApply(linkAttributes.getPeerAdjSid(), value -> TlvUtil.writeTLV(PEER_ADJ_SID_CODE, SrLinkAttributesParser.serializeAdjacencySegmentIdentifier((PeerAdjSid) value), output)); ifPresentApply(linkAttributes.getPeerSetSids(), value -> SrLinkAttributesParser .serializeAdjacencySegmentIdentifiers((List<PeerSetSids>) value, PEER_SET_SID_CODE, output)); LOG.trace("Finished serializing Link Attributes"); }
From source file:org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.SidLabelIndexParser.java
License:Open Source License
public static ByteBuf serializeSidValue(final SidLabelIndex tlv) { if (tlv instanceof Ipv6AddressCase) { return Ipv6Util.byteBufForAddress(((Ipv6AddressCase) tlv).getIpv6Address()); } else if (tlv instanceof LocalLabelCase) { return Unpooled.copyMedium(((LocalLabelCase) tlv).getLocalLabel().getValue().intValue() & LABEL_MASK); } else if (tlv instanceof SidCase) { return Unpooled.copyInt(((SidCase) tlv).getSid().intValue()); }/*from w w w . j a v a2 s . com*/ return null; }
From source file:org.opendaylight.protocol.util.MplsLabelUtil.java
License:Open Source License
/** * Serializes incoming MplsLabel without bottom bit * @param label MplsLabel object/*from ww w . j a v a 2 s. c om*/ * @return */ public static ByteBuf byteBufForMplsLabel(final MplsLabel label) { return Unpooled.copyMedium(intForMplsLabel(label)); }
From source file:org.opendaylight.protocol.util.MplsLabelUtil.java
License:Open Source License
/** * Serializes incoming MplsLabel with bottom bit * @param label MplsLabel object/*from www . j a v a2s .co m*/ * @return */ public static ByteBuf byteBufForMplsLabelWithBottomBit(final MplsLabel label) { return Unpooled.copyMedium(intForMplsLabelWithBottomBit(label)); }