Example usage for io.netty.buffer Unpooled copyShort

List of usage examples for io.netty.buffer Unpooled copyShort

Introduction

In this page you can find the example usage for io.netty.buffer Unpooled copyShort.

Prototype

public static ByteBuf copyShort(int... values) 

Source Link

Document

Create a new big-endian buffer that holds a sequence of the specified 16-bit integers.

Usage

From source file:org.opendaylight.atrium.hostservice.api.Arp.java

License:Open Source License

public Arp setHardwareType(int value) {
    hdrFieldsMap.put(HTYPE, Unpooled.copyShort(value).array());
    return this;
}

From source file:org.opendaylight.atrium.hostservice.api.Arp.java

License:Open Source License

public Arp setProtocolType(int value) {
    hdrFieldsMap.put(PTYPE, Unpooled.copyShort(value).array());
    return this;
}

From source file:org.opendaylight.atrium.hostservice.api.Arp.java

License:Open Source License

public Arp setOperation(int value) {
    hdrFieldsMap.put(OPERATION, Unpooled.copyShort(value).array());
    return this;
}

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);
    }//  ww  w  . jav a 2 s .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.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.nlri.LinkNlriParser.java

License:Open Source License

static void serializeLinkDescriptors(final LinkDescriptors descriptors, final ByteBuf buffer) {
    if (descriptors.getLinkLocalIdentifier() != null && descriptors.getLinkRemoteIdentifier() != null) {
        final ByteBuf identifierBuf = Unpooled.buffer();
        identifierBuf.writeInt(descriptors.getLinkLocalIdentifier().intValue());
        identifierBuf.writeInt(descriptors.getLinkRemoteIdentifier().intValue());
        TlvUtil.writeTLV(LINK_LR_IDENTIFIERS, identifierBuf, buffer);
    }//from  www  . j  ava  2  s.  c  om
    if (descriptors.getIpv4InterfaceAddress() != null) {
        TlvUtil.writeTLV(IPV4_IFACE_ADDRESS, Ipv4Util.byteBufForAddress(descriptors.getIpv4InterfaceAddress()),
                buffer);
    }
    if (descriptors.getIpv4NeighborAddress() != null) {
        TlvUtil.writeTLV(IPV4_NEIGHBOR_ADDRESS,
                Ipv4Util.byteBufForAddress(descriptors.getIpv4NeighborAddress()), buffer);
    }
    if (descriptors.getIpv6InterfaceAddress() != null) {
        TlvUtil.writeTLV(IPV6_IFACE_ADDRESS, Ipv6Util.byteBufForAddress(descriptors.getIpv6InterfaceAddress()),
                buffer);
    }
    if (descriptors.getIpv6NeighborAddress() != null) {
        TlvUtil.writeTLV(IPV6_NEIGHBOR_ADDRESS,
                Ipv6Util.byteBufForAddress(descriptors.getIpv6NeighborAddress()), buffer);
    }
    if (descriptors.getMultiTopologyId() != null) {
        TlvUtil.writeTLV(TlvUtil.MULTI_TOPOLOGY_ID,
                Unpooled.copyShort(descriptors.getMultiTopologyId().getValue()), buffer);
    }
}

From source file:org.opendaylight.protocol.bgp.linkstate.nlri.PrefixNlriParser.java

License:Open Source License

static void serializePrefixDescriptors(final PrefixDescriptors descriptors, final ByteBuf buffer) {
    if (descriptors.getMultiTopologyId() != null) {
        TlvUtil.writeTLV(TlvUtil.MULTI_TOPOLOGY_ID,
                Unpooled.copyShort(descriptors.getMultiTopologyId().getValue()), buffer);
    }/* w  ww . ja va 2 s  .  c  om*/
    if (descriptors.getOspfRouteType() != null) {
        TlvUtil.writeTLV(OSPF_ROUTE_TYPE,
                Unpooled.wrappedBuffer(
                        new byte[] { UnsignedBytes.checkedCast(descriptors.getOspfRouteType().getIntValue()) }),
                buffer);
    }
    if (descriptors.getIpReachabilityInformation() != null) {
        final IpPrefix prefix = descriptors.getIpReachabilityInformation();
        byte[] prefixBytes = null;
        if (prefix.getIpv4Prefix() != null) {
            prefixBytes = Ipv4Util.bytesForPrefixBegin(prefix.getIpv4Prefix());
        } else if (prefix.getIpv6Prefix() != null) {
            prefixBytes = Ipv6Util.bytesForPrefixBegin(prefix.getIpv6Prefix());
        }
        TlvUtil.writeTLV(IP_REACHABILITY, Unpooled.wrappedBuffer(prefixBytes), buffer);
    }
}

From source file:org.opendaylight.protocol.bmp.impl.tlv.ReasonTlvHandler.java

License:Open Source License

@Override
public void serializeTlv(final Tlv tlv, final ByteBuf output) {
    Preconditions.checkArgument(tlv instanceof ReasonTlv, "ReasonTlv is mandatory.");
    TlvUtil.formatTlv(TYPE, Unpooled.copyShort(((ReasonTlv) tlv).getReason().getIntValue()), output);
}

From source file:org.opendaylight.usc.protocol.UscControl.java

License:Open Source License

@Override
public ByteBuf getPayload() {
    return Unpooled.copyShort(controlCode.getCode());
}

From source file:org.opendaylight.usc.protocol.UscError.java

License:Open Source License

@Override
public ByteBuf getPayload() {
    return Unpooled.copyShort(errorCode.code);
}