Priyanka B | 0ab34b9 | 2015-12-03 21:13:52 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame^] | 2 | * Copyright 2015-present Open Networking Laboratory |
Priyanka B | 0ab34b9 | 2015-12-03 21:13:52 +0530 | [diff] [blame] | 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 | |
Priyanka B | 0ab34b9 | 2015-12-03 21:13:52 +0530 | [diff] [blame] | 19 | import org.jboss.netty.buffer.ChannelBuffer; |
| 20 | import org.jboss.netty.buffer.ChannelBuffers; |
| 21 | import org.junit.Test; |
| 22 | import org.onlab.packet.Ip4Address; |
| 23 | import org.onlab.packet.IpAddress; |
| 24 | import org.onlab.packet.IpPrefix; |
| 25 | import org.onosproject.bgpio.exceptions.BgpParseException; |
| 26 | import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4; |
| 27 | import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSIdentifier; |
| 28 | import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4; |
| 29 | import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType; |
| 30 | import org.onosproject.bgpio.protocol.linkstate.NodeDescriptors; |
| 31 | import org.onosproject.bgpio.protocol.ver4.BgpPathAttributes; |
| 32 | import org.onosproject.bgpio.types.As4Path; |
| 33 | import org.onosproject.bgpio.types.AsPath; |
| 34 | import org.onosproject.bgpio.types.AutonomousSystemTlv; |
| 35 | import org.onosproject.bgpio.types.BgpHeader; |
| 36 | import org.onosproject.bgpio.types.BgpLSIdentifierTlv; |
| 37 | import org.onosproject.bgpio.types.BgpValueType; |
| 38 | import org.onosproject.bgpio.types.IPReachabilityInformationTlv; |
| 39 | import org.onosproject.bgpio.types.IsIsNonPseudonode; |
| 40 | import org.onosproject.bgpio.types.IsIsPseudonode; |
| 41 | import org.onosproject.bgpio.types.LinkStateAttributes; |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 42 | import org.onosproject.bgpio.types.LocalPref; |
Priyanka B | 0ab34b9 | 2015-12-03 21:13:52 +0530 | [diff] [blame] | 43 | import org.onosproject.bgpio.types.Med; |
| 44 | import org.onosproject.bgpio.types.MpReachNlri; |
| 45 | import org.onosproject.bgpio.types.MpUnReachNlri; |
Priyanka B | 0ab34b9 | 2015-12-03 21:13:52 +0530 | [diff] [blame] | 46 | import org.onosproject.bgpio.types.NextHop; |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 47 | import org.onosproject.bgpio.types.Origin; |
| 48 | import org.onosproject.bgpio.types.Origin.OriginType; |
Priyanka B | 0ab34b9 | 2015-12-03 21:13:52 +0530 | [diff] [blame] | 49 | import org.onosproject.bgpio.types.attr.BgpAttrRouterIdV4; |
| 50 | import org.onosproject.bgpio.types.attr.BgpLinkAttrName; |
| 51 | import org.onosproject.bgpio.types.attr.BgpPrefixAttrExtRouteTag; |
| 52 | import org.onosproject.bgpio.types.attr.BgpPrefixAttrIgpFlags; |
| 53 | import org.slf4j.Logger; |
| 54 | import org.slf4j.LoggerFactory; |
| 55 | |
| 56 | import java.util.LinkedList; |
| 57 | import java.util.List; |
| 58 | import java.util.ListIterator; |
| 59 | |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 60 | import static org.hamcrest.MatcherAssert.assertThat; |
| 61 | import static org.hamcrest.Matchers.instanceOf; |
| 62 | import static org.hamcrest.core.Is.is; |
| 63 | |
Priyanka B | 0ab34b9 | 2015-12-03 21:13:52 +0530 | [diff] [blame] | 64 | /** |
| 65 | * Test cases for BGP update Message. |
| 66 | */ |
| 67 | public class BgpUpdateMsgTest { |
| 68 | protected static final Logger log = LoggerFactory.getLogger(BgpUpdateMsgTest.class); |
| 69 | public static final byte[] MARKER = new byte[]{(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 70 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 71 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff}; |
| 72 | public static final byte UPDATE_MSG_TYPE = 0x2; |
| 73 | |
| 74 | /** |
| 75 | * This test case checks update message with no withdrawn routes |
| 76 | * and path attributes. |
| 77 | */ |
| 78 | @Test |
| 79 | public void bgpUpdateMessageTest01() throws BgpParseException { |
| 80 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 81 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 82 | (byte) 0xff, (byte) 0xff, 0x00, 0x17, 0x02, 0x00, 0x00, 0x00, 0x00}; |
| 83 | |
| 84 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 85 | buffer.writeBytes(updateMsg); |
| 86 | |
| 87 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 88 | BgpMessage message; |
| 89 | BgpHeader bgpHeader = new BgpHeader(); |
| 90 | |
| 91 | message = reader.readFrom(buffer, bgpHeader); |
| 92 | |
| 93 | assertThat(message, instanceOf(BgpUpdateMsg.class)); |
| 94 | BgpUpdateMsg other = (BgpUpdateMsg) message; |
| 95 | |
| 96 | assertThat(other.getHeader().getMarker(), is(MARKER)); |
| 97 | assertThat(other.getHeader().getType(), is(UPDATE_MSG_TYPE)); |
| 98 | assertThat(other.getHeader().getLength(), is((short) 23)); |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * In this test case, Marker is set as 0 in input and expecting |
| 103 | * an exception. |
| 104 | */ |
| 105 | @Test(expected = BgpParseException.class) |
| 106 | public void bgpUpdateMessageTest02() throws BgpParseException { |
| 107 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 108 | 0x00, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 109 | (byte) 0xff, (byte) 0xff, 0x00, 0x17, 0x02, 0x00, 0x00, 0x00, 0x00}; |
| 110 | |
| 111 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 112 | buffer.writeBytes(updateMsg); |
| 113 | |
| 114 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 115 | BgpMessage message; |
| 116 | BgpHeader bgpHeader = new BgpHeader(); |
| 117 | message = reader.readFrom(buffer, bgpHeader); |
| 118 | |
| 119 | assertThat(message, instanceOf(BgpUpdateMsg.class)); |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * In this test case, Invalid message length is given as input and expecting |
| 124 | * an exception. |
| 125 | */ |
| 126 | @Test(expected = BgpParseException.class) |
| 127 | public void bgpUpdateMessageTest03() throws BgpParseException { |
| 128 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 129 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 130 | (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, 0x18, 0x02, 0x00, 0x00, 0x00, 0x00}; |
| 131 | |
| 132 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 133 | buffer.writeBytes(updateMsg); |
| 134 | |
| 135 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 136 | BgpMessage message; |
| 137 | BgpHeader bgpHeader = new BgpHeader(); |
| 138 | message = reader.readFrom(buffer, bgpHeader); |
| 139 | |
| 140 | assertThat(message, instanceOf(BgpUpdateMsg.class)); |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * In this test case, Invalid message type is given as input and expecting |
| 145 | * an exception. |
| 146 | */ |
| 147 | @Test(expected = BgpParseException.class) |
| 148 | public void bgpUpdateMessageTest04() throws BgpParseException { |
| 149 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 150 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 151 | (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, 0x17, 0x06, 0x00, 0x00, 0x00, 0x00}; |
| 152 | |
| 153 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 154 | buffer.writeBytes(updateMsg); |
| 155 | |
| 156 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 157 | BgpMessage message; |
| 158 | BgpHeader bgpHeader = new BgpHeader(); |
| 159 | message = reader.readFrom(buffer, bgpHeader); |
| 160 | |
| 161 | assertThat(message, instanceOf(BgpUpdateMsg.class)); |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * This test case checks update message with withdrawn routes. |
| 166 | */ |
| 167 | @Test |
| 168 | public void bgpUpdateMessageTest05() throws BgpParseException { |
| 169 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 170 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 171 | (byte) 0xff, (byte) 0xff, 0x00, 0x1b, 0x02, 0x00, 0x04, 0x18, 0x0a, 0x01, 0x01, 0x00, 0x00}; |
| 172 | |
| 173 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 174 | buffer.writeBytes(updateMsg); |
| 175 | |
| 176 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 177 | BgpMessage message; |
| 178 | BgpHeader bgpHeader = new BgpHeader(); |
| 179 | |
| 180 | message = reader.readFrom(buffer, bgpHeader); |
| 181 | |
| 182 | assertThat(message, instanceOf(BgpUpdateMsg.class)); |
| 183 | BgpUpdateMsg other = (BgpUpdateMsg) message; |
| 184 | |
| 185 | assertThat(other.getHeader().getMarker(), is(MARKER)); |
| 186 | assertThat(other.getHeader().getType(), is(UPDATE_MSG_TYPE)); |
| 187 | assertThat(other.getHeader().getLength(), is((short) 27)); |
| 188 | |
| 189 | ListIterator<IpPrefix> listIterator1 = other.withdrawnRoutes().listIterator(); |
| 190 | byte[] prefix = new byte[] {0x0a, 0x01, 0x01, 0x00}; |
| 191 | |
| 192 | IpPrefix testPrefixValue = listIterator1.next(); |
| 193 | assertThat(testPrefixValue.prefixLength(), is((int) 24)); |
| 194 | assertThat(testPrefixValue.address().toOctets(), is(prefix)); |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * In this test case, Invalid withdrawn route length is given as input and expecting |
| 199 | * an exception. |
| 200 | */ |
| 201 | @Test(expected = BgpParseException.class) |
| 202 | public void bgpUpdateMessageTest06() throws BgpParseException { |
| 203 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 204 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 205 | (byte) 0xff, (byte) 0xff, 0x00, 0x1b, 0x02, 0x00, 0x04, 0x19, 0x0a, 0x01, 0x01, 0x00, 0x00}; |
| 206 | |
| 207 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 208 | buffer.writeBytes(updateMsg); |
| 209 | |
| 210 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 211 | BgpMessage message; |
| 212 | BgpHeader bgpHeader = new BgpHeader(); |
| 213 | |
| 214 | message = reader.readFrom(buffer, bgpHeader); |
| 215 | |
| 216 | assertThat(message, instanceOf(BgpUpdateMsg.class)); |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * This test case checks update message with path attributes. |
| 221 | */ |
| 222 | @Test |
| 223 | public void bgpUpdateMessageTest07() throws BgpParseException { |
Jian Li | 68c4fc4 | 2016-01-11 16:07:03 -0800 | [diff] [blame] | 224 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
Priyanka B | 0ab34b9 | 2015-12-03 21:13:52 +0530 | [diff] [blame] | 225 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 226 | (byte) 0xff, (byte) 0xff, 0x00, 0x3f, 0x02, 0x00, 0x00, 0x00, 0x1c, 0x40, 0x01, 0x01, |
| 227 | 0x00, 0x40, 0x02, 0x00, 0x40, 0x03, 0x04, 0x03, 0x03, 0x03, 0x03, (byte) 0x80, 0x04, 0x04, 0x00, 0x00, |
| 228 | 0x00, 0x00, 0x40, 0x05, 0x04, 0x00, 0x00, 0x00, 0x64, 0x18, 0x0a, 0x1e, 0x03, 0x18, 0x0a, 0x1e, |
| 229 | 0x02, 0x18, 0x0a, 0x1e, 0x01}; |
| 230 | |
| 231 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 232 | buffer.writeBytes(updateMsg); |
| 233 | |
| 234 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 235 | BgpMessage message; |
| 236 | BgpHeader bgpHeader = new BgpHeader(); |
| 237 | |
| 238 | message = reader.readFrom(buffer, bgpHeader); |
| 239 | |
| 240 | assertThat(message, instanceOf(BgpUpdateMsg.class)); |
| 241 | BgpUpdateMsg other = (BgpUpdateMsg) message; |
| 242 | |
| 243 | assertThat(other.getHeader().getMarker(), is(MARKER)); |
| 244 | assertThat(other.getHeader().getType(), is(UPDATE_MSG_TYPE)); |
| 245 | assertThat(other.getHeader().getLength(), is((short) 63)); |
| 246 | |
| 247 | BgpValueType testPathAttribute; |
| 248 | Origin origin; |
| 249 | AsPath asPath; |
| 250 | NextHop nexthop; |
| 251 | Med med; |
| 252 | LocalPref localPref; |
| 253 | |
| 254 | List<BgpValueType> pathAttributes = new LinkedList<>(); |
| 255 | BgpPathAttributes actualpathAttribute = other.bgpPathAttributes(); |
| 256 | pathAttributes = actualpathAttribute.pathAttributes(); |
| 257 | ListIterator<BgpValueType> listIterator = pathAttributes.listIterator(); |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 258 | OriginType originValue = OriginType.IGP; |
Priyanka B | 0ab34b9 | 2015-12-03 21:13:52 +0530 | [diff] [blame] | 259 | |
| 260 | testPathAttribute = listIterator.next(); |
| 261 | origin = (Origin) testPathAttribute; |
| 262 | assertThat(origin.origin(), is(originValue)); |
| 263 | |
| 264 | testPathAttribute = listIterator.next(); // AS PATH value is empty in hex dump |
| 265 | asPath = (AsPath) testPathAttribute; |
| 266 | List<Short> asPathValues = asPath.asPathSeq(); |
| 267 | assertThat(asPathValues.isEmpty(), is(true)); |
| 268 | |
| 269 | testPathAttribute = listIterator.next(); |
| 270 | nexthop = (NextHop) testPathAttribute; |
| 271 | byte[] nextHopAddr = new byte[] {0x03, 0x03, 0x03, 0x03}; |
| 272 | assertThat(nexthop.nextHop().toOctets(), is(nextHopAddr)); |
| 273 | |
| 274 | testPathAttribute = listIterator.next(); |
| 275 | med = (Med) testPathAttribute; |
| 276 | assertThat(med.med(), is(0)); |
| 277 | |
| 278 | testPathAttribute = listIterator.next(); |
| 279 | localPref = (LocalPref) testPathAttribute; |
| 280 | assertThat(localPref.localPref(), is(100)); |
| 281 | |
| 282 | ListIterator<IpPrefix> listIterator1 = other.nlri().listIterator(); |
| 283 | byte[] prefix = new byte[] {0x0a, 0x1e, 0x03, 0x00}; |
| 284 | |
| 285 | IpPrefix testPrefixValue = listIterator1.next(); |
| 286 | assertThat(testPrefixValue.prefixLength(), is((int) 24)); |
| 287 | assertThat(testPrefixValue.address().toOctets(), is(prefix)); |
| 288 | } |
| 289 | |
| 290 | /** |
| 291 | * In this test case, Invalid ORIGIN flags is given as input and expecting |
| 292 | * an exception. |
| 293 | */ |
| 294 | @Test(expected = BgpParseException.class) |
| 295 | public void bgpUpdateMessageTest08() throws BgpParseException { |
| 296 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 297 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 298 | (byte) 0xff, (byte) 0xff, 0x00, 0x60, 0x02, 0x00, 0x00, //withdrawn len |
| 299 | 0x00, 0x49, //path attribute len |
| 300 | (byte) 0xff, 0x01, 0x01, 0x00, //origin |
| 301 | 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path |
| 302 | (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med |
| 303 | (byte) 0x80, 0x0e, 0x34, 0x40, 0x04, 0x47, //mpreach with safi = 71 |
| 304 | 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop |
| 305 | 0x00, //reserved |
| 306 | 0x00, 0x01, 0x00, |
| 307 | 0x27, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, |
| 308 | 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, |
| 309 | 0x00, 0x06, 0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58}; //node nlri}; |
| 310 | |
| 311 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 312 | buffer.writeBytes(updateMsg); |
| 313 | |
| 314 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 315 | BgpMessage message; |
| 316 | BgpHeader bgpHeader = new BgpHeader(); |
| 317 | |
| 318 | message = reader.readFrom(buffer, bgpHeader); |
| 319 | |
| 320 | assertThat(message, instanceOf(BgpUpdateMsg.class)); |
| 321 | } |
| 322 | |
| 323 | /** |
| 324 | * In this test case, Invalid ORIGIN value is given as input and expecting |
| 325 | * an exception. |
| 326 | */ |
| 327 | @Test(expected = BgpParseException.class) |
| 328 | public void bgpUpdateMessageTest09() throws BgpParseException { |
| 329 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 330 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 331 | (byte) 0xff, (byte) 0xff, 0x00, 0x60, 0x02, 0x00, 0x00, //withdrawn len |
| 332 | 0x00, 0x49, //path attribute len |
| 333 | (byte) 0xff, 0x01, 0x04, 0x00, //origin |
| 334 | 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path |
| 335 | (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med |
| 336 | (byte) 0x80, 0x0e, 0x34, 0x40, 0x04, 0x47, //mpreach with safi = 71 |
| 337 | 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop |
| 338 | 0x00, //reserved |
| 339 | 0x00, 0x01, 0x00, |
| 340 | 0x27, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, |
| 341 | 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, |
| 342 | 0x00, 0x06, 0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58}; //node nlri}; |
| 343 | |
| 344 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 345 | buffer.writeBytes(updateMsg); |
| 346 | |
| 347 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 348 | BgpMessage message; |
| 349 | BgpHeader bgpHeader = new BgpHeader(); |
| 350 | |
| 351 | message = reader.readFrom(buffer, bgpHeader); |
| 352 | |
| 353 | assertThat(message, instanceOf(BgpUpdateMsg.class)); |
| 354 | } |
| 355 | |
| 356 | /** |
| 357 | * In this test case, update message without path attribute is given as input and expecting |
| 358 | * an exception. |
| 359 | */ |
| 360 | @Test(expected = BgpParseException.class) |
| 361 | public void bgpUpdateMessageTest10() throws BgpParseException { |
| 362 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 363 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 364 | (byte) 0xff, (byte) 0xff, 0x00, 0x1a, 0x02, 0x00, 0x04, 0x18, 0x0a, 0x01, 0x01, 0x00}; |
| 365 | |
| 366 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 367 | buffer.writeBytes(updateMsg); |
| 368 | |
| 369 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 370 | BgpMessage message; |
| 371 | BgpHeader bgpHeader = new BgpHeader(); |
| 372 | |
| 373 | message = reader.readFrom(buffer, bgpHeader); |
| 374 | |
| 375 | assertThat(message, instanceOf(BgpUpdateMsg.class)); |
| 376 | } |
| 377 | |
| 378 | /** |
| 379 | * In this test case, update message with incorrect path attribute length is given as input and expecting |
| 380 | * an exception. |
| 381 | */ |
| 382 | @Test(expected = BgpParseException.class) |
| 383 | public void bgpUpdateMessageTest11() throws BgpParseException { |
| 384 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 385 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 386 | (byte) 0xff, (byte) 0xff, 0x00, 0x1b, 0x02, 0x00, 0x04, 0x18, 0x0a, 0x01, 0x01, 0x00, 0x01}; |
| 387 | |
| 388 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 389 | buffer.writeBytes(updateMsg); |
| 390 | |
| 391 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 392 | BgpMessage message; |
| 393 | BgpHeader bgpHeader = new BgpHeader(); |
| 394 | |
| 395 | message = reader.readFrom(buffer, bgpHeader); |
| 396 | |
| 397 | assertThat(message, instanceOf(BgpUpdateMsg.class)); |
| 398 | } |
| 399 | |
| 400 | /** |
| 401 | * In this test case, Invalid MED flags is given as input and expecting |
| 402 | * an exception. |
| 403 | */ |
| 404 | @Test(expected = BgpParseException.class) |
| 405 | public void bgpUpdateMessageTest12() throws BgpParseException { |
| 406 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 407 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 408 | (byte) 0xff, (byte) 0xff, 0x00, 0x60, 0x02, 0x00, 0x00, //withdrawn len |
| 409 | 0x00, 0x49, //path attribute len |
| 410 | (byte) 0xff, 0x01, 0x01, 0x00, //origin |
| 411 | 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path |
| 412 | (byte) 0xff, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med |
| 413 | (byte) 0x80, 0x0e, 0x34, 0x40, 0x04, 0x47, //mpreach with safi = 71 |
| 414 | 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop |
| 415 | 0x00, //reserved |
| 416 | 0x00, 0x01, 0x00, |
| 417 | 0x27, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, |
| 418 | 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, |
| 419 | 0x00, 0x06, 0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58}; //node nlri}; |
| 420 | |
| 421 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 422 | buffer.writeBytes(updateMsg); |
| 423 | |
| 424 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 425 | BgpMessage message; |
| 426 | BgpHeader bgpHeader = new BgpHeader(); |
| 427 | |
| 428 | message = reader.readFrom(buffer, bgpHeader); |
| 429 | |
| 430 | assertThat(message, instanceOf(BgpUpdateMsg.class)); |
| 431 | } |
| 432 | |
| 433 | /** |
| 434 | * In this test case, Invalid AS Path flags is given as input and expecting |
| 435 | * an exception. |
| 436 | */ |
| 437 | @Test(expected = BgpParseException.class) |
| 438 | public void bgpUpdateMessageTest13() throws BgpParseException { |
| 439 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 440 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 441 | (byte) 0xff, (byte) 0xff, 0x00, 0x60, 0x02, 0x00, 0x00, //withdrawn len |
| 442 | 0x00, 0x49, //path attribute len |
| 443 | (byte) 0xff, 0x01, 0x01, 0x00, //origin |
| 444 | (byte) 0xff, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path |
| 445 | (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med |
| 446 | (byte) 0x80, 0x0e, 0x34, 0x40, 0x04, 0x47, //mpreach with safi = 71 |
| 447 | 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop |
| 448 | 0x00, //reserved |
| 449 | 0x00, 0x01, 0x00, |
| 450 | 0x27, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, |
| 451 | 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, |
| 452 | 0x00, 0x06, 0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58}; //node nlri}; |
| 453 | |
| 454 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 455 | buffer.writeBytes(updateMsg); |
| 456 | |
| 457 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 458 | BgpMessage message; |
| 459 | BgpHeader bgpHeader = new BgpHeader(); |
| 460 | |
| 461 | message = reader.readFrom(buffer, bgpHeader); |
| 462 | |
| 463 | assertThat(message, instanceOf(BgpUpdateMsg.class)); |
| 464 | } |
| 465 | |
| 466 | /** |
| 467 | * In this test case, Invalid MP reach flags is given as input and expecting |
| 468 | * an exception. |
| 469 | */ |
| 470 | @Test(expected = BgpParseException.class) |
| 471 | public void bgpUpdateMessageTest14() throws BgpParseException { |
| 472 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 473 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 474 | (byte) 0xff, (byte) 0xff, 0x00, 0x60, 0x02, 0x00, 0x00, //withdrawn len |
| 475 | 0x00, 0x49, //path attribute len |
| 476 | (byte) 0xff, 0x01, 0x01, 0x00, //origin |
| 477 | 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path |
| 478 | (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med |
| 479 | (byte) 0xff, 0x0e, 0x34, 0x40, 0x04, 0x47, //mpreach with safi = 71 |
| 480 | 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop |
| 481 | 0x00, //reserved |
| 482 | 0x00, 0x01, 0x00, |
| 483 | 0x27, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, |
| 484 | 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, |
| 485 | 0x00, 0x06, 0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58}; //node nlri}; |
| 486 | |
| 487 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 488 | buffer.writeBytes(updateMsg); |
| 489 | |
| 490 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 491 | BgpMessage message; |
| 492 | BgpHeader bgpHeader = new BgpHeader(); |
| 493 | |
| 494 | message = reader.readFrom(buffer, bgpHeader); |
| 495 | |
| 496 | assertThat(message, instanceOf(BgpUpdateMsg.class)); |
| 497 | } |
| 498 | |
| 499 | /** |
| 500 | * In this test case, Invalid SAFI is given as input and expecting |
| 501 | * an exception. |
| 502 | */ |
| 503 | @Test(expected = BgpParseException.class) |
| 504 | public void bgpUpdateMessageTest15() throws BgpParseException { |
| 505 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 506 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 507 | (byte) 0xff, (byte) 0xff, 0x00, 0x60, 0x02, 0x00, 0x00, //withdrawn len |
| 508 | 0x00, 0x49, //path attribute len |
| 509 | (byte) 0xff, 0x01, 0x01, 0x00, //origin |
| 510 | 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path |
| 511 | (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med |
| 512 | (byte) 0x80, 0x0e, 0x34, 0x40, 0x04, 0x49, //mpreach with safi = 71 |
| 513 | 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop |
| 514 | 0x00, //reserved |
| 515 | 0x00, 0x01, 0x00, |
| 516 | 0x27, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, |
| 517 | 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, |
| 518 | 0x00, 0x06, 0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58}; //node nlri}; |
| 519 | |
| 520 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 521 | buffer.writeBytes(updateMsg); |
| 522 | |
| 523 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 524 | BgpMessage message; |
| 525 | BgpHeader bgpHeader = new BgpHeader(); |
| 526 | |
| 527 | message = reader.readFrom(buffer, bgpHeader); |
| 528 | |
| 529 | assertThat(message, instanceOf(BgpUpdateMsg.class)); |
| 530 | } |
| 531 | |
| 532 | /** |
| 533 | * In this test case, Invalid AFI is given as input and expecting |
| 534 | * an exception. |
| 535 | */ |
| 536 | @Test(expected = BgpParseException.class) |
| 537 | public void bgpUpdateMessageTest16() throws BgpParseException { |
| 538 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 539 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 540 | (byte) 0xff, (byte) 0xff, 0x00, 0x60, 0x02, 0x00, 0x00, //withdrawn len |
| 541 | 0x00, 0x49, //path attribute len |
| 542 | (byte) 0xff, 0x01, 0x01, 0x00, //origin |
| 543 | 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path |
| 544 | (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med |
| 545 | (byte) 0x80, 0x0e, 0x34, 0x40, 0x06, 0x47, //mpreach with safi = 71 |
| 546 | 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop |
| 547 | 0x00, //reserved |
| 548 | 0x00, 0x01, 0x00, |
| 549 | 0x27, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, |
| 550 | 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, |
| 551 | 0x00, 0x06, 0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58}; //node nlri}; |
| 552 | |
| 553 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 554 | buffer.writeBytes(updateMsg); |
| 555 | |
| 556 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 557 | BgpMessage message; |
| 558 | BgpHeader bgpHeader = new BgpHeader(); |
| 559 | |
| 560 | message = reader.readFrom(buffer, bgpHeader); |
| 561 | |
| 562 | assertThat(message, instanceOf(BgpUpdateMsg.class)); |
| 563 | } |
| 564 | |
| 565 | /** |
| 566 | * In this test case, Invalid res is given as input and expecting |
| 567 | * an exception. |
| 568 | */ |
| 569 | @Test(expected = BgpParseException.class) |
| 570 | public void bgpUpdateMessageTest17() throws BgpParseException { |
| 571 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 572 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 573 | (byte) 0xff, (byte) 0xff, 0x00, 0x60, 0x02, 0x00, 0x00, //withdrawn len |
| 574 | 0x00, 0x49, //path attribute len |
| 575 | (byte) 0xff, 0x01, 0x01, 0x00, //origin |
| 576 | 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path |
| 577 | (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med |
| 578 | (byte) 0x80, 0x0e, 0x34, 0x40, 0x04, 0x47, //mpreach with safi = 71 |
| 579 | 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop |
| 580 | 0x01, //reserved |
| 581 | 0x00, 0x01, 0x00, |
| 582 | 0x27, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, |
| 583 | 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, |
| 584 | 0x00, 0x06, 0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58}; //node nlri}; |
| 585 | |
| 586 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 587 | buffer.writeBytes(updateMsg); |
| 588 | |
| 589 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 590 | BgpMessage message; |
| 591 | BgpHeader bgpHeader = new BgpHeader(); |
| 592 | |
| 593 | message = reader.readFrom(buffer, bgpHeader); |
| 594 | |
| 595 | assertThat(message, instanceOf(BgpUpdateMsg.class)); |
| 596 | } |
| 597 | |
| 598 | /** |
| 599 | * This test case checks update message with node NLRI. |
| 600 | */ |
| 601 | @Test |
| 602 | public void bgpUpdateMessageTest18() throws BgpParseException { |
| 603 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 604 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 605 | (byte) 0xff, (byte) 0xff, 0x00, 0x60, 0x02, 0x00, 0x00, //withdrawn len |
| 606 | 0x00, 0x49, //path attribute len |
| 607 | 0x04, 0x01, 0x01, 0x00, //origin |
| 608 | 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path |
| 609 | (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med |
| 610 | (byte) 0x80, 0x0e, 0x34, 0x40, 0x04, 0x47, //mpreach with safi = 71 |
| 611 | 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop |
| 612 | 0x00, //reserved |
| 613 | 0x00, 0x01, 0x00, |
| 614 | 0x27, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, |
| 615 | 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, |
| 616 | 0x00, 0x06, 0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58}; //node nlri |
| 617 | |
| 618 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 619 | buffer.writeBytes(updateMsg); |
| 620 | |
| 621 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 622 | BgpMessage message; |
| 623 | BgpHeader bgpHeader = new BgpHeader(); |
| 624 | |
| 625 | message = reader.readFrom(buffer, bgpHeader); |
| 626 | assertThat(message, instanceOf(BgpUpdateMsg.class)); |
| 627 | BgpUpdateMsg other = (BgpUpdateMsg) message; |
| 628 | |
| 629 | assertThat(other.getHeader().getMarker(), is(MARKER)); |
| 630 | assertThat(other.getHeader().getType(), is(UPDATE_MSG_TYPE)); |
| 631 | assertThat(other.getHeader().getLength(), is((short) 96)); |
| 632 | |
| 633 | BgpValueType testPathAttribute; |
| 634 | Origin origin; |
| 635 | AsPath asPath; |
| 636 | Med med; |
| 637 | MpReachNlri mpReach; |
| 638 | List<BgpValueType> pathAttributes = new LinkedList<>(); |
| 639 | BgpPathAttributes actualpathAttribute = other.bgpPathAttributes(); |
| 640 | pathAttributes = actualpathAttribute.pathAttributes(); |
| 641 | ListIterator<BgpValueType> listIterator = pathAttributes.listIterator(); |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 642 | OriginType originValue = OriginType.IGP; |
Priyanka B | 0ab34b9 | 2015-12-03 21:13:52 +0530 | [diff] [blame] | 643 | |
| 644 | testPathAttribute = listIterator.next(); |
| 645 | origin = (Origin) testPathAttribute; |
| 646 | assertThat(origin.origin(), is(originValue)); |
| 647 | |
| 648 | testPathAttribute = listIterator.next(); |
| 649 | asPath = (AsPath) testPathAttribute; |
| 650 | ListIterator<Short> listIterator2 = asPath.asPathSeq().listIterator(); |
| 651 | assertThat(listIterator2.next(), is((short) 65001)); |
| 652 | |
| 653 | testPathAttribute = listIterator.next(); |
| 654 | med = (Med) testPathAttribute; |
| 655 | assertThat(med.med(), is(0)); |
| 656 | |
| 657 | testPathAttribute = listIterator.next(); |
| 658 | mpReach = (MpReachNlri) testPathAttribute; |
| 659 | assertThat(mpReach.mpReachNlriLen(), is((int) 52)); |
| 660 | assertThat(mpReach.getType(), is((short) 14)); |
| 661 | |
| 662 | List<BgpLSNlri> testMpReachNlri = new LinkedList<>(); |
| 663 | testMpReachNlri = mpReach.mpReachNlri(); |
| 664 | |
| 665 | ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator(); |
| 666 | BgpLSNlri testnlri = list1.next(); |
| 667 | NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.NODE; |
| 668 | ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate. |
| 669 | BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO; |
| 670 | assertThat(testnlri.getIdentifier(), is((long) 0)); |
| 671 | assertThat(testnlri.getNlriType(), is(nlriType)); |
| 672 | assertThat(testnlri.getProtocolId(), is(protocolId)); |
| 673 | |
| 674 | BgpNodeLSNlriVer4 testNodenlri = (BgpNodeLSNlriVer4) testnlri; |
| 675 | |
| 676 | BgpNodeLSIdentifier testLocalNodeDescriptors = testNodenlri.getLocalNodeDescriptors(); |
| 677 | |
| 678 | List<BgpValueType> testSubTlvs = new LinkedList<>(); |
| 679 | NodeDescriptors localNodeDescriptors = testLocalNodeDescriptors.getNodedescriptors(); |
| 680 | testSubTlvs = localNodeDescriptors.getSubTlvs(); |
| 681 | ListIterator<BgpValueType> subtlvlist1 = testSubTlvs.listIterator(); |
| 682 | |
| 683 | AutonomousSystemTlv testAutonomousSystemTlv = (AutonomousSystemTlv) subtlvlist1.next(); |
| 684 | assertThat(testAutonomousSystemTlv.getAsNum(), is(2222)); |
| 685 | assertThat(testAutonomousSystemTlv.getType(), is((short) 512)); |
| 686 | |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 687 | BgpLSIdentifierTlv testBgpLsIdentifierTlv = (BgpLSIdentifierTlv) subtlvlist1.next(); |
| 688 | assertThat(testBgpLsIdentifierTlv.getBgpLsIdentifier(), is(33686018)); |
| 689 | assertThat(testBgpLsIdentifierTlv.getType(), is((short) 513)); |
Priyanka B | 0ab34b9 | 2015-12-03 21:13:52 +0530 | [diff] [blame] | 690 | |
| 691 | IsIsNonPseudonode testIsIsNonPseudonode = (IsIsNonPseudonode) subtlvlist1.next(); |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 692 | byte[] expIsoNodeId = new byte[] {0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58}; |
| 693 | assertThat(testIsIsNonPseudonode.getIsoNodeId(), is(expIsoNodeId)); |
Priyanka B | 0ab34b9 | 2015-12-03 21:13:52 +0530 | [diff] [blame] | 694 | assertThat(testIsIsNonPseudonode.getType(), is((short) 515)); |
| 695 | |
| 696 | } |
| 697 | |
| 698 | /** |
| 699 | * This test case checks update message with prefix NLRI. |
| 700 | */ |
| 701 | @Test |
| 702 | public void bgpUpdateMessageTest19() throws BgpParseException { |
| 703 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 704 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 705 | (byte) 0xff, (byte) 0xff, 0x00, (byte) 0xd6, 0x02, 0x00, 0x04, |
| 706 | 0x18, 0x0a, 0x01, 0x01, //withdrawn routes |
| 707 | 0x00, (byte) 0xbb, //path attribute len |
| 708 | 0x04, 0x01, 0x01, 0x00, //origin |
| 709 | 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path |
| 710 | (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med |
| 711 | (byte) 0x90, 0x0e, 0x00, (byte) 0xa5, 0x40, 0x04, 0x47, //mpreach |
| 712 | 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop |
| 713 | 0x00, //reserved |
| 714 | 0x00, 0x03, 0x00, 0x30, 0x02, 0x00, 0x00, 0x00, |
| 715 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, |
| 716 | 0x1a, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, |
| 717 | (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, |
| 718 | 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, 0x21, 0x68, |
| 719 | 0x07, 0x70, 0x01, 0x01, 0x09, 0x00, 0x05, 0x20, |
| 720 | (byte) 0xc0, (byte) 0xa8, 0x4d, 0x01, 0x00, 0x03, 0x00, 0x30, |
| 721 | 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 722 | 0x00, 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, 0x00, |
| 723 | 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, |
| 724 | 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, |
| 725 | 0x06, 0x19, 0x00, (byte) 0x95, 0x02, 0x50, 0x21, 0x01, |
| 726 | 0x09, 0x00, 0x05, 0x20, 0x15, 0x15, 0x15, 0x15, |
| 727 | 0x00, 0x03, 0x00, 0x30, 0x02, 0x00, 0x00, 0x00, |
| 728 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, |
| 729 | 0x1a, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, |
| 730 | (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, |
| 731 | 0x02, 0x02, 0x03, 0x00, 0x06, 0x02, 0x20, 0x22, |
| 732 | 0x02, 0x20, 0x22, 0x01, 0x09, 0x00, 0x05, 0x20, |
| 733 | 0x16, 0x16, 0x16, 0x16}; // prefix nlri |
| 734 | |
| 735 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 736 | buffer.writeBytes(updateMsg); |
| 737 | |
| 738 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 739 | BgpMessage message; |
| 740 | BgpHeader bgpHeader = new BgpHeader(); |
| 741 | |
| 742 | message = reader.readFrom(buffer, bgpHeader); |
| 743 | assertThat(message, instanceOf(BgpUpdateMsg.class)); |
| 744 | BgpUpdateMsg other = (BgpUpdateMsg) message; |
| 745 | |
| 746 | assertThat(other.getHeader().getMarker(), is(MARKER)); |
| 747 | assertThat(other.getHeader().getType(), is(UPDATE_MSG_TYPE)); |
| 748 | assertThat(other.getHeader().getLength(), is((short) 214)); |
| 749 | |
| 750 | ListIterator<IpPrefix> listIterator1 = other.withdrawnRoutes().listIterator(); |
| 751 | byte[] prefix = new byte[] {0x0a, 0x01, 0x01, 0x00}; |
| 752 | |
| 753 | IpPrefix testPrefixValue = listIterator1.next(); |
| 754 | assertThat(testPrefixValue.prefixLength(), is((int) 24)); |
| 755 | assertThat(testPrefixValue.address().toOctets(), is(prefix)); |
| 756 | |
| 757 | BgpValueType testPathAttribute; |
| 758 | Origin origin; |
| 759 | AsPath asPath; |
| 760 | Med med; |
| 761 | MpReachNlri mpReach; |
| 762 | List<BgpValueType> pathAttributes = new LinkedList<>(); |
| 763 | BgpPathAttributes actualpathAttribute = other.bgpPathAttributes(); |
| 764 | pathAttributes = actualpathAttribute.pathAttributes(); |
| 765 | ListIterator<BgpValueType> listIterator = pathAttributes.listIterator(); |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 766 | OriginType originValue = OriginType.IGP; |
Priyanka B | 0ab34b9 | 2015-12-03 21:13:52 +0530 | [diff] [blame] | 767 | |
| 768 | testPathAttribute = listIterator.next(); |
| 769 | origin = (Origin) testPathAttribute; |
| 770 | assertThat(origin.origin(), is(originValue)); |
| 771 | |
| 772 | testPathAttribute = listIterator.next(); |
| 773 | asPath = (AsPath) testPathAttribute; |
| 774 | ListIterator<Short> listIterator2 = asPath.asPathSeq().listIterator(); |
| 775 | assertThat(listIterator2.next(), is((short) 65001)); |
| 776 | |
| 777 | testPathAttribute = listIterator.next(); |
| 778 | med = (Med) testPathAttribute; |
| 779 | assertThat(med.med(), is(0)); |
| 780 | |
| 781 | testPathAttribute = listIterator.next(); |
| 782 | mpReach = (MpReachNlri) testPathAttribute; |
| 783 | assertThat(mpReach.mpReachNlriLen(), is((int) 165)); |
| 784 | assertThat(mpReach.getType(), is((short) 14)); |
| 785 | |
| 786 | List<BgpLSNlri> testMpReachNlri = new LinkedList<>(); |
| 787 | testMpReachNlri = mpReach.mpReachNlri(); |
| 788 | |
| 789 | ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator(); |
| 790 | BgpLSNlri testnlri = list1.next(); |
| 791 | NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.PREFIX_IPV4; |
| 792 | ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate. |
| 793 | BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO; |
| 794 | assertThat(testnlri.getIdentifier(), is((long) 0)); |
| 795 | assertThat(testnlri.getNlriType(), is(nlriType)); |
| 796 | assertThat(testnlri.getProtocolId(), is(protocolId)); |
| 797 | |
| 798 | BgpPrefixLSNlri testprefixnlri = (BgpPrefixLSNlri) testnlri; |
| 799 | |
| 800 | NodeDescriptors testLocalNodeDescriptors = testprefixnlri.getLocalNodeDescriptors(); |
| 801 | |
| 802 | List<BgpValueType> testSubTlvs = new LinkedList<>(); |
| 803 | testSubTlvs = testLocalNodeDescriptors.getSubTlvs(); |
| 804 | ListIterator<BgpValueType> subtlvlist1 = testSubTlvs.listIterator(); |
| 805 | |
| 806 | AutonomousSystemTlv testAutonomousSystemTlv = (AutonomousSystemTlv) subtlvlist1.next(); |
| 807 | assertThat(testAutonomousSystemTlv.getAsNum(), is(2222)); |
| 808 | assertThat(testAutonomousSystemTlv.getType(), is((short) 512)); |
| 809 | |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 810 | BgpLSIdentifierTlv testBgpLsIdentifierTlv = (BgpLSIdentifierTlv) subtlvlist1.next(); |
| 811 | assertThat(testBgpLsIdentifierTlv.getBgpLsIdentifier(), is(33686018)); |
| 812 | assertThat(testBgpLsIdentifierTlv.getType(), is((short) 513)); |
Priyanka B | 0ab34b9 | 2015-12-03 21:13:52 +0530 | [diff] [blame] | 813 | |
| 814 | IsIsNonPseudonode testIsIsNonPseudonode = (IsIsNonPseudonode) subtlvlist1.next(); |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 815 | byte[] expIsoNodeId = new byte[] {0x19, 0x21, 0x68, 0x07, 0x70, 0x01}; |
| 816 | assertThat(testIsIsNonPseudonode.getIsoNodeId(), is(expIsoNodeId)); |
Priyanka B | 0ab34b9 | 2015-12-03 21:13:52 +0530 | [diff] [blame] | 817 | assertThat(testIsIsNonPseudonode.getType(), is((short) 515)); |
| 818 | |
| 819 | List<BgpValueType> testPrefixDescriptors = new LinkedList<>(); |
| 820 | testPrefixDescriptors = testprefixnlri.getPrefixdescriptor(); |
| 821 | ListIterator<BgpValueType> subtlvlist2 = testPrefixDescriptors.listIterator(); |
| 822 | IPReachabilityInformationTlv testIPReachabilityInformationTlv = (IPReachabilityInformationTlv) |
| 823 | subtlvlist2.next(); |
| 824 | byte[] address = new byte[] {(byte) 0xc0, (byte) 0xa8, 0x4d, 0x01}; |
| 825 | IpPrefix prefix1 = IpPrefix.valueOf(IpAddress.Version.INET, address, 32); |
| 826 | assertThat(testIPReachabilityInformationTlv.getPrefixValue(), is(prefix1)); |
| 827 | assertThat(testIPReachabilityInformationTlv.getPrefixLen(), is((byte) 32)); |
| 828 | } |
| 829 | |
| 830 | /** |
| 831 | * This test case checks update message with link NLRI. |
| 832 | */ |
| 833 | @Test |
| 834 | public void bgpUpdateMessageTest20() throws BgpParseException { |
| 835 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 836 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 837 | (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x83, 0x02, 0x00, 0x04, |
| 838 | 0x18, 0x0a, 0x01, 0x01, //withdrawn routes |
| 839 | 0x00, 0x68, //path attribute len |
| 840 | 0x04, 0x01, 0x01, 0x00, //origin |
| 841 | 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path |
| 842 | (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med |
| 843 | (byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach |
| 844 | 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop |
| 845 | 0x00, //reserved |
| 846 | 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 847 | 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00, |
| 848 | 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, |
| 849 | 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00, |
| 850 | (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02, |
| 851 | 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, |
| 852 | 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, |
| 853 | 0x00, (byte) 0x95, 0x02, 0x50, 0x21//link nlri |
| 854 | }; |
| 855 | |
| 856 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 857 | buffer.writeBytes(updateMsg); |
| 858 | |
| 859 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 860 | BgpMessage message = null; |
| 861 | BgpHeader bgpHeader = new BgpHeader(); |
| 862 | |
| 863 | message = reader.readFrom(buffer, bgpHeader); |
| 864 | assertThat(message, instanceOf(BgpUpdateMsg.class)); |
| 865 | BgpUpdateMsg other = (BgpUpdateMsg) message; |
| 866 | |
| 867 | assertThat(other.getHeader().getMarker(), is(MARKER)); |
| 868 | assertThat(other.getHeader().getType(), is(UPDATE_MSG_TYPE)); |
| 869 | assertThat(other.getHeader().getLength(), is((short) 131)); |
| 870 | |
| 871 | ListIterator<IpPrefix> listIterator1 = other.withdrawnRoutes().listIterator(); |
| 872 | byte[] prefix = new byte[] {0x0a, 0x01, 0x01, 0x00}; |
| 873 | |
| 874 | IpPrefix testPrefixValue = listIterator1.next(); |
| 875 | assertThat(testPrefixValue.prefixLength(), is((int) 24)); |
| 876 | assertThat(testPrefixValue.address().toOctets(), is(prefix)); |
| 877 | |
| 878 | BgpValueType testPathAttribute; |
| 879 | Origin origin; |
| 880 | AsPath asPath; |
| 881 | Med med; |
| 882 | MpReachNlri mpReach; |
| 883 | |
| 884 | List<BgpValueType> pathAttributes = new LinkedList<>(); |
| 885 | BgpPathAttributes actualpathAttribute = other.bgpPathAttributes(); |
| 886 | pathAttributes = actualpathAttribute.pathAttributes(); |
| 887 | ListIterator<BgpValueType> listIterator = pathAttributes.listIterator(); |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 888 | OriginType originValue = OriginType.IGP; |
Priyanka B | 0ab34b9 | 2015-12-03 21:13:52 +0530 | [diff] [blame] | 889 | |
| 890 | testPathAttribute = listIterator.next(); |
| 891 | origin = (Origin) testPathAttribute; |
| 892 | assertThat(origin.origin(), is(originValue)); |
| 893 | |
| 894 | testPathAttribute = listIterator.next(); |
| 895 | asPath = (AsPath) testPathAttribute; |
| 896 | ListIterator<Short> listIterator2 = asPath.asPathSeq().listIterator(); |
| 897 | assertThat(listIterator2.next(), is((short) 65001)); |
| 898 | |
| 899 | testPathAttribute = listIterator.next(); |
| 900 | med = (Med) testPathAttribute; |
| 901 | assertThat(med.med(), is(0)); |
| 902 | |
| 903 | testPathAttribute = listIterator.next(); |
| 904 | mpReach = (MpReachNlri) testPathAttribute; |
| 905 | assertThat(mpReach.mpReachNlriLen(), is((int) 83)); |
| 906 | assertThat(mpReach.getType(), is((short) 14)); |
| 907 | |
| 908 | List<BgpLSNlri> testMpReachNlri = new LinkedList<>(); |
| 909 | testMpReachNlri = mpReach.mpReachNlri(); |
| 910 | |
| 911 | ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator(); |
| 912 | BgpLSNlri testnlri = list1.next(); |
| 913 | NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.LINK; |
| 914 | ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate. |
| 915 | BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO; |
| 916 | assertThat(testnlri.getIdentifier(), is((long) 0)); |
| 917 | assertThat(testnlri.getNlriType(), is(nlriType)); |
| 918 | assertThat(testnlri.getProtocolId(), is(protocolId)); |
| 919 | |
| 920 | BgpLinkLsNlriVer4 testlinknlri = (BgpLinkLsNlriVer4) testnlri; |
| 921 | |
| 922 | NodeDescriptors testLocalNodeDescriptors = testlinknlri.localNodeDescriptors(); |
| 923 | |
| 924 | List<BgpValueType> testSubTlvs = new LinkedList<>(); |
| 925 | testSubTlvs = testLocalNodeDescriptors.getSubTlvs(); |
| 926 | ListIterator<BgpValueType> subtlvlist1 = testSubTlvs.listIterator(); |
| 927 | |
| 928 | AutonomousSystemTlv testAutonomousSystemTlv = (AutonomousSystemTlv) subtlvlist1.next(); |
| 929 | |
| 930 | assertThat(testAutonomousSystemTlv.getAsNum(), is(2222)); |
| 931 | assertThat(testAutonomousSystemTlv.getType(), is((short) 512)); |
| 932 | |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 933 | BgpLSIdentifierTlv testBgpLsIdentifierTlv = (BgpLSIdentifierTlv) subtlvlist1.next(); |
| 934 | assertThat(testBgpLsIdentifierTlv.getBgpLsIdentifier(), is(33686018)); |
| 935 | assertThat(testBgpLsIdentifierTlv.getType(), is((short) 513)); |
Priyanka B | 0ab34b9 | 2015-12-03 21:13:52 +0530 | [diff] [blame] | 936 | |
| 937 | IsIsPseudonode testIsIsPseudonode = (IsIsPseudonode) subtlvlist1.next(); |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 938 | assertThat(testIsIsPseudonode.getPsnIdentifier(), is((byte) 3)); |
Priyanka B | 0ab34b9 | 2015-12-03 21:13:52 +0530 | [diff] [blame] | 939 | assertThat(testIsIsPseudonode.getType(), is((short) 515)); |
| 940 | |
| 941 | NodeDescriptors testRemoteNodeDescriptors = testlinknlri.remoteNodeDescriptors(); |
| 942 | testSubTlvs = testRemoteNodeDescriptors.getSubTlvs(); |
| 943 | ListIterator<BgpValueType> subtlvlist2 = testSubTlvs.listIterator(); |
| 944 | |
| 945 | testAutonomousSystemTlv = (AutonomousSystemTlv) subtlvlist2.next(); |
| 946 | |
| 947 | assertThat(testAutonomousSystemTlv.getAsNum(), is(2222)); |
| 948 | assertThat(testAutonomousSystemTlv.getType(), is((short) 512)); |
| 949 | |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 950 | testBgpLsIdentifierTlv = (BgpLSIdentifierTlv) subtlvlist2.next(); |
| 951 | assertThat(testBgpLsIdentifierTlv.getBgpLsIdentifier(), is(33686018)); |
| 952 | assertThat(testBgpLsIdentifierTlv.getType(), is((short) 513)); |
Priyanka B | 0ab34b9 | 2015-12-03 21:13:52 +0530 | [diff] [blame] | 953 | |
| 954 | IsIsNonPseudonode testIsIsNonPseudonode = (IsIsNonPseudonode) subtlvlist2.next(); |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 955 | byte[] expIsoNodeId = new byte[] {0x19, 0x00, (byte) 0x95, 0x02, 0x50, 0x21}; |
| 956 | assertThat(testIsIsNonPseudonode.getIsoNodeId(), is(expIsoNodeId)); |
Priyanka B | 0ab34b9 | 2015-12-03 21:13:52 +0530 | [diff] [blame] | 957 | assertThat(testIsIsNonPseudonode.getType(), is((short) 515)); |
| 958 | } |
| 959 | |
| 960 | /** |
| 961 | * In this test case, Invalid withdrawn route length is given as input and expecting |
| 962 | * an exception. |
| 963 | */ |
| 964 | @Test(expected = BgpParseException.class) |
| 965 | public void bgpUpdateMessageTest21() throws BgpParseException { |
| 966 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 967 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 968 | (byte) 0xff, (byte) 0xff, 0x00, 0x1b, 0x02, 0x00, 0x07, 0x18, 0x0a, 0x01, 0x01, 0x00, 0x00}; |
| 969 | |
| 970 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 971 | buffer.writeBytes(updateMsg); |
| 972 | |
| 973 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 974 | BgpMessage message; |
| 975 | BgpHeader bgpHeader = new BgpHeader(); |
| 976 | |
| 977 | message = reader.readFrom(buffer, bgpHeader); |
| 978 | assertThat(message, instanceOf(BgpUpdateMsg.class)); |
| 979 | } |
| 980 | |
| 981 | /** |
| 982 | * In this test case, Invalid withdrawn route length is given as input and expecting |
| 983 | * an exception. |
| 984 | */ |
| 985 | @Test(expected = BgpParseException.class) |
| 986 | public void bgpUpdateMessageTest22() throws BgpParseException { |
| 987 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 988 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 989 | (byte) 0xff, (byte) 0xff, 0x00, 0x25, 0x02, 0x00, 0x00, //withdrawn len |
| 990 | 0x00, 0x0e, //path attribute len |
| 991 | 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path |
| 992 | (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00}; //med |
| 993 | |
| 994 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 995 | buffer.writeBytes(updateMsg); |
| 996 | |
| 997 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 998 | BgpMessage message; |
| 999 | BgpHeader bgpHeader = new BgpHeader(); |
| 1000 | |
| 1001 | message = reader.readFrom(buffer, bgpHeader); |
| 1002 | |
| 1003 | assertThat(message, instanceOf(BgpUpdateMsg.class)); |
| 1004 | } |
| 1005 | |
| 1006 | /** |
| 1007 | * In this test case, Mandatory attributes are not given in input and expecting |
| 1008 | * an exception. |
| 1009 | */ |
| 1010 | @Test(expected = BgpParseException.class) |
| 1011 | public void bgpUpdateMessageTest23() throws BgpParseException { |
| 1012 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1013 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1014 | (byte) 0xff, (byte) 0xff, 0x00, 0x29, 0x02, 0x00, 0x00, //withdrawn len |
| 1015 | 0x00, 0x12, //path attribute len |
| 1016 | 0x0e, 0x01, 0x01, 0x00, //origin |
| 1017 | 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path |
| 1018 | (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00}; //med |
| 1019 | |
| 1020 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 1021 | buffer.writeBytes(updateMsg); |
| 1022 | |
| 1023 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 1024 | BgpMessage message; |
| 1025 | BgpHeader bgpHeader = new BgpHeader(); |
| 1026 | |
| 1027 | message = reader.readFrom(buffer, bgpHeader); |
| 1028 | |
| 1029 | assertThat(message, instanceOf(BgpUpdateMsg.class)); |
| 1030 | } |
| 1031 | |
| 1032 | /** |
| 1033 | * In this test case, Invalid origin length is given as input and expecting |
| 1034 | * an exception. |
| 1035 | */ |
| 1036 | @Test(expected = BgpParseException.class) |
| 1037 | public void bgpUpdateMessageTest24() throws BgpParseException { |
| 1038 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1039 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1040 | (byte) 0xff, (byte) 0xff, 0x00, 0x29, 0x02, 0x00, 0x00, //withdrawn len |
| 1041 | 0x00, 0x12, //path attribute len |
| 1042 | 0x04, 0x01, 0x02, 0x00, //origin |
| 1043 | 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path |
| 1044 | (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00}; //med |
| 1045 | |
| 1046 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 1047 | buffer.writeBytes(updateMsg); |
| 1048 | |
| 1049 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 1050 | BgpMessage message; |
| 1051 | BgpHeader bgpHeader = new BgpHeader(); |
| 1052 | |
| 1053 | message = reader.readFrom(buffer, bgpHeader); |
| 1054 | |
| 1055 | assertThat(message, instanceOf(BgpUpdateMsg.class)); |
| 1056 | } |
| 1057 | |
| 1058 | /** |
| 1059 | * In this test case, Invalid origin value is given as input and expecting |
| 1060 | * an exception. |
| 1061 | */ |
| 1062 | @Test(expected = BgpParseException.class) |
| 1063 | public void bgpUpdateMessageTest25() throws BgpParseException { |
| 1064 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1065 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1066 | (byte) 0xff, (byte) 0xff, 0x00, 0x29, 0x02, 0x00, 0x00, //withdrawn len |
| 1067 | 0x00, 0x12, //path attribute len |
| 1068 | 0x04, 0x01, 0x01, 0x04, //origin |
| 1069 | 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path |
| 1070 | (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00}; //med |
| 1071 | |
| 1072 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 1073 | buffer.writeBytes(updateMsg); |
| 1074 | |
| 1075 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 1076 | BgpMessage message; |
| 1077 | BgpHeader bgpHeader = new BgpHeader(); |
| 1078 | |
| 1079 | message = reader.readFrom(buffer, bgpHeader); |
| 1080 | |
| 1081 | assertThat(message, instanceOf(BgpUpdateMsg.class)); |
| 1082 | } |
| 1083 | |
| 1084 | /** |
| 1085 | * In this test case, Invalid descriptor type in node nlri is given as input and expecting |
| 1086 | * an exception. |
| 1087 | */ |
| 1088 | @Test(expected = BgpParseException.class) |
| 1089 | public void bgpUpdateMessageTest26() throws BgpParseException { |
| 1090 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1091 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1092 | (byte) 0xff, (byte) 0xff, 0x00, 0x60, 0x02, 0x00, 0x00, //withdrawn len |
| 1093 | 0x00, 0x49, //path attribute len |
| 1094 | 0x04, 0x01, 0x01, 0x00, //origin |
| 1095 | 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path |
| 1096 | (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med |
| 1097 | (byte) 0x80, 0x0e, 0x34, 0x40, 0x04, 0x47, //mpreach with safi = 71 |
| 1098 | 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop |
| 1099 | 0x00, //reserved |
| 1100 | 0x00, 0x01, 0x00, |
| 1101 | 0x27, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x1a, 0x02, 0x00, |
| 1102 | 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, |
| 1103 | 0x00, 0x06, 0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58}; //node nlri |
| 1104 | |
| 1105 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 1106 | buffer.writeBytes(updateMsg); |
| 1107 | |
| 1108 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 1109 | BgpMessage message; |
| 1110 | BgpHeader bgpHeader = new BgpHeader(); |
| 1111 | |
| 1112 | message = reader.readFrom(buffer, bgpHeader); |
| 1113 | |
| 1114 | assertThat(message, instanceOf(BgpUpdateMsg.class)); |
| 1115 | } |
| 1116 | |
| 1117 | /** |
| 1118 | * In this test case, Invalid node nlri length field in is given as input and expecting |
| 1119 | * an exception. |
| 1120 | */ |
| 1121 | @Test(expected = BgpParseException.class) |
| 1122 | public void bgpUpdateMessageTest27() throws BgpParseException { |
| 1123 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1124 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1125 | (byte) 0xff, (byte) 0xff, 0x00, 0x60, 0x02, 0x00, 0x00, //withdrawn len |
| 1126 | 0x00, 0x49, //path attribute len |
| 1127 | 0x04, 0x01, 0x01, 0x00, //origin |
| 1128 | 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path |
| 1129 | (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med |
| 1130 | (byte) 0x80, 0x0e, 0x34, 0x40, 0x04, 0x47, //mpreach with safi = 71 |
| 1131 | 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop |
| 1132 | 0x00, //reserved |
| 1133 | 0x00, 0x01, 0x00, |
| 1134 | 0x27, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, |
| 1135 | 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, |
| 1136 | 0x00, 0x06, 0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58}; //node nlri |
| 1137 | |
| 1138 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 1139 | buffer.writeBytes(updateMsg); |
| 1140 | |
| 1141 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 1142 | BgpMessage message; |
| 1143 | BgpHeader bgpHeader = new BgpHeader(); |
| 1144 | |
| 1145 | message = reader.readFrom(buffer, bgpHeader); |
| 1146 | |
| 1147 | assertThat(message, instanceOf(BgpUpdateMsg.class)); |
| 1148 | } |
| 1149 | |
| 1150 | /** |
| 1151 | * In this test case, withdrawn routes with prefix length 0 is given as input and expecting |
| 1152 | * an exception. |
| 1153 | */ |
| 1154 | @Test |
| 1155 | public void bgpUpdateMessageTest28() throws BgpParseException { |
| 1156 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1157 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1158 | (byte) 0xff, (byte) 0xff, //marker |
| 1159 | 0x00, 0x18, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00}; |
| 1160 | |
| 1161 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 1162 | buffer.writeBytes(updateMsg); |
| 1163 | |
| 1164 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 1165 | BgpMessage message; |
| 1166 | BgpHeader bgpHeader = new BgpHeader(); |
| 1167 | |
| 1168 | message = reader.readFrom(buffer, bgpHeader); |
| 1169 | |
| 1170 | assertThat(message, instanceOf(BgpUpdateMsg.class)); |
| 1171 | } |
| 1172 | |
| 1173 | /** |
| 1174 | * In this test case, update message without total Path Attribute Length field is given as |
| 1175 | * input and expecting an exception. |
| 1176 | */ |
| 1177 | @Test(expected = BgpParseException.class) |
| 1178 | public void bgpUpdateMessageTest29() throws BgpParseException { |
| 1179 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1180 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1181 | (byte) 0xff, (byte) 0xff, //marker |
| 1182 | 0x00, 0x16, 0x02, 0x00, 0x01, 0x00}; |
| 1183 | |
| 1184 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 1185 | buffer.writeBytes(updateMsg); |
| 1186 | |
| 1187 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 1188 | BgpMessage message; |
| 1189 | BgpHeader bgpHeader = new BgpHeader(); |
| 1190 | |
| 1191 | message = reader.readFrom(buffer, bgpHeader); |
| 1192 | |
| 1193 | assertThat(message, instanceOf(BgpUpdateMsg.class)); |
| 1194 | } |
| 1195 | |
| 1196 | /** |
| 1197 | * This test case checks update message with as4 path attribute. |
| 1198 | */ |
| 1199 | @Test |
| 1200 | public void bgpUpdateMessageTest30() throws BgpParseException { |
| 1201 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1202 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1203 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1204 | 0x00, 0x3a, 0x02, 0x00, 0x00, 0x00, 0x21, 0x40, 0x01, 0x01, 0x00, (byte) 0xc0, |
| 1205 | 0x11, 0x0a, 0x02, 0x02, 0x00, 0x0a, 0x00, 0x01, 0x00, 0x28, 0x00, 0x01, 0x40, |
| 1206 | 0x02, 0x06, 0x02, 0x02, 0x5b, (byte) 0xa0, 0x5b, (byte) 0xa0, 0x40, 0x03, 0x04, |
| 1207 | (byte) 0xac, 0x10, 0x03, 0x01, 0x08, 0x28}; |
| 1208 | |
| 1209 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 1210 | buffer.writeBytes(updateMsg); |
| 1211 | |
| 1212 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 1213 | BgpMessage message = null; |
| 1214 | BgpHeader bgpHeader = new BgpHeader(); |
| 1215 | |
| 1216 | message = reader.readFrom(buffer, bgpHeader); |
| 1217 | assertThat(message, instanceOf(BgpUpdateMsg.class)); |
| 1218 | BgpUpdateMsg other = (BgpUpdateMsg) message; |
| 1219 | |
| 1220 | assertThat(other.getHeader().getMarker(), is(MARKER)); |
| 1221 | assertThat(other.getHeader().getType(), is(UPDATE_MSG_TYPE)); |
| 1222 | assertThat(other.getHeader().getLength(), is((short) 58)); |
| 1223 | |
| 1224 | BgpValueType testPathAttribute; |
| 1225 | Origin origin; |
| 1226 | As4Path as4Path; |
| 1227 | AsPath asPath; |
| 1228 | NextHop nextHop; |
| 1229 | |
| 1230 | List<BgpValueType> pathAttributes = new LinkedList<>(); |
| 1231 | BgpPathAttributes actualpathAttribute = other.bgpPathAttributes(); |
| 1232 | pathAttributes = actualpathAttribute.pathAttributes(); |
| 1233 | ListIterator<BgpValueType> listIterator = pathAttributes.listIterator(); |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 1234 | OriginType originValue = OriginType.IGP; |
Priyanka B | 0ab34b9 | 2015-12-03 21:13:52 +0530 | [diff] [blame] | 1235 | |
| 1236 | testPathAttribute = listIterator.next(); |
| 1237 | origin = (Origin) testPathAttribute; |
| 1238 | assertThat(origin.origin(), is(originValue)); |
| 1239 | |
| 1240 | testPathAttribute = listIterator.next(); |
| 1241 | as4Path = (As4Path) testPathAttribute; |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 1242 | ListIterator<Integer> listIterator2 = as4Path.as4PathSeq().listIterator(); |
Priyanka B | 0ab34b9 | 2015-12-03 21:13:52 +0530 | [diff] [blame] | 1243 | assertThat(listIterator2.next(), is(655361)); |
| 1244 | |
| 1245 | testPathAttribute = listIterator.next(); |
| 1246 | asPath = (AsPath) testPathAttribute; |
| 1247 | ListIterator<Short> listIterator3 = asPath.asPathSeq().listIterator(); |
| 1248 | assertThat(listIterator3.next(), is((short) 23456)); |
| 1249 | |
| 1250 | testPathAttribute = listIterator.next(); |
| 1251 | nextHop = (NextHop) testPathAttribute; |
| 1252 | byte[] nextHopAddr = new byte[] {(byte) 0xac, 0x10, 0x03, 0x01}; |
| 1253 | assertThat(nextHop.nextHop().toOctets(), is(nextHopAddr)); |
| 1254 | |
| 1255 | ListIterator<IpPrefix> listIterator1 = other.nlri().listIterator(); |
| 1256 | byte[] prefix = new byte[] {0x28, 0x00, 0x00, 0x00}; |
| 1257 | |
| 1258 | IpPrefix testPrefixValue = listIterator1.next(); |
| 1259 | assertThat(testPrefixValue.prefixLength(), is((int) 8)); |
| 1260 | assertThat(testPrefixValue.address().toOctets(), is(prefix)); |
| 1261 | } |
| 1262 | |
| 1263 | /** |
| 1264 | * This test case checks update message with MPUnreach. |
| 1265 | */ |
| 1266 | @Test |
| 1267 | public void bgpUpdateMessageTest31() throws BgpParseException { |
| 1268 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1269 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1270 | (byte) 0xff, (byte) 0xff, 0x00, 0x5e, 0x02, 0x00, 0x04, 0x18, 0x0a, 0x01, 0x01, //withdrawn routes |
| 1271 | 0x00, 0x43, //path attribute len |
| 1272 | 0x04, 0x01, 0x01, 0x00, //origin |
| 1273 | 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path |
| 1274 | (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med |
| 1275 | (byte) 0x80, 0x0f, 0x2e, 0x40, 0x04, 0x47, //mpunreach with safi = 71 |
| 1276 | 0x00, 0x01, 0x00, |
| 1277 | 0x27, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, |
| 1278 | 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, |
| 1279 | 0x00, 0x06, 0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58}; //node nlri |
| 1280 | |
| 1281 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 1282 | buffer.writeBytes(updateMsg); |
| 1283 | |
| 1284 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 1285 | BgpMessage message; |
| 1286 | BgpHeader bgpHeader = new BgpHeader(); |
| 1287 | |
| 1288 | message = reader.readFrom(buffer, bgpHeader); |
| 1289 | assertThat(message, instanceOf(BgpUpdateMsg.class)); |
| 1290 | BgpUpdateMsg other = (BgpUpdateMsg) message; |
| 1291 | |
| 1292 | assertThat(other.getHeader().getMarker(), is(MARKER)); |
| 1293 | assertThat(other.getHeader().getType(), is(UPDATE_MSG_TYPE)); |
| 1294 | assertThat(other.getHeader().getLength(), is((short) 94)); |
| 1295 | |
| 1296 | ListIterator<IpPrefix> listIterator1 = other.withdrawnRoutes().listIterator(); |
| 1297 | byte[] prefix = new byte[] {0x0a, 0x01, 0x01, 0x00}; |
| 1298 | |
| 1299 | IpPrefix testPrefixValue = listIterator1.next(); |
| 1300 | assertThat(testPrefixValue.prefixLength(), is((int) 24)); |
| 1301 | assertThat(testPrefixValue.address().toOctets(), is(prefix)); |
| 1302 | |
| 1303 | BgpValueType testPathAttribute; |
| 1304 | Origin origin; |
| 1305 | AsPath asPath; |
| 1306 | Med med; |
| 1307 | MpUnReachNlri mpUnReach; |
| 1308 | List<BgpValueType> pathAttributes = new LinkedList<>(); |
| 1309 | BgpPathAttributes actualpathAttribute = other.bgpPathAttributes(); |
| 1310 | pathAttributes = actualpathAttribute.pathAttributes(); |
| 1311 | ListIterator<BgpValueType> listIterator = pathAttributes.listIterator(); |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 1312 | OriginType originValue = OriginType.IGP; |
Priyanka B | 0ab34b9 | 2015-12-03 21:13:52 +0530 | [diff] [blame] | 1313 | |
| 1314 | testPathAttribute = listIterator.next(); |
| 1315 | origin = (Origin) testPathAttribute; |
| 1316 | assertThat(origin.origin(), is(originValue)); |
| 1317 | |
| 1318 | testPathAttribute = listIterator.next(); |
| 1319 | asPath = (AsPath) testPathAttribute; |
| 1320 | ListIterator<Short> listIterator2 = asPath.asPathSeq().listIterator(); |
| 1321 | assertThat(listIterator2.next(), is((short) 65001)); |
| 1322 | |
| 1323 | testPathAttribute = listIterator.next(); |
| 1324 | med = (Med) testPathAttribute; |
| 1325 | assertThat(med.med(), is(0)); |
| 1326 | |
| 1327 | testPathAttribute = listIterator.next(); |
| 1328 | mpUnReach = (MpUnReachNlri) testPathAttribute; |
| 1329 | assertThat(mpUnReach.mpUnReachNlriLen(), is((int) 46)); |
| 1330 | assertThat(mpUnReach.getType(), is((short) 15)); |
| 1331 | |
| 1332 | List<BgpLSNlri> testMpUnReachNlri = new LinkedList<>(); |
| 1333 | testMpUnReachNlri = mpUnReach.mpUnReachNlri(); |
| 1334 | |
| 1335 | ListIterator<BgpLSNlri> list1 = testMpUnReachNlri.listIterator(); |
| 1336 | BgpLSNlri testnlri = list1.next(); |
| 1337 | NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.NODE; |
| 1338 | ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate. |
| 1339 | BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO; |
| 1340 | assertThat(testnlri.getIdentifier(), is((long) 0)); |
| 1341 | assertThat(testnlri.getNlriType(), is(nlriType)); |
| 1342 | assertThat(testnlri.getProtocolId(), is(protocolId)); |
| 1343 | |
| 1344 | BgpNodeLSNlriVer4 testNodenlri = (BgpNodeLSNlriVer4) testnlri; |
| 1345 | |
| 1346 | BgpNodeLSIdentifier testLocalNodeDescriptors = testNodenlri.getLocalNodeDescriptors(); |
| 1347 | |
| 1348 | List<BgpValueType> testSubTlvs = new LinkedList<>(); |
| 1349 | NodeDescriptors localNodeDescriptors = testLocalNodeDescriptors.getNodedescriptors(); |
| 1350 | testSubTlvs = localNodeDescriptors.getSubTlvs(); |
| 1351 | ListIterator<BgpValueType> subtlvlist1 = testSubTlvs.listIterator(); |
| 1352 | |
| 1353 | AutonomousSystemTlv testAutonomousSystemTlv = (AutonomousSystemTlv) subtlvlist1.next(); |
| 1354 | |
| 1355 | assertThat(testAutonomousSystemTlv.getAsNum(), is(2222)); |
| 1356 | assertThat(testAutonomousSystemTlv.getType(), is((short) 512)); |
| 1357 | |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 1358 | BgpLSIdentifierTlv testBgpLsIdentifierTlv = (BgpLSIdentifierTlv) subtlvlist1.next(); |
| 1359 | assertThat(testBgpLsIdentifierTlv.getBgpLsIdentifier(), is(33686018)); |
| 1360 | assertThat(testBgpLsIdentifierTlv.getType(), is((short) 513)); |
Priyanka B | 0ab34b9 | 2015-12-03 21:13:52 +0530 | [diff] [blame] | 1361 | |
| 1362 | IsIsNonPseudonode testIsIsNonPseudonode = (IsIsNonPseudonode) subtlvlist1.next(); |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 1363 | byte[] expIsoNodeId = new byte[] {0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58}; |
| 1364 | assertThat(testIsIsNonPseudonode.getIsoNodeId(), is(expIsoNodeId)); |
Priyanka B | 0ab34b9 | 2015-12-03 21:13:52 +0530 | [diff] [blame] | 1365 | assertThat(testIsIsNonPseudonode.getType(), is((short) 515)); |
| 1366 | } |
| 1367 | |
| 1368 | /** |
| 1369 | * This test case checks update message with invalid mpreach packet. |
| 1370 | */ |
| 1371 | @Test(expected = BgpParseException.class) |
| 1372 | public void bgpUpdateMessageTest32() throws BgpParseException { |
| 1373 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1374 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1375 | (byte) 0xff, (byte) 0xff, 0x00, (byte) 0xd6, 0x02, 0x00, 0x04, |
| 1376 | 0x18, 0x0a, 0x01, 0x01, //withdrawn routes |
| 1377 | 0x00, (byte) 0xbb, //path attribute len |
| 1378 | 0x04, 0x01, 0x01, 0x00, //origin |
| 1379 | 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path |
| 1380 | (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med |
| 1381 | (byte) 0x90, 0x0e, 0x00, (byte) 0xa5, 0x40, 0x04, 0x47, //mpreach |
| 1382 | 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop |
| 1383 | 0x00, //reserved |
| 1384 | 0x00, 0x03, 0x00, 0x30, 0x02, 0x00, 0x00, 0x00, |
| 1385 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 1386 | 0x1a, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, |
| 1387 | (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, |
| 1388 | 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, 0x21, 0x68, |
| 1389 | 0x07, 0x70, 0x01, 0x01, 0x09, 0x00, 0x05, 0x20, |
| 1390 | (byte) 0xc0, (byte) 0xa8, 0x4d, 0x01, 0x00, 0x03, 0x00, 0x30, |
| 1391 | 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1392 | 0x00, 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, 0x00, |
| 1393 | 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, |
| 1394 | 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, |
| 1395 | 0x06, 0x19, 0x00, (byte) 0x95, 0x02, 0x50, 0x21, 0x01, |
| 1396 | 0x09, 0x00, 0x05, 0x20, 0x15, 0x15, 0x15, 0x15, |
| 1397 | 0x00, 0x03, 0x00, 0x30, 0x02, 0x00, 0x00, 0x00, |
| 1398 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, |
| 1399 | 0x1a, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, |
| 1400 | (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, |
| 1401 | 0x02, 0x02, 0x03, 0x00, 0x06, 0x02, 0x20, 0x22, |
| 1402 | 0x02, 0x20, 0x22, 0x01, 0x09, 0x00, 0x05, 0x20, |
| 1403 | 0x16, 0x16, 0x16, 0x16}; // prefix nlri |
| 1404 | |
| 1405 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 1406 | buffer.writeBytes(updateMsg); |
| 1407 | |
| 1408 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 1409 | BgpMessage message; |
| 1410 | BgpHeader bgpHeader = new BgpHeader(); |
| 1411 | |
| 1412 | message = reader.readFrom(buffer, bgpHeader); |
| 1413 | |
| 1414 | assertThat(message, instanceOf(BgpUpdateMsg.class)); |
| 1415 | } |
| 1416 | |
| 1417 | /** |
| 1418 | * This test case checks update message with invalid prefix nlri length in input. |
| 1419 | */ |
| 1420 | @Test(expected = BgpParseException.class) |
| 1421 | public void bgpUpdateMessageTest33() throws BgpParseException { |
| 1422 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1423 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1424 | (byte) 0xff, (byte) 0xff, 0x00, (byte) 0xd6, 0x02, 0x00, 0x04, |
| 1425 | 0x18, 0x0a, 0x01, 0x01, //withdrawn routes |
| 1426 | 0x00, (byte) 0xbb, //path attribute len |
| 1427 | 0x04, 0x01, 0x01, 0x00, //origin |
| 1428 | 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path |
| 1429 | (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med |
| 1430 | (byte) 0x90, 0x0e, 0x00, (byte) 0xa5, 0x40, 0x04, 0x47, //mpreach |
| 1431 | 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop |
| 1432 | 0x00, //reserved |
| 1433 | 0x00, 0x03, 0x00, 0x35, 0x02, 0x00, 0x00, 0x00, |
| 1434 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, |
| 1435 | 0x1a, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, |
| 1436 | (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, |
| 1437 | 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, 0x21, 0x68, |
| 1438 | 0x07, 0x70, 0x01, 0x01, 0x09, 0x00, 0x05, 0x20, |
| 1439 | (byte) 0xc0, (byte) 0xa8, 0x4d, 0x01, 0x00, 0x03, 0x00, 0x30, |
| 1440 | 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1441 | 0x00, 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, 0x00, |
| 1442 | 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, |
| 1443 | 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, |
| 1444 | 0x06, 0x19, 0x00, (byte) 0x95, 0x02, 0x50, 0x21, 0x01, |
| 1445 | 0x09, 0x00, 0x05, 0x20, 0x15, 0x15, 0x15, 0x15, |
| 1446 | 0x00, 0x03, 0x00, 0x30, 0x02, 0x00, 0x00, 0x00, |
| 1447 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, |
| 1448 | 0x1a, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, |
| 1449 | (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, |
| 1450 | 0x02, 0x02, 0x03, 0x00, 0x06, 0x02, 0x20, 0x22, |
| 1451 | 0x02, 0x20, 0x22, 0x01, 0x09, 0x00, 0x05, 0x20, |
| 1452 | 0x16, 0x16, 0x16, 0x16}; // prefix nlri |
| 1453 | |
| 1454 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 1455 | buffer.writeBytes(updateMsg); |
| 1456 | |
| 1457 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 1458 | BgpMessage message; |
| 1459 | BgpHeader bgpHeader = new BgpHeader(); |
| 1460 | |
| 1461 | message = reader.readFrom(buffer, bgpHeader); |
| 1462 | |
| 1463 | assertThat(message, instanceOf(BgpUpdateMsg.class)); |
| 1464 | } |
| 1465 | |
| 1466 | /** |
| 1467 | * This test case checks update message with invalid link nlri length in input. |
| 1468 | */ |
| 1469 | @Test(expected = BgpParseException.class) |
| 1470 | public void bgpUpdateMessageTest34() throws BgpParseException { |
| 1471 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1472 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1473 | (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x83, 0x02, 0x00, 0x04, |
| 1474 | 0x18, 0x0a, 0x01, 0x01, //withdrawn routes |
| 1475 | 0x00, 0x68, //path attribute len |
| 1476 | 0x04, 0x01, 0x01, 0x00, //origin |
| 1477 | 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path |
| 1478 | (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med |
| 1479 | (byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach |
| 1480 | 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop |
| 1481 | 0x00, //reserved |
| 1482 | 0x00, 0x02, 0x00, 0x48, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1483 | 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00, |
| 1484 | 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, |
| 1485 | 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00, |
| 1486 | (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02, |
| 1487 | 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, |
| 1488 | 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, |
| 1489 | 0x00, (byte) 0x95, 0x02, 0x50, 0x21}; //link nlri |
| 1490 | |
| 1491 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 1492 | buffer.writeBytes(updateMsg); |
| 1493 | |
| 1494 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 1495 | BgpMessage message; |
| 1496 | BgpHeader bgpHeader = new BgpHeader(); |
| 1497 | |
| 1498 | message = reader.readFrom(buffer, bgpHeader); |
| 1499 | |
| 1500 | assertThat(message, instanceOf(BgpUpdateMsg.class)); |
| 1501 | } |
| 1502 | |
| 1503 | //Negative scenarios |
| 1504 | /** |
| 1505 | * Wrong length BgpAttrRouterIdV4. |
| 1506 | */ |
| 1507 | @Test(expected = BgpParseException.class) |
| 1508 | public void bgpUpdateMessageTest35() throws BgpParseException { |
| 1509 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1510 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1511 | (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x95, |
| 1512 | 0x02, 0x00, 0x04, |
| 1513 | 0x18, 0x0a, 0x01, 0x01, //withdrawn routes |
| 1514 | 0x00, 0x7A, //path attribute len |
| 1515 | 0x04, 0x01, 0x01, 0x00, //origin |
| 1516 | 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path |
| 1517 | (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med |
| 1518 | (byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach |
| 1519 | 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop |
| 1520 | 0x00, //reserved |
| 1521 | 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1522 | 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00, |
| 1523 | 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, |
| 1524 | 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00, |
| 1525 | (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02, |
| 1526 | 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, |
| 1527 | 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, |
| 1528 | 0x00, (byte) 0x95, 0x02, 0x50, 0x21, //link nlri |
| 1529 | (byte) 0x80, 0x1d, 0x0f, //linkstate attr |
| 1530 | 0x04, 0x04, 0x00, 0x06, (byte) 0xbd, 0x59, 0x4c, 0x62, //BgpAttrRouterIdV4 |
| 1531 | 0x04, 0x47, 0x00, 0x03, 0x00, 0x00, 0x0a}; //BgpLinkAttrIGPMetric |
| 1532 | |
| 1533 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 1534 | buffer.writeBytes(updateMsg); |
| 1535 | |
| 1536 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 1537 | BgpHeader bgpHeader = new BgpHeader(); |
| 1538 | reader.readFrom(buffer, bgpHeader); |
| 1539 | } |
| 1540 | |
| 1541 | /** |
| 1542 | * Wrong length BgpLinkAttrIGPMetric. |
| 1543 | */ |
| 1544 | @Test(expected = BgpParseException.class) |
| 1545 | public void bgpUpdateMessageTest36() throws BgpParseException { |
| 1546 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1547 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1548 | (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x95, |
| 1549 | 0x02, 0x00, 0x04, |
| 1550 | 0x18, 0x0a, 0x01, 0x01, //withdrawn routes |
| 1551 | 0x00, 0x7A, //path attribute len |
| 1552 | 0x04, 0x01, 0x01, 0x00, //origin |
| 1553 | 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path |
| 1554 | (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med |
| 1555 | (byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach |
| 1556 | 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop |
| 1557 | 0x00, //reserved |
| 1558 | 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1559 | 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00, |
| 1560 | 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, |
| 1561 | 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00, |
| 1562 | (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02, |
| 1563 | 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, |
| 1564 | 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, |
| 1565 | 0x00, (byte) 0x95, 0x02, 0x50, 0x21, //link nlri |
| 1566 | (byte) 0x80, 0x1d, 0x0f, //linkstate attr |
| 1567 | 0x04, 0x04, 0x00, 0x04, (byte) 0xbd, 0x59, 0x4c, 0x62, //BgpAttrRouterIdV4 |
| 1568 | 0x04, 0x47, 0x00, 0x02, 0x00, 0x00, 0x0a}; //BgpLinkAttrIGPMetric |
| 1569 | |
| 1570 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 1571 | buffer.writeBytes(updateMsg); |
| 1572 | |
| 1573 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 1574 | BgpHeader bgpHeader = new BgpHeader(); |
| 1575 | reader.readFrom(buffer, bgpHeader); |
| 1576 | } |
| 1577 | |
| 1578 | /** |
| 1579 | * Wrong length BgpPrefixAttrMetric. |
| 1580 | */ |
| 1581 | @Test(expected = BgpParseException.class) |
| 1582 | public void bgpUpdateMessageTest37() throws BgpParseException { |
| 1583 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1584 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1585 | (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x96, |
| 1586 | 0x02, 0x00, 0x04, |
| 1587 | 0x18, 0x0a, 0x01, 0x01, //withdrawn routes |
| 1588 | 0x00, 0x7b, //path attribute len |
| 1589 | 0x04, 0x01, 0x01, 0x00, //origin |
| 1590 | 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path |
| 1591 | (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med |
| 1592 | (byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach |
| 1593 | 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop |
| 1594 | 0x00, //reserved |
| 1595 | 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1596 | 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00, |
| 1597 | 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, |
| 1598 | 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00, |
| 1599 | (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02, |
| 1600 | 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, |
| 1601 | 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, |
| 1602 | 0x00, (byte) 0x95, 0x02, 0x50, 0x21, //link nlri |
| 1603 | (byte) 0x80, 0x1d, 0x10, //linkstate attr |
| 1604 | 0x04, 0x04, 0x00, 0x04, (byte) 0x15, 0x15, 0x15, 0x15, //BgpAttrRouterIdV4 |
| 1605 | 0x04, (byte) 0x83, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00}; //BgpPrefixAttrMetric |
| 1606 | |
| 1607 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 1608 | buffer.writeBytes(updateMsg); |
| 1609 | |
| 1610 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 1611 | BgpHeader bgpHeader = new BgpHeader(); |
| 1612 | reader.readFrom(buffer, bgpHeader); |
| 1613 | } |
| 1614 | |
| 1615 | /** |
| 1616 | * Wrong length BgpPrefixAttrMetric. |
| 1617 | */ |
| 1618 | @Test(expected = BgpParseException.class) |
| 1619 | public void bgpUpdateMessageTest38() throws BgpParseException { |
| 1620 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1621 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1622 | (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x96, |
| 1623 | 0x02, 0x00, 0x04, |
| 1624 | 0x18, 0x0a, 0x01, 0x01, //withdrawn routes |
| 1625 | 0x00, 0x7b, //path attribute len |
| 1626 | 0x04, 0x01, 0x01, 0x00, //origin |
| 1627 | 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path |
| 1628 | (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med |
| 1629 | (byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach |
| 1630 | 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop |
| 1631 | 0x00, //reserved |
| 1632 | 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1633 | 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00, |
| 1634 | 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, |
| 1635 | 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00, |
| 1636 | (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02, |
| 1637 | 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, |
| 1638 | 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, |
| 1639 | 0x00, (byte) 0x95, 0x02, 0x50, 0x21, //link nlri |
| 1640 | (byte) 0x80, 0x1d, 0x10, //linkstate attr |
| 1641 | 0x04, 0x04, 0x00, 0x04, (byte) 0x15, 0x15, 0x15, 0x15, //BgpAttrRouterIdV4 |
| 1642 | 0x04, (byte) 0x83, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00}; //BgpPrefixAttrMetric |
| 1643 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 1644 | buffer.writeBytes(updateMsg); |
| 1645 | |
| 1646 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 1647 | BgpHeader bgpHeader = new BgpHeader(); |
| 1648 | reader.readFrom(buffer, bgpHeader); |
| 1649 | } |
| 1650 | |
| 1651 | /** |
| 1652 | * Wrong length BgpPrefixAttrOpaqueData. |
| 1653 | */ |
| 1654 | @Test(expected = BgpParseException.class) |
| 1655 | public void bgpUpdateMessageTest39() throws BgpParseException { |
| 1656 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1657 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1658 | (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x96, |
| 1659 | 0x02, 0x00, 0x04, |
| 1660 | 0x18, 0x0a, 0x01, 0x01, //withdrawn routes |
| 1661 | 0x00, 0x7B, //path attribute len |
| 1662 | 0x04, 0x01, 0x01, 0x00, //origin |
| 1663 | 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path |
| 1664 | (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med |
| 1665 | (byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach |
| 1666 | 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop |
| 1667 | 0x00, //reserved |
| 1668 | 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1669 | 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00, |
| 1670 | 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, |
| 1671 | 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00, |
| 1672 | (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02, |
| 1673 | 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, |
| 1674 | 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, |
| 1675 | 0x00, (byte) 0x95, 0x02, 0x50, 0x21, //link nlri |
| 1676 | (byte) 0x80, 0x1d, 0x10, //linkstate attr |
| 1677 | 0x04, 0x04, 0x00, 0x04, 0x15, 0x15, 0x15, 0x15, //BgpAttrRouterIdV4 |
| 1678 | 0x04, (byte) 0x85, 0x00, 0x06, 0x0a, 0x0a, 0x0a, 0x0a}; //BgpPrefixAttrOpaqueData |
| 1679 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 1680 | buffer.writeBytes(updateMsg); |
| 1681 | |
| 1682 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 1683 | BgpHeader bgpHeader = new BgpHeader(); |
| 1684 | reader.readFrom(buffer, bgpHeader); |
| 1685 | } |
| 1686 | |
| 1687 | /** |
| 1688 | * Test for LinkStateattribute BgpAttrNodeRouterId and BgpLinkAttrName. |
| 1689 | * |
| 1690 | * @throws BgpParseException while parsing update message |
| 1691 | */ |
| 1692 | @Test |
| 1693 | public void bgpUpdateMessageTest40() throws BgpParseException { |
| 1694 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1695 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1696 | (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x9A, |
| 1697 | 0x02, 0x00, 0x04, |
| 1698 | 0x18, 0x0a, 0x01, 0x01, //withdrawn routes |
| 1699 | 0x00, 0x7F, //path attribute len |
| 1700 | 0x04, 0x01, 0x01, 0x00, //origin |
| 1701 | 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path |
| 1702 | (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med |
| 1703 | (byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach |
| 1704 | 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop |
| 1705 | 0x00, //reserved |
| 1706 | 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1707 | 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00, |
| 1708 | 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, |
| 1709 | 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00, |
| 1710 | (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02, |
| 1711 | 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, |
| 1712 | 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, |
| 1713 | 0x00, (byte) 0x95, 0x02, 0x50, 0x21, //link nlri |
| 1714 | (byte) 0x80, 0x1d, 0x14, //linkstate attr |
| 1715 | 0x04, 0x04, 0x00, 0x04, (byte) 0x15, 0x15, 0x15, 0x15, //BgpAttrRouterIdV4 |
| 1716 | 0x04, 0x4A, 0x00, 0x08, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x0b}; //BgpLinkAttrName |
| 1717 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 1718 | buffer.writeBytes(updateMsg); |
| 1719 | |
| 1720 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 1721 | BgpMessage message = null; |
| 1722 | BgpHeader bgpHeader = new BgpHeader(); |
| 1723 | |
| 1724 | message = reader.readFrom(buffer, bgpHeader); |
| 1725 | |
| 1726 | assertThat(message, instanceOf(BgpUpdateMsg.class)); |
| 1727 | BgpUpdateMsg other = (BgpUpdateMsg) message; |
| 1728 | |
| 1729 | byte[] marker = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1730 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1731 | (byte) 0xff, (byte) 0xff, (byte) 0xff }; |
| 1732 | |
| 1733 | assertThat(other.getHeader().getMarker(), is(marker)); |
| 1734 | assertThat(other.getHeader().getType(), is((byte) 2)); |
| 1735 | assertThat(other.getHeader().getLength(), is((short) 154)); |
| 1736 | |
| 1737 | ListIterator<IpPrefix> listIterator1 = other.withdrawnRoutes().listIterator(); |
| 1738 | byte[] prefix = new byte[] {0x0a, 0x01, 0x01, 0x00}; |
| 1739 | |
| 1740 | while (listIterator1.hasNext()) { |
| 1741 | IpPrefix testPrefixValue = listIterator1.next(); |
| 1742 | assertThat(testPrefixValue.prefixLength(), is((int) 24)); |
| 1743 | assertThat(testPrefixValue.address().toOctets(), is(prefix)); |
| 1744 | } |
| 1745 | |
| 1746 | BgpValueType testPathAttribute = null; |
| 1747 | Origin origin; |
| 1748 | AsPath aspath; |
| 1749 | Med med; |
| 1750 | MpReachNlri mpReach; |
| 1751 | LinkStateAttributes linkStateAttr; |
| 1752 | List<BgpValueType> pathAttributeList = new LinkedList<>(); |
| 1753 | BgpPathAttributes pathAttribute = other.bgpPathAttributes(); |
| 1754 | pathAttributeList = pathAttribute.pathAttributes(); |
| 1755 | ListIterator<BgpValueType> listIterator = pathAttributeList.listIterator(); |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 1756 | OriginType originValue = OriginType.IGP; |
Priyanka B | 0ab34b9 | 2015-12-03 21:13:52 +0530 | [diff] [blame] | 1757 | |
| 1758 | testPathAttribute = listIterator.next(); |
| 1759 | origin = (Origin) testPathAttribute; |
| 1760 | assertThat(origin.origin(), is(originValue)); |
| 1761 | |
| 1762 | testPathAttribute = listIterator.next(); |
| 1763 | aspath = (AsPath) testPathAttribute; |
| 1764 | ListIterator<Short> listIterator2 = aspath.asPathSeq().listIterator(); |
| 1765 | assertThat(listIterator2.next(), is((short) 65001)); |
| 1766 | |
| 1767 | testPathAttribute = listIterator.next(); |
| 1768 | med = (Med) testPathAttribute; |
| 1769 | assertThat(med.med(), is(0)); |
| 1770 | |
| 1771 | testPathAttribute = listIterator.next(); |
| 1772 | mpReach = (MpReachNlri) testPathAttribute; |
| 1773 | assertThat(mpReach.mpReachNlriLen(), is((int) 83)); |
| 1774 | assertThat(mpReach.getType(), is((short) 14)); |
| 1775 | |
| 1776 | List<BgpLSNlri> testMpReachNlri = new LinkedList<>(); |
| 1777 | testMpReachNlri = mpReach.mpReachNlri(); |
| 1778 | |
| 1779 | ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator(); |
| 1780 | BgpLSNlri testnlri = list1.next(); |
| 1781 | NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.LINK; |
| 1782 | ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate. |
| 1783 | BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO; |
| 1784 | assertThat(testnlri.getIdentifier(), is((long) 0)); |
| 1785 | assertThat(testnlri.getNlriType(), is(nlriType)); |
| 1786 | assertThat(testnlri.getProtocolId(), is(protocolId)); |
| 1787 | |
| 1788 | testPathAttribute = listIterator.next(); |
| 1789 | linkStateAttr = (LinkStateAttributes) testPathAttribute; |
| 1790 | |
| 1791 | assertThat(linkStateAttr.getType(), is((short) 29)); |
| 1792 | ListIterator<BgpValueType> list = linkStateAttr.linkStateAttributes().listIterator(); |
| 1793 | byte[] ipBytes = new byte[] {(byte) 0x15, 0x15, 0x15, 0x15 }; |
| 1794 | Ip4Address ip4RouterId = Ip4Address.valueOf(ipBytes); |
| 1795 | assertThat(((BgpAttrRouterIdV4) list.next()).attrRouterId(), is(ip4RouterId)); |
| 1796 | byte[] linkName = new byte[] {0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x0b }; |
| 1797 | assertThat(((BgpLinkAttrName) list.next()).attrLinkName(), is(linkName)); |
| 1798 | } |
| 1799 | |
| 1800 | /** |
| 1801 | * Test for LinkStateattribute BgpAttrNodeRouterId and BgpPrefixAttrIGPFlags. |
| 1802 | * |
| 1803 | * @throws BgpParseException while parsing update message |
| 1804 | */ |
| 1805 | @Test |
| 1806 | public void bgpUpdateMessageTest41() throws BgpParseException { |
| 1807 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1808 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1809 | (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x93, |
| 1810 | 0x02, 0x00, 0x04, |
| 1811 | 0x18, 0x0a, 0x01, 0x01, //withdrawn routes |
| 1812 | 0x00, 0x78, //path attribute len |
| 1813 | 0x04, 0x01, 0x01, 0x00, //origin |
| 1814 | 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path |
| 1815 | (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med |
| 1816 | (byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach |
| 1817 | 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop |
| 1818 | 0x00, //reserved |
| 1819 | 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1820 | 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00, |
| 1821 | 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, |
| 1822 | 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00, |
| 1823 | (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02, |
| 1824 | 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, |
| 1825 | 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, |
| 1826 | 0x00, (byte) 0x95, 0x02, 0x50, 0x21, //link nlri |
| 1827 | (byte) 0x80, 0x1d, 0x0D, //linkstate attr |
| 1828 | 0x04, 0x04, 0x00, 0x04, (byte) 0x15, 0x15, 0x15, 0x15, //BgpAttrRouterIdV4 |
| 1829 | 0x04, (byte) 0x80, 0x00, 0x01, (byte) 0xA0}; //BgpPrefixAttrIGPFlags |
| 1830 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 1831 | buffer.writeBytes(updateMsg); |
| 1832 | |
| 1833 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 1834 | BgpMessage message = null; |
| 1835 | BgpHeader bgpHeader = new BgpHeader(); |
| 1836 | |
| 1837 | message = reader.readFrom(buffer, bgpHeader); |
| 1838 | |
| 1839 | assertThat(message, instanceOf(BgpUpdateMsg.class)); |
| 1840 | BgpUpdateMsg other = (BgpUpdateMsg) message; |
| 1841 | |
| 1842 | byte[] marker = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1843 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1844 | (byte) 0xff, (byte) 0xff, (byte) 0xff }; |
| 1845 | |
| 1846 | assertThat(other.getHeader().getMarker(), is(marker)); |
| 1847 | assertThat(other.getHeader().getType(), is((byte) 2)); |
| 1848 | assertThat(other.getHeader().getLength(), is((short) 147)); |
| 1849 | |
| 1850 | BgpValueType testPathAttribute = null; |
| 1851 | Origin origin; |
| 1852 | AsPath aspath; |
| 1853 | Med med; |
| 1854 | MpReachNlri mpReach; |
| 1855 | LinkStateAttributes linkStateAttr; |
| 1856 | List<BgpValueType> pathAttributeList = new LinkedList<>(); |
| 1857 | BgpPathAttributes pathAttribute = other.bgpPathAttributes(); |
| 1858 | pathAttributeList = pathAttribute.pathAttributes(); |
| 1859 | ListIterator<BgpValueType> listIterator = pathAttributeList.listIterator(); |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 1860 | OriginType originValue = OriginType.IGP; |
Priyanka B | 0ab34b9 | 2015-12-03 21:13:52 +0530 | [diff] [blame] | 1861 | |
| 1862 | testPathAttribute = listIterator.next(); |
| 1863 | origin = (Origin) testPathAttribute; |
| 1864 | assertThat(origin.origin(), is(originValue)); |
| 1865 | |
| 1866 | testPathAttribute = listIterator.next(); |
| 1867 | aspath = (AsPath) testPathAttribute; |
| 1868 | ListIterator<Short> listIterator2 = aspath.asPathSeq().listIterator(); |
| 1869 | assertThat(listIterator2.next(), is((short) 65001)); |
| 1870 | |
| 1871 | testPathAttribute = listIterator.next(); |
| 1872 | med = (Med) testPathAttribute; |
| 1873 | assertThat(med.med(), is(0)); |
| 1874 | |
| 1875 | testPathAttribute = listIterator.next(); |
| 1876 | mpReach = (MpReachNlri) testPathAttribute; |
| 1877 | List<BgpLSNlri> testMpReachNlri = new LinkedList<>(); |
| 1878 | testMpReachNlri = mpReach.mpReachNlri(); |
| 1879 | |
| 1880 | ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator(); |
| 1881 | BgpLSNlri testnlri = list1.next(); |
| 1882 | NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.LINK; |
| 1883 | ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate. |
| 1884 | BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO; |
| 1885 | assertThat(testnlri.getIdentifier(), is((long) 0)); |
| 1886 | assertThat(testnlri.getNlriType(), is(nlriType)); |
| 1887 | assertThat(testnlri.getProtocolId(), is(protocolId)); |
| 1888 | |
| 1889 | testPathAttribute = listIterator.next(); |
| 1890 | linkStateAttr = (LinkStateAttributes) testPathAttribute; |
| 1891 | |
| 1892 | assertThat(linkStateAttr.getType(), is((short) 29)); |
| 1893 | ListIterator<BgpValueType> list = linkStateAttr.linkStateAttributes().listIterator(); |
| 1894 | byte[] ipBytes = new byte[] {(byte) 0x15, 0x15, 0x15, 0x15 }; |
| 1895 | Ip4Address ip4RouterId = Ip4Address.valueOf(ipBytes); |
| 1896 | assertThat(((BgpAttrRouterIdV4) list.next()).attrRouterId(), is(ip4RouterId)); |
| 1897 | BgpPrefixAttrIgpFlags obj = new BgpPrefixAttrIgpFlags(true, false, true, false); |
| 1898 | assertThat(((BgpPrefixAttrIgpFlags) list.next()).equals(obj), is(true)); |
| 1899 | } |
| 1900 | |
| 1901 | /** |
| 1902 | * Test for LinkStateattribute BgpAttrNodeRouterId and BgpPrefixAttrExtRouteTag. |
| 1903 | * |
| 1904 | * @throws BgpParseException while parsing update message |
| 1905 | */ |
| 1906 | @Test |
| 1907 | public void bgpUpdateMessageTest42() throws BgpParseException { |
| 1908 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1909 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1910 | (byte) 0xff, (byte) 0xff, 0x00, (byte) 0xA2, 0x02, 0x00, 0x04, |
| 1911 | 0x18, 0x0a, 0x01, 0x01, 0x00, (byte) 0x87, 0x04, 0x01, 0x01, 0x00, //origin |
| 1912 | 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path |
| 1913 | (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med |
| 1914 | (byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach |
| 1915 | 0x04, 0x04, 0x00, 0x00, 0x01, 0x00, //reserved |
| 1916 | 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1917 | 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00, |
| 1918 | 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, |
| 1919 | 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00, |
| 1920 | (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02, |
| 1921 | 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, |
| 1922 | 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, |
| 1923 | 0x00, (byte) 0x95, 0x02, 0x50, 0x21, (byte) 0x80, 0x1d, 0x1C, //linkstate attr |
| 1924 | 0x04, 0x04, 0x00, 0x04, (byte) 0x15, 0x15, 0x15, 0x15, //BgpAttrNodeRouterId |
| 1925 | 0x04, (byte) 0x82, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x02, (byte) 0xBB, (byte) 0xE9, 0x0B, |
| 1926 | 0x00, 0x00, 0x00, 0x00, 0x03, 0x20, 0x6E, 0x1B}; //BgpPrefixAttrExtRouteTag |
| 1927 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 1928 | buffer.writeBytes(updateMsg); |
| 1929 | |
| 1930 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
| 1931 | BgpMessage message = null; |
| 1932 | BgpHeader bgpHeader = new BgpHeader(); |
| 1933 | |
| 1934 | message = reader.readFrom(buffer, bgpHeader); |
| 1935 | |
| 1936 | assertThat(message, instanceOf(BgpUpdateMsg.class)); |
| 1937 | BgpUpdateMsg other = (BgpUpdateMsg) message; |
| 1938 | |
| 1939 | byte[] marker = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1940 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 1941 | (byte) 0xff, (byte) 0xff, (byte) 0xff }; |
| 1942 | |
| 1943 | assertThat(other.getHeader().getMarker(), is(marker)); |
| 1944 | assertThat(other.getHeader().getType(), is((byte) 2)); |
| 1945 | assertThat(other.getHeader().getLength(), is((short) 162)); |
| 1946 | |
| 1947 | BgpValueType testPathAttribute = null; |
| 1948 | Origin origin; |
| 1949 | AsPath aspath; |
| 1950 | Med med; |
| 1951 | MpReachNlri mpReach; |
| 1952 | LinkStateAttributes linkStateAttr; |
| 1953 | List<BgpValueType> pathAttributeList = new LinkedList<>(); |
| 1954 | BgpPathAttributes pathAttribute = other.bgpPathAttributes(); |
| 1955 | pathAttributeList = pathAttribute.pathAttributes(); |
| 1956 | ListIterator<BgpValueType> listIterator = pathAttributeList.listIterator(); |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 1957 | OriginType originValue = OriginType.IGP; |
Priyanka B | 0ab34b9 | 2015-12-03 21:13:52 +0530 | [diff] [blame] | 1958 | |
| 1959 | testPathAttribute = listIterator.next(); |
| 1960 | origin = (Origin) testPathAttribute; |
| 1961 | assertThat(origin.origin(), is(originValue)); |
| 1962 | |
| 1963 | testPathAttribute = listIterator.next(); |
| 1964 | aspath = (AsPath) testPathAttribute; |
| 1965 | ListIterator<Short> listIterator2 = aspath.asPathSeq().listIterator(); |
| 1966 | assertThat(listIterator2.next(), is((short) 65001)); |
| 1967 | |
| 1968 | testPathAttribute = listIterator.next(); |
| 1969 | med = (Med) testPathAttribute; |
| 1970 | assertThat(med.med(), is(0)); |
| 1971 | |
| 1972 | testPathAttribute = listIterator.next(); |
| 1973 | mpReach = (MpReachNlri) testPathAttribute; |
| 1974 | |
| 1975 | List<BgpLSNlri> testMpReachNlri = new LinkedList<>(); |
| 1976 | testMpReachNlri = mpReach.mpReachNlri(); |
| 1977 | ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator(); |
| 1978 | BgpLSNlri testnlri = list1.next(); |
| 1979 | ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate. |
| 1980 | BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO; |
| 1981 | assertThat(testnlri.getProtocolId(), is(protocolId)); |
| 1982 | |
| 1983 | testPathAttribute = listIterator.next(); |
| 1984 | linkStateAttr = (LinkStateAttributes) testPathAttribute; |
| 1985 | |
| 1986 | assertThat(linkStateAttr.getType(), is((short) 29)); |
| 1987 | ListIterator<BgpValueType> list = linkStateAttr.linkStateAttributes().listIterator(); |
| 1988 | byte[] ipBytes = new byte[] {(byte) 0x15, 0x15, 0x15, 0x15 }; |
| 1989 | Ip4Address ip4RouterId = Ip4Address.valueOf(ipBytes); |
| 1990 | assertThat(((BgpAttrRouterIdV4) list.next()).attrRouterId(), is(ip4RouterId)); |
| 1991 | List<Long> extRouteTag = new LinkedList<>(); |
| 1992 | extRouteTag.add(45869323L); |
| 1993 | extRouteTag.add(52456987L); |
| 1994 | assertThat(((BgpPrefixAttrExtRouteTag) list.next()).pfxExtRouteTag(), is(extRouteTag)); |
| 1995 | } |
| 1996 | } |