[ONOS-2602]Implement Link NLRI
Change-Id: Ia17868c0a2f701a88d82171943c52fe7b7880fba
Showing
2 changed files
with
213 additions
and
3 deletions
... | @@ -29,19 +29,19 @@ public interface BgpLinkLsNlri extends BGPLSNlri { | ... | @@ -29,19 +29,19 @@ public interface BgpLinkLsNlri extends BGPLSNlri { |
29 | * | 29 | * |
30 | * @return local node descriptors | 30 | * @return local node descriptors |
31 | */ | 31 | */ |
32 | - NodeDescriptors getLocalNodeDescriptors(); | 32 | + NodeDescriptors localNodeDescriptors(); |
33 | 33 | ||
34 | /** | 34 | /** |
35 | * Returns remote node descriptors. | 35 | * Returns remote node descriptors. |
36 | * | 36 | * |
37 | * @return remote node descriptors | 37 | * @return remote node descriptors |
38 | */ | 38 | */ |
39 | - NodeDescriptors getRemoteNodeDescriptors(); | 39 | + NodeDescriptors remoteNodeDescriptors(); |
40 | 40 | ||
41 | /** | 41 | /** |
42 | * Returns link descriptors. | 42 | * Returns link descriptors. |
43 | * | 43 | * |
44 | * @return link descriptors | 44 | * @return link descriptors |
45 | */ | 45 | */ |
46 | - List<BGPValueType> getLinkDescriptors(); | 46 | + List<BGPValueType> linkDescriptors(); |
47 | } | 47 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.bgpio.protocol.linkstate; | ||
17 | + | ||
18 | +import java.util.List; | ||
19 | + | ||
20 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
21 | +import org.onosproject.bgpio.exceptions.BGPParseException; | ||
22 | +import org.onosproject.bgpio.protocol.BgpLinkLsNlri; | ||
23 | +import org.onosproject.bgpio.protocol.NlriType; | ||
24 | +import org.onosproject.bgpio.protocol.linkstate.BGPNodeLSNlriVer4.PROTOCOLTYPE; | ||
25 | +import org.onosproject.bgpio.types.BGPErrorType; | ||
26 | +import org.onosproject.bgpio.types.BGPValueType; | ||
27 | +import org.onosproject.bgpio.types.RouteDistinguisher; | ||
28 | +import org.onosproject.bgpio.util.Constants; | ||
29 | +import org.slf4j.Logger; | ||
30 | +import org.slf4j.LoggerFactory; | ||
31 | + | ||
32 | +import com.google.common.base.MoreObjects; | ||
33 | + | ||
34 | +/** | ||
35 | + * Implementation of Link LS NLRI. | ||
36 | + */ | ||
37 | +public class BgpLinkLsNlriVer4 implements BgpLinkLsNlri { | ||
38 | + | ||
39 | + /* | ||
40 | + * REFERENCE : draft-ietf-idr-ls-distribution-11 | ||
41 | + 0 1 2 3 | ||
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 | ||
43 | + +-+-+-+-+-+-+-+-+ | ||
44 | + | Protocol-ID | | ||
45 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
46 | + | Identifier | | ||
47 | + | (64 bits) | | ||
48 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
49 | + // Local Node Descriptors (variable) // | ||
50 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
51 | + // Remote Node Descriptors (variable) // | ||
52 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
53 | + // Link Descriptors (variable) // | ||
54 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
55 | + | ||
56 | + Figure : The Link NLRI format | ||
57 | + */ | ||
58 | + private static final Logger log = LoggerFactory.getLogger(BgpLinkLsNlriVer4.class); | ||
59 | + public static final int LINK_NLRITYPE = 2; | ||
60 | + | ||
61 | + private BGPLinkLSIdentifier linkLSIdentifier; | ||
62 | + private byte protocolId; | ||
63 | + private long identifier; | ||
64 | + private RouteDistinguisher routeDistinguisher; | ||
65 | + private boolean isVpn; | ||
66 | + | ||
67 | + /** | ||
68 | + * Initialize fields. | ||
69 | + */ | ||
70 | + public BgpLinkLsNlriVer4() { | ||
71 | + this.protocolId = 0; | ||
72 | + this.identifier = 0; | ||
73 | + this.linkLSIdentifier = null; | ||
74 | + this.routeDistinguisher = null; | ||
75 | + this.isVpn = false; | ||
76 | + } | ||
77 | + | ||
78 | + /** | ||
79 | + * Constructor to initialize parameters for BGP LinkLSNlri. | ||
80 | + * | ||
81 | + * @param protocolId protocol Id | ||
82 | + * @param identifier field in BGP LinkLSNlri | ||
83 | + * @param linkLSIdentifier link LS identifier | ||
84 | + * @param routeDistinguisher route distinguisher from message | ||
85 | + * @param isVpn vpn info availability in message | ||
86 | + */ | ||
87 | + public BgpLinkLsNlriVer4(byte protocolId, long identifier, BGPLinkLSIdentifier linkLSIdentifier, | ||
88 | + RouteDistinguisher routeDistinguisher, boolean isVpn) { | ||
89 | + this.protocolId = protocolId; | ||
90 | + this.identifier = identifier; | ||
91 | + this.linkLSIdentifier = linkLSIdentifier; | ||
92 | + this.routeDistinguisher = routeDistinguisher; | ||
93 | + this.isVpn = isVpn; | ||
94 | + } | ||
95 | + | ||
96 | + /** | ||
97 | + * Reads from channelBuffer and parses Link LS Nlri. | ||
98 | + * | ||
99 | + * @param cb ChannelBuffer | ||
100 | + * @param afi Address Family Identifier | ||
101 | + * @param safi Subsequent Address Family Identifier | ||
102 | + * @return object of this class | ||
103 | + * @throws BGPParseException while parsing Link LS NLRI | ||
104 | + */ | ||
105 | + public static BgpLinkLsNlriVer4 read(ChannelBuffer cb, short afi, byte safi) throws BGPParseException { | ||
106 | + boolean isVpn = false; | ||
107 | + RouteDistinguisher routeDistinguisher = null; | ||
108 | + if ((afi == Constants.AFI_VALUE) && (safi == Constants.VPN_SAFI_VALUE)) { | ||
109 | + routeDistinguisher = new RouteDistinguisher(); | ||
110 | + routeDistinguisher = RouteDistinguisher.read(cb); | ||
111 | + isVpn = true; | ||
112 | + } else { | ||
113 | + isVpn = false; | ||
114 | + } | ||
115 | + byte protocolId = cb.readByte(); | ||
116 | + long identifier = cb.readLong(); | ||
117 | + | ||
118 | + BGPLinkLSIdentifier linkLSIdentifier = new BGPLinkLSIdentifier(); | ||
119 | + linkLSIdentifier = BGPLinkLSIdentifier.parseLinkIdendifier(cb, protocolId); | ||
120 | + return new BgpLinkLsNlriVer4(protocolId, identifier, linkLSIdentifier, routeDistinguisher, isVpn); | ||
121 | + } | ||
122 | + | ||
123 | + @Override | ||
124 | + public NlriType getNlriType() { | ||
125 | + return NlriType.LINK; | ||
126 | + } | ||
127 | + | ||
128 | + @Override | ||
129 | + public long getIdentifier() { | ||
130 | + return this.identifier; | ||
131 | + } | ||
132 | + | ||
133 | + /** | ||
134 | + * Set the link LS identifier. | ||
135 | + * | ||
136 | + * @param linkLSIdentifier link LS identifier to set | ||
137 | + */ | ||
138 | + public void setLinkLSIdentifier(BGPLinkLSIdentifier linkLSIdentifier) { | ||
139 | + this.linkLSIdentifier = linkLSIdentifier; | ||
140 | + } | ||
141 | + | ||
142 | + @Override | ||
143 | + public PROTOCOLTYPE getProtocolId() throws BGPParseException { | ||
144 | + switch (protocolId) { | ||
145 | + case Constants.ISIS_LEVELONE: | ||
146 | + return PROTOCOLTYPE.ISIS_LevelOne; | ||
147 | + case Constants.ISIS_LEVELTWO: | ||
148 | + return PROTOCOLTYPE.ISIS_LevelTwo; | ||
149 | + case Constants.OSPFV2: | ||
150 | + return PROTOCOLTYPE.OSPFv2; | ||
151 | + case Constants.DIRECT: | ||
152 | + return PROTOCOLTYPE.Direct; | ||
153 | + case Constants.STATIC_CONFIGURATION: | ||
154 | + return PROTOCOLTYPE.Static_Configuration; | ||
155 | + case Constants.OSPFV3: | ||
156 | + return PROTOCOLTYPE.OSPFv3; | ||
157 | + default: | ||
158 | + throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, (byte) 0, null); | ||
159 | + } | ||
160 | + } | ||
161 | + | ||
162 | + @Override | ||
163 | + public NodeDescriptors localNodeDescriptors() { | ||
164 | + return this.linkLSIdentifier.localNodeDescriptors(); | ||
165 | + } | ||
166 | + | ||
167 | + @Override | ||
168 | + public NodeDescriptors remoteNodeDescriptors() { | ||
169 | + return this.linkLSIdentifier.remoteNodeDescriptors(); | ||
170 | + } | ||
171 | + | ||
172 | + /** | ||
173 | + * Returns whether VPN is present or not. | ||
174 | + * | ||
175 | + * @return whether VPN is present or not | ||
176 | + */ | ||
177 | + public boolean isVpnPresent() { | ||
178 | + return this.isVpn; | ||
179 | + } | ||
180 | + | ||
181 | + @Override | ||
182 | + public RouteDistinguisher getRouteDistinguisher() { | ||
183 | + return this.routeDistinguisher; | ||
184 | + } | ||
185 | + | ||
186 | + /** | ||
187 | + * Returns link identifier. | ||
188 | + * | ||
189 | + * @return link identifier | ||
190 | + */ | ||
191 | + public BGPLinkLSIdentifier getLinkIdentifier() { | ||
192 | + return this.linkLSIdentifier; | ||
193 | + } | ||
194 | + | ||
195 | + @Override | ||
196 | + public List<BGPValueType> linkDescriptors() { | ||
197 | + return this.linkLSIdentifier.linkDescriptors(); | ||
198 | + } | ||
199 | + | ||
200 | + @Override | ||
201 | + public String toString() { | ||
202 | + return MoreObjects.toStringHelper(getClass()) | ||
203 | + .omitNullValues() | ||
204 | + .add("protocolId", protocolId) | ||
205 | + .add("identifier", identifier) | ||
206 | + .add("RouteDistinguisher ", routeDistinguisher) | ||
207 | + .add("linkLSIdentifier", linkLSIdentifier) | ||
208 | + .toString(); | ||
209 | + } | ||
210 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment