Priyanka B
Committed by Gerrit Code Review

[Emu] [ONOS-2603] Implement BGP Update Protocol Message and parse all Link State atrributes of

 Node and Prefix

Change-Id: I1859ad92a1fc5ba0035865576fd062cf8f1ed64e
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;
17 +
18 +import org.onosproject.bgpio.exceptions.BGPParseException;
19 +import org.onosproject.bgpio.protocol.link_state.BGPNodeLSNlriVer4.PROTOCOLTYPE;
20 +import org.onosproject.bgpio.types.RouteDistinguisher;
21 +
22 +/**
23 + * Abstraction of an entity providing BGP-LS NLRI.
24 + */
25 +public interface BGPLSNlri {
26 + /**
27 + * Returns NlriType of BGP-LS NLRI.
28 + *
29 + * @return NlriType of BGP-LS NLRI
30 + */
31 + NlriType getNlriType();
32 +
33 + /**
34 + * Returns Identifier in Nlri.
35 + *
36 + * @return Identifier in Nlri
37 + */
38 + long getIdentifier();
39 +
40 + /**
41 + * Returns Protocol Id in Nlri.
42 + *
43 + * @return Protocol Id in Nlri
44 + * @throws BGPParseException while getting protocol ID
45 + */
46 + PROTOCOLTYPE getProtocolId() throws BGPParseException;
47 +
48 + /**
49 + * Returns Route distinguisher in Nlri.
50 + *
51 + * @return Route distinguisher in Nlri
52 + */
53 + RouteDistinguisher getRouteDistinguisher();
54 +}
...\ 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;
17 +
18 +import org.onosproject.bgpio.protocol.link_state.BGPNodeLSIdentifier;
19 +
20 +/**
21 + * Abstraction of an entity providing BGP-LS Node NLRI.
22 + */
23 +public interface BGPNodeLSNlri extends BGPLSNlri {
24 + /**
25 + * Returns local node descriptors.
26 + *
27 + * @return local node descriptors
28 + */
29 + BGPNodeLSIdentifier getLocalNodeDescriptors();
30 +}
...\ 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;
17 +
18 +import java.util.LinkedList;
19 +
20 +import org.onosproject.bgpio.types.BGPValueType;
21 +import org.onosproject.bgpio.protocol.link_state.NodeDescriptors;
22 +
23 +/**
24 + * Abstraction of an entity providing BGP-LS Prefix NLRI.
25 + */
26 +public interface BGPPrefixLSNlri extends BGPLSNlri {
27 + /**
28 + * Returns local node descriptors.
29 + *
30 + * @return local node descriptors
31 + */
32 + NodeDescriptors getLocalNodeDescriptors();
33 +
34 + /**
35 + * Returns list of Prefix descriptor.
36 + *
37 + * @return list of Prefix descriptor
38 + */
39 + LinkedList<BGPValueType> getPrefixdescriptor();
40 +}
...\ 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 +
17 +package org.onosproject.bgpio.protocol;
18 +
19 +/**
20 + * Enum to Provide the Different BGP-LS NLRI types.
21 + */
22 +public enum NlriType {
23 +
24 + NODE(1), LINK(2), PREFIX_IPV4(3), PREFIX_IPV6(4);
25 +
26 + int value;
27 +
28 + /**
29 + * Assign value with the value as the LINK-STATE NLRI type.
30 + *
31 + * @param value LINK-STATE NLRI type
32 + */
33 + NlriType(int value) {
34 + this.value = value;
35 + }
36 +
37 + /**
38 + * Returns value as LINK-STATE NLRI type.
39 + *
40 + * @return value LINK-STATE NLRI type
41 + */
42 + public byte getType() {
43 + return (byte) value;
44 + }
45 +}
...\ 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.link_state;
17 +
18 +import java.util.Objects;
19 +
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.bgpio.exceptions.BGPParseException;
22 +import org.onosproject.bgpio.types.BGPErrorType;
23 +import org.onosproject.bgpio.util.Constants;
24 +import org.slf4j.Logger;
25 +import org.slf4j.LoggerFactory;
26 +
27 +import com.google.common.base.MoreObjects;
28 +
29 +/**
30 + * Implementation of Node Identifier which includes local node descriptor/remote node descriptors.
31 + */
32 +public class BGPNodeLSIdentifier {
33 +
34 + protected static final Logger log = LoggerFactory.getLogger(BGPNodeLSIdentifier.class);
35 + private NodeDescriptors nodeDescriptors;
36 +
37 + /**
38 + * Resets fields.
39 + */
40 + public BGPNodeLSIdentifier() {
41 + this.nodeDescriptors = null;
42 + }
43 +
44 + /**
45 + * Constructor to initialize fields.
46 + *
47 + * @param nodeDescriptors local/remote node descriptor
48 + */
49 + public BGPNodeLSIdentifier(NodeDescriptors nodeDescriptors) {
50 + this.nodeDescriptors = nodeDescriptors;
51 + }
52 +
53 + /**
54 + * Parse local node descriptors.
55 + *
56 + * @param cb ChannelBuffer
57 + * @param protocolId protocol identifier
58 + * @return object of this BGPNodeLSIdentifier
59 + * @throws BGPParseException while parsing local node descriptors
60 + */
61 + public static BGPNodeLSIdentifier parseLocalNodeDescriptors(ChannelBuffer cb, byte protocolId)
62 + throws BGPParseException {
63 + ChannelBuffer tempBuf = cb;
64 + short type = cb.readShort();
65 + short length = cb.readShort();
66 + if (cb.readableBytes() < length) {
67 + throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.OPTIONAL_ATTRIBUTE_ERROR,
68 + tempBuf.readBytes(cb.readableBytes() + Constants.TYPE_AND_LEN));
69 + }
70 + NodeDescriptors nodeDescriptors = new NodeDescriptors();
71 + ChannelBuffer tempCb = cb.readBytes(length);
72 +
73 + if (type == NodeDescriptors.LOCAL_NODE_DES_TYPE) {
74 + nodeDescriptors = NodeDescriptors.read(tempCb, length, type, protocolId);
75 + } else {
76 + throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.MALFORMED_ATTRIBUTE_LIST, null);
77 + }
78 + return new BGPNodeLSIdentifier(nodeDescriptors);
79 + }
80 +
81 + /**
82 + * Returns node descriptors.
83 + *
84 + * @return node descriptors
85 + */
86 + public NodeDescriptors getNodedescriptors() {
87 + return this.nodeDescriptors;
88 + }
89 +
90 + @Override
91 + public boolean equals(Object obj) {
92 + if (this == obj) {
93 + return true;
94 + }
95 + if (obj instanceof BGPNodeLSIdentifier) {
96 + BGPNodeLSIdentifier other = (BGPNodeLSIdentifier) obj;
97 + return Objects.equals(nodeDescriptors, other.nodeDescriptors);
98 + }
99 + return false;
100 + }
101 +
102 + @Override
103 + public int hashCode() {
104 + return Objects.hash(nodeDescriptors);
105 + }
106 +
107 + @Override
108 + public String toString() {
109 + return MoreObjects.toStringHelper(getClass())
110 + .add("NodeDescriptors", nodeDescriptors)
111 + .toString();
112 + }
113 +}
...\ 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.link_state;
17 +
18 +import org.jboss.netty.buffer.ChannelBuffer;
19 +import org.onosproject.bgpio.exceptions.BGPParseException;
20 +import org.onosproject.bgpio.protocol.BGPNodeLSNlri;
21 +import org.onosproject.bgpio.protocol.NlriType;
22 +import org.onosproject.bgpio.types.BGPErrorType;
23 +import org.onosproject.bgpio.types.RouteDistinguisher;
24 +import org.onosproject.bgpio.util.Constants;
25 +import org.slf4j.Logger;
26 +import org.slf4j.LoggerFactory;
27 +
28 +import com.google.common.base.MoreObjects;
29 +
30 +/**
31 + * Implementation of Node LS NLRI.
32 + */
33 +public class BGPNodeLSNlriVer4 implements BGPNodeLSNlri {
34 +
35 + /*
36 + *REFERENCE : draft-ietf-idr-ls-distribution-11
37 + 0 1 2 3
38 + 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
39 + +-+-+-+-+-+-+-+-+
40 + | Protocol-ID |
41 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 + | Identifier |
43 + | (64 bits) |
44 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
45 + // Local Node Descriptors (variable) //
46 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
47 +
48 + Figure : The Node NLRI format
49 + */
50 +
51 + protected static final Logger log = LoggerFactory.getLogger(BGPNodeLSNlriVer4.class);
52 +
53 + public static final int NODE_NLRITYPE = 1;
54 + public static final int IDENTIFIER_LENGTH = 16;
55 + private long identifier;
56 + private byte protocolId;
57 + private BGPNodeLSIdentifier localNodeDescriptors;
58 + private RouteDistinguisher routeDistinguisher;
59 + private boolean isVpn;
60 +
61 + /**
62 + * Enum to provide PROTOCOLTYPE.
63 + */
64 + public enum PROTOCOLTYPE {
65 + ISIS_LevelOne(1), ISIS_LevelTwo(2), OSPFv2(3), Direct(4), Static_Configuration(5), OSPFv3(6);
66 + int value;
67 +
68 + /**
69 + * Assign val with the value as the protocol type.
70 + *
71 + * @param val protocol type
72 + */
73 + PROTOCOLTYPE(int val) {
74 + value = val;
75 + }
76 +
77 + /**
78 + * Returns value of protocol type.
79 + *
80 + * @return protocol type
81 + */
82 + public byte getType() {
83 + return (byte) value;
84 + }
85 + }
86 +
87 + /**
88 + * Reset fields.
89 + */
90 + public BGPNodeLSNlriVer4() {
91 + this.identifier = 0;
92 + this.protocolId = 0;
93 + this.localNodeDescriptors = null;
94 + this.routeDistinguisher = null;
95 + this.isVpn = false;
96 + }
97 +
98 + /**
99 + * Constructors to initialize its parameters.
100 + *
101 + * @param identifier of LinkState Nlri
102 + * @param protocolId of LinkState Nlri
103 + * @param localNodeDescriptors local node descriptors
104 + * @param isVpn true if VPN info is present
105 + * @param routeDistinguisher unique for each VPN
106 + */
107 + BGPNodeLSNlriVer4(long identifier, byte protocolId, BGPNodeLSIdentifier localNodeDescriptors, boolean isVpn,
108 + RouteDistinguisher routeDistinguisher) {
109 + this.identifier = identifier;
110 + this.protocolId = protocolId;
111 + this.localNodeDescriptors = localNodeDescriptors;
112 + this.routeDistinguisher = routeDistinguisher;
113 + this.isVpn = isVpn;
114 + }
115 +
116 + /**
117 + * Reads from channelBuffer and parses Node LS Nlri.
118 + *
119 + * @param cb ChannelBuffer
120 + * @param afi Address Family Identifier
121 + * @param safi Subsequent Address Family Identifier
122 + * @return object of this class
123 + * @throws BGPParseException while parsing node descriptors
124 + */
125 + public static BGPNodeLSNlriVer4 read(ChannelBuffer cb, short afi, byte safi) throws BGPParseException {
126 + boolean isVpn = false;
127 + RouteDistinguisher routeDistinguisher = null;
128 + if ((afi == Constants.AFI_VALUE) && (safi == Constants.VPN_SAFI_VALUE)) {
129 + routeDistinguisher = new RouteDistinguisher();
130 + routeDistinguisher = RouteDistinguisher.read(cb);
131 + isVpn = true;
132 + } else {
133 + isVpn = false;
134 + }
135 + byte protocolId = cb.readByte();
136 + long identifier = cb.readLong();
137 +
138 + // Parse Local Node Descriptors
139 + BGPNodeLSIdentifier localNodeDescriptors = new BGPNodeLSIdentifier();
140 + localNodeDescriptors = BGPNodeLSIdentifier.parseLocalNodeDescriptors(cb, protocolId);
141 + return new BGPNodeLSNlriVer4(identifier, protocolId, localNodeDescriptors, isVpn, routeDistinguisher);
142 + }
143 +
144 + @Override
145 + public NlriType getNlriType() {
146 + return NlriType.NODE;
147 + }
148 +
149 + @Override
150 + public BGPNodeLSIdentifier getLocalNodeDescriptors() {
151 + return this.localNodeDescriptors;
152 + }
153 +
154 + /**
155 + * Returns whether VPN is present or not.
156 + *
157 + * @return whether VPN is present or not
158 + */
159 + public boolean isVpnPresent() {
160 + return this.isVpn;
161 + }
162 +
163 + @Override
164 + public RouteDistinguisher getRouteDistinguisher() {
165 + return this.routeDistinguisher;
166 + }
167 +
168 + @Override
169 + public long getIdentifier() {
170 + return this.identifier;
171 + }
172 +
173 + /**
174 + * Set the node LS identifier.
175 + *
176 + * @param localNodeDescriptors node LS identifier to set
177 + */
178 + public void setNodeLSIdentifier(BGPNodeLSIdentifier localNodeDescriptors) {
179 + this.localNodeDescriptors = localNodeDescriptors;
180 + }
181 +
182 + @Override
183 + public PROTOCOLTYPE getProtocolId() throws BGPParseException {
184 + switch (protocolId) {
185 + case Constants.ISIS_LEVELONE:
186 + return PROTOCOLTYPE.ISIS_LevelOne;
187 + case Constants.ISIS_LEVELTWO:
188 + return PROTOCOLTYPE.ISIS_LevelTwo;
189 + case Constants.OSPFV2:
190 + return PROTOCOLTYPE.OSPFv2;
191 + case Constants.DIRECT:
192 + return PROTOCOLTYPE.Direct;
193 + case Constants.STATIC_CONFIGURATION:
194 + return PROTOCOLTYPE.Static_Configuration;
195 + case Constants.OSPFV3:
196 + return PROTOCOLTYPE.OSPFv3;
197 + default:
198 + throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, (byte) 0, null);
199 + }
200 + }
201 +
202 + @Override
203 + public String toString() {
204 + return MoreObjects.toStringHelper(getClass())
205 + .omitNullValues()
206 + .add("protocolId", protocolId)
207 + .add("identifier", identifier)
208 + .add("RouteDistinguisher ", routeDistinguisher)
209 + .add("localNodeDescriptors", localNodeDescriptors)
210 + .toString();
211 + }
212 +}
...\ 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.link_state;
17 +
18 +import java.util.LinkedList;
19 +
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.bgpio.exceptions.BGPParseException;
22 +import org.onosproject.bgpio.protocol.BGPPrefixLSNlri;
23 +import org.onosproject.bgpio.protocol.NlriType;
24 +import org.onosproject.bgpio.protocol.link_state.BGPNodeLSNlriVer4.PROTOCOLTYPE;
25 +import org.onosproject.bgpio.types.BGPValueType;
26 +import org.onosproject.bgpio.types.RouteDistinguisher;
27 +import org.onosproject.bgpio.util.Constants;
28 +import org.slf4j.Logger;
29 +import org.slf4j.LoggerFactory;
30 +
31 +import com.google.common.base.MoreObjects;
32 +
33 +/**
34 + * Implementation of Prefix IPV4 LS NLRI.
35 + */
36 +public class BGPPrefixIPv4LSNlriVer4 implements BGPPrefixLSNlri {
37 +
38 + /*
39 + * REFERENCE : draft-ietf-idr-ls-distribution-11
40 + * 0 1 2 3
41 + 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
42 + +-+-+-+-+-+-+-+-+
43 + | Protocol-ID |
44 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
45 + | Identifier |
46 + | (64 bits) |
47 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
48 + // Local Node Descriptor (variable) //
49 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
50 + // Prefix Descriptors (variable) //
51 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
52 +
53 + Figure : The IPv4/IPv6 Topology Prefix NLRI format
54 + */
55 +
56 + protected static final Logger log = LoggerFactory.getLogger(BGPPrefixIPv4LSNlriVer4.class);
57 +
58 + public static final int PREFIX_IPV4_NLRITYPE = 3;
59 + public static final int IDENTIFIER_LENGTH = 16;
60 + private long identifier;
61 + private byte protocolId;
62 + private RouteDistinguisher routeDistinguisher;
63 + private boolean isVpn;
64 + private BGPPrefixLSIdentifier bgpPrefixLSIdentifier;
65 +
66 + /**
67 + * Resets parameters.
68 + */
69 + public BGPPrefixIPv4LSNlriVer4() {
70 + this.identifier = 0;
71 + this.protocolId = 0;
72 + this.bgpPrefixLSIdentifier = null;
73 + this.routeDistinguisher = null;
74 + this.isVpn = false;
75 + }
76 +
77 + /**
78 + * Constructor to initialize parameters for BGP PrefixLSNlri.
79 + *
80 + * @param identifier field in BGP PrefixLSNlri
81 + * @param protocolId protocol Id
82 + * @param bgpPrefixLSIdentifier prefix LS Identifier
83 + * @param routeDistinguisher RouteDistinguisher
84 + * @param isVpn vpn availability in message
85 + */
86 + public BGPPrefixIPv4LSNlriVer4(long identifier, byte protocolId, BGPPrefixLSIdentifier bgpPrefixLSIdentifier,
87 + RouteDistinguisher routeDistinguisher, boolean isVpn) {
88 + this.identifier = identifier;
89 + this.protocolId = protocolId;
90 + this.bgpPrefixLSIdentifier = bgpPrefixLSIdentifier;
91 + this.routeDistinguisher = routeDistinguisher;
92 + this.isVpn = isVpn;
93 + }
94 +
95 + /**
96 + * Reads from channelBuffer and parses Prefix LS Nlri.
97 + *
98 + * @param cb ChannelBuffer
99 + * @param afi Address family identifier
100 + * @param safi Subsequent address family identifier
101 + * @return object of BGPPrefixIPv4LSNlriVer4
102 + * @throws BGPParseException while parsing Prefix LS Nlri
103 + */
104 + public static BGPPrefixIPv4LSNlriVer4 read(ChannelBuffer cb, short afi, byte safi) throws BGPParseException {
105 +
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 + BGPPrefixLSIdentifier bgpPrefixLSIdentifier = new BGPPrefixLSIdentifier();
119 + bgpPrefixLSIdentifier = BGPPrefixLSIdentifier.parsePrefixIdendifier(cb, protocolId);
120 + return new BGPPrefixIPv4LSNlriVer4(identifier, protocolId, bgpPrefixLSIdentifier, routeDistinguisher, isVpn);
121 + }
122 +
123 + @Override
124 + public NlriType getNlriType() {
125 + return NlriType.PREFIX_IPV4;
126 + }
127 +
128 + @Override
129 + public NodeDescriptors getLocalNodeDescriptors() {
130 + return this.bgpPrefixLSIdentifier.getLocalNodeDescriptors();
131 + }
132 +
133 + @Override
134 + public long getIdentifier() {
135 + return this.identifier;
136 + }
137 +
138 + /**
139 + * Set the prefix LS identifier.
140 + *
141 + * @param bgpPrefixLSIdentifier prefix identifier to set
142 + */
143 + public void setPrefixLSIdentifier(BGPPrefixLSIdentifier bgpPrefixLSIdentifier) {
144 + this.bgpPrefixLSIdentifier = bgpPrefixLSIdentifier;
145 + }
146 +
147 + @Override
148 + public PROTOCOLTYPE getProtocolId() throws BGPParseException {
149 + switch (protocolId) {
150 + case Constants.ISIS_LEVELONE:
151 + return PROTOCOLTYPE.ISIS_LevelOne;
152 + case Constants.ISIS_LEVELTWO:
153 + return PROTOCOLTYPE.ISIS_LevelTwo;
154 + case Constants.OSPFV2:
155 + return PROTOCOLTYPE.OSPFv2;
156 + case Constants.DIRECT:
157 + return PROTOCOLTYPE.Direct;
158 + case Constants.STATIC_CONFIGURATION:
159 + return PROTOCOLTYPE.Static_Configuration;
160 + case Constants.OSPFV3:
161 + return PROTOCOLTYPE.OSPFv3;
162 + default:
163 + throw new BGPParseException("protocol id not valid");
164 + }
165 + }
166 +
167 + /**
168 + * Returns whether VPN is present or not.
169 + *
170 + * @return whether VPN is present or not
171 + */
172 + public boolean isVpnPresent() {
173 + return this.isVpn;
174 + }
175 +
176 + /**
177 + * Returns Prefix Identifier.
178 + *
179 + * @return Prefix Identifier
180 + */
181 + public BGPPrefixLSIdentifier getPrefixIdentifier() {
182 + return this.bgpPrefixLSIdentifier;
183 + }
184 +
185 + @Override
186 + public RouteDistinguisher getRouteDistinguisher() {
187 + return this.routeDistinguisher;
188 + }
189 +
190 + @Override
191 + public LinkedList<BGPValueType> getPrefixdescriptor() {
192 + return this.bgpPrefixLSIdentifier.getPrefixdescriptor();
193 + }
194 +
195 + @Override
196 + public String toString() {
197 + return MoreObjects.toStringHelper(getClass())
198 + .omitNullValues()
199 + .add("protocolId", protocolId)
200 + .add("identifier", identifier)
201 + .add("RouteDistinguisher ", routeDistinguisher)
202 + .add("bgpPrefixLSIdentifier", bgpPrefixLSIdentifier)
203 + .toString();
204 + }
205 +}
...\ 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 +
17 +package org.onosproject.bgpio.types;
18 +
19 +import org.jboss.netty.buffer.ChannelBuffer;
20 +
21 +/**
22 + * Implementation of RouteDistinguisher.
23 + */
24 +public class RouteDistinguisher {
25 +
26 + private long routeDistinguisher;
27 +
28 + /**
29 + * Resets fields.
30 + */
31 + public RouteDistinguisher() {
32 + this.routeDistinguisher = 0;
33 + }
34 +
35 + /**
36 + * Constructor to initialize parameters.
37 + *
38 + * @param routeDistinguisher route distinguisher
39 + */
40 + public RouteDistinguisher(long routeDistinguisher) {
41 + this.routeDistinguisher = routeDistinguisher;
42 + }
43 +
44 + /**
45 + * Reads route distinguisher from channelBuffer.
46 + *
47 + * @param cb channelBuffer
48 + * @return object of RouteDistinguisher
49 + */
50 + public static RouteDistinguisher read(ChannelBuffer cb) {
51 + return new RouteDistinguisher(cb.readLong());
52 + }
53 +
54 + /**
55 + * Returns route distinguisher.
56 + *
57 + * @return route distinguisher
58 + */
59 + public long getRouteDistinguisher() {
60 + return this.routeDistinguisher;
61 + }
62 +}
...\ 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.util;
17 +
18 +/**
19 + * Provides Constants usage for BGP.
20 + */
21 +public final class Constants {
22 + private Constants() {
23 + }
24 +
25 + public static final short TYPE_AND_LEN = 4;
26 + public static final short TYPE_AND_LEN_AS_SHORT = 4;
27 + public static final short TYPE_AND_LEN_AS_BYTE = 3;
28 + public static final int ISIS_LEVELONE = 1;
29 + public static final int ISIS_LEVELTWO = 2;
30 + public static final int OSPFV2 = 3;
31 + public static final int DIRECT = 4;
32 + public static final int STATIC_CONFIGURATION = 5;
33 + public static final int OSPFV3 = 6;
34 + public static final short AFI_VALUE = 16388;
35 + public static final byte VPN_SAFI_VALUE = (byte) 0x80;
36 + public static final byte SAFI_VALUE = 71;
37 +}
...\ No newline at end of file ...\ No newline at end of file