2 * Copyright 2015 Open Networking Laboratory
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
16 package org.onosproject.bgpio.protocol.linkstate;
\r
18 import java.util.List;
\r
20 import org.jboss.netty.buffer.ChannelBuffer;
\r
21 import org.onosproject.bgpio.exceptions.BgpParseException;
\r
22 import org.onosproject.bgpio.protocol.BgpLinkLsNlri;
\r
23 import org.onosproject.bgpio.protocol.NlriType;
\r
24 import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType;
\r
25 import org.onosproject.bgpio.types.BgpErrorType;
\r
26 import org.onosproject.bgpio.types.BgpValueType;
\r
27 import org.onosproject.bgpio.types.RouteDistinguisher;
\r
28 import org.onosproject.bgpio.util.Constants;
\r
29 import org.slf4j.Logger;
\r
30 import org.slf4j.LoggerFactory;
\r
32 import com.google.common.base.MoreObjects;
\r
35 * Implementation of Link LS NLRI.
\r
37 public class BgpLinkLsNlriVer4 implements BgpLinkLsNlri {
\r
40 * REFERENCE : draft-ietf-idr-ls-distribution-11
\r
42 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
\r
45 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
\r
48 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
\r
49 // Local Node Descriptors (variable) //
\r
50 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
\r
51 // Remote Node Descriptors (variable) //
\r
52 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
\r
53 // Link Descriptors (variable) //
\r
54 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
\r
56 Figure : The Link NLRI format
\r
58 private static final Logger log = LoggerFactory.getLogger(BgpLinkLsNlriVer4.class);
\r
59 public static final int LINK_NLRITYPE = 2;
\r
61 private BgpLinkLSIdentifier linkLSIdentifier;
\r
62 private byte protocolId;
\r
63 private long identifier;
\r
64 private RouteDistinguisher routeDistinguisher;
\r
65 private boolean isVpn;
\r
68 * Initialize fields.
\r
70 public BgpLinkLsNlriVer4() {
\r
71 this.protocolId = 0;
\r
72 this.identifier = 0;
\r
73 this.linkLSIdentifier = null;
\r
74 this.routeDistinguisher = null;
\r
79 * Constructor to initialize parameters for BGP LinkLSNlri.
\r
81 * @param protocolId protocol Id
\r
82 * @param identifier field in BGP LinkLSNlri
\r
83 * @param linkLSIdentifier link LS identifier
\r
84 * @param routeDistinguisher route distinguisher from message
\r
85 * @param isVpn vpn info availability in message
\r
87 public BgpLinkLsNlriVer4(byte protocolId, long identifier, BgpLinkLSIdentifier linkLSIdentifier,
\r
88 RouteDistinguisher routeDistinguisher, boolean isVpn) {
\r
89 this.protocolId = protocolId;
\r
90 this.identifier = identifier;
\r
91 this.linkLSIdentifier = linkLSIdentifier;
\r
92 this.routeDistinguisher = routeDistinguisher;
\r
97 * Reads from channelBuffer and parses Link LS Nlri.
\r
99 * @param cb ChannelBuffer
\r
100 * @param afi Address Family Identifier
\r
101 * @param safi Subsequent Address Family Identifier
\r
102 * @return object of this class
\r
103 * @throws BgpParseException while parsing Link LS NLRI
\r
105 public static BgpLinkLsNlriVer4 read(ChannelBuffer cb, short afi, byte safi) throws BgpParseException {
\r
106 boolean isVpn = false;
\r
107 RouteDistinguisher routeDistinguisher = null;
\r
108 if ((afi == Constants.AFI_VALUE) && (safi == Constants.VPN_SAFI_VALUE)) {
\r
109 routeDistinguisher = new RouteDistinguisher();
\r
110 routeDistinguisher = RouteDistinguisher.read(cb);
\r
115 byte protocolId = cb.readByte();
\r
116 long identifier = cb.readLong();
\r
118 BgpLinkLSIdentifier linkLSIdentifier = new BgpLinkLSIdentifier();
\r
119 linkLSIdentifier = BgpLinkLSIdentifier.parseLinkIdendifier(cb, protocolId);
\r
120 return new BgpLinkLsNlriVer4(protocolId, identifier, linkLSIdentifier, routeDistinguisher, isVpn);
\r
124 public NlriType getNlriType() {
\r
125 return NlriType.LINK;
\r
129 public long getIdentifier() {
\r
130 return this.identifier;
\r
134 * Set the link LS identifier.
\r
136 * @param linkLSIdentifier link LS identifier to set
\r
138 public void setLinkLSIdentifier(BgpLinkLSIdentifier linkLSIdentifier) {
\r
139 this.linkLSIdentifier = linkLSIdentifier;
\r
143 public ProtocolType getProtocolId() throws BgpParseException {
\r
144 switch (protocolId) {
\r
145 case Constants.ISIS_LEVELONE:
\r
146 return ProtocolType.ISIS_LEVEL_ONE;
\r
147 case Constants.ISIS_LEVELTWO:
\r
148 return ProtocolType.ISIS_LEVEL_TWO;
\r
149 case Constants.OSPFV2:
\r
150 return ProtocolType.OSPF_V2;
\r
151 case Constants.DIRECT:
\r
152 return ProtocolType.DIRECT;
\r
153 case Constants.STATIC_CONFIGURATION:
\r
154 return ProtocolType.STATIC_CONFIGURATION;
\r
155 case Constants.OSPFV3:
\r
156 return ProtocolType.OSPF_V3;
\r
158 throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, (byte) 0, null);
\r
163 public NodeDescriptors localNodeDescriptors() {
\r
164 return this.linkLSIdentifier.localNodeDescriptors();
\r
168 public NodeDescriptors remoteNodeDescriptors() {
\r
169 return this.linkLSIdentifier.remoteNodeDescriptors();
\r
173 * Returns whether VPN is present or not.
\r
175 * @return whether VPN is present or not
\r
177 public boolean isVpnPresent() {
\r
182 public RouteDistinguisher getRouteDistinguisher() {
\r
183 return this.routeDistinguisher;
\r
187 * Returns link identifier.
\r
189 * @return link identifier
\r
191 public BgpLinkLSIdentifier getLinkIdentifier() {
\r
192 return this.linkLSIdentifier;
\r
196 public List<BgpValueType> linkDescriptors() {
\r
197 return this.linkLSIdentifier.linkDescriptors();
\r
201 public String toString() {
\r
202 return MoreObjects.toStringHelper(getClass())
\r
204 .add("protocolId", protocolId)
\r
205 .add("identifier", identifier)
\r
206 .add("RouteDistinguisher ", routeDistinguisher)
\r
207 .add("linkLSIdentifier", linkLSIdentifier)
\r