Vidyashree Rama | 7bd3d78 | 2015-11-23 08:46:33 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Vidyashree Rama | 7bd3d78 | 2015-11-23 08:46:33 +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.bgp; |
| 17 | |
Priyanka B | 249027e | 2015-12-14 12:42:41 +0530 | [diff] [blame] | 18 | import java.net.InetSocketAddress; |
Vidyashree Rama | 7bd3d78 | 2015-11-23 08:46:33 +0530 | [diff] [blame] | 19 | import java.util.LinkedList; |
| 20 | import java.util.concurrent.TimeUnit; |
| 21 | |
| 22 | import org.jboss.netty.buffer.ChannelBuffer; |
| 23 | import org.jboss.netty.buffer.ChannelBuffers; |
| 24 | import org.jboss.netty.channel.ChannelHandlerContext; |
| 25 | import org.jboss.netty.channel.ChannelStateEvent; |
| 26 | import org.jboss.netty.channel.SimpleChannelHandler; |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 27 | import org.onosproject.bgpio.protocol.ver4.BgpKeepaliveMsgVer4; |
| 28 | import org.onosproject.bgpio.protocol.ver4.BgpOpenMsgVer4; |
| 29 | import org.onosproject.bgpio.types.BgpHeader; |
| 30 | import org.onosproject.bgpio.types.BgpValueType; |
Priyanka B | 249027e | 2015-12-14 12:42:41 +0530 | [diff] [blame] | 31 | import org.slf4j.Logger; |
| 32 | import org.slf4j.LoggerFactory; |
Vidyashree Rama | 7bd3d78 | 2015-11-23 08:46:33 +0530 | [diff] [blame] | 33 | |
| 34 | public class BgpPeerChannelHandlerTest extends SimpleChannelHandler { |
Ray Milkey | 9c9cde4 | 2018-01-12 14:22:06 -0800 | [diff] [blame^] | 35 | private static final Logger log = LoggerFactory.getLogger(BgpPeerChannelHandlerTest.class); |
Vidyashree Rama | 7bd3d78 | 2015-11-23 08:46:33 +0530 | [diff] [blame] | 36 | public static final int OPEN_MSG_MINIMUM_LENGTH = 29; |
| 37 | public static final byte[] MARKER = new byte[] {(byte) 0xff, (byte) 0xff, |
| 38 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 39 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 40 | (byte) 0xff, (byte) 0xff}; |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 41 | public static final BgpHeader DEFAULT_OPEN_HEADER = new BgpHeader(MARKER, |
Vidyashree Rama | 7bd3d78 | 2015-11-23 08:46:33 +0530 | [diff] [blame] | 42 | (short) OPEN_MSG_MINIMUM_LENGTH, (byte) 0X01); |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 43 | LinkedList<BgpValueType> capabilityTlv = new LinkedList<>(); |
Vidyashree Rama | 7bd3d78 | 2015-11-23 08:46:33 +0530 | [diff] [blame] | 44 | public byte version; |
| 45 | public short asNumber; |
| 46 | public short holdTime; |
| 47 | public int bgpId; |
| 48 | public boolean isLargeAsCapabilitySet; |
| 49 | |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 50 | final BgpOpenMsgVer4 openMessage = new BgpOpenMsgVer4(); |
Vidyashree Rama | 7bd3d78 | 2015-11-23 08:46:33 +0530 | [diff] [blame] | 51 | ChannelHandlerContext savedCtx; |
| 52 | |
| 53 | /** |
| 54 | * Constructor to initialize all variables of BGP Open message. |
| 55 | * |
| 56 | * @param version BGP version in open message |
| 57 | * @param asNumber AS number in open message |
| 58 | * @param holdTime hold time in open message |
| 59 | * @param bgpId BGP identifier in open message |
| 60 | * @param capabilityTlv capabilities in open message |
| 61 | */ |
| 62 | public BgpPeerChannelHandlerTest(byte version, |
| 63 | short asNumber, |
| 64 | short holdTime, |
| 65 | int bgpId, |
| 66 | boolean isLargeAsCapabilitySet, |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 67 | LinkedList<BgpValueType> capabilityTlv) { |
Vidyashree Rama | 7bd3d78 | 2015-11-23 08:46:33 +0530 | [diff] [blame] | 68 | this.version = version; |
| 69 | this.asNumber = asNumber; |
| 70 | this.holdTime = holdTime; |
| 71 | this.bgpId = bgpId; |
| 72 | this.isLargeAsCapabilitySet = isLargeAsCapabilitySet; |
| 73 | this.capabilityTlv = capabilityTlv; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * closes the channel. |
| 78 | */ |
| 79 | void closeChannel() { |
| 80 | savedCtx.getChannel().close(); |
| 81 | } |
| 82 | |
Priyanka B | 249027e | 2015-12-14 12:42:41 +0530 | [diff] [blame] | 83 | /** |
| 84 | * Select update message buffer with VPN. |
| 85 | * |
| 86 | * @param select number to select update message buffer |
| 87 | * @return packet dump in byte array |
| 88 | */ |
| 89 | byte[] selectUpdateMessageVpn(int select) { |
| 90 | switch (select) { |
| 91 | case 5: |
| 92 | /** |
| 93 | * Node NLRI with VPN - MpReach. |
| 94 | */ |
| 95 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 96 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 97 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, 0x5E, 0x02, 0x00, 0x00, //withdrawn len |
| 98 | 0x00, 0x47, //path attribute len |
| 99 | 0x04, 0x01, 0x01, 0x02, //origin |
| 100 | 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path |
| 101 | (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med |
| 102 | (byte) 0x80, 0x0e, 0x32, 0x40, 0x04, (byte) 0x80, //mpreach with safi = 80 vpn |
| 103 | 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop |
| 104 | 0x00, //reserved |
| 105 | 0x00, 0x01, 0x00, 0x25, //type ND LEN |
| 106 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, |
| 107 | 0x02, |
| 108 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 109 | 0x01, 0x00, 0x00, 0x10, |
| 110 | 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x09, (byte) 0xae, |
| 111 | 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02}; //node nlri |
| 112 | return updateMsg; |
| 113 | case 6: |
| 114 | /** |
| 115 | * Node NLRI MpReach and MpUnReach different with same VPN. |
| 116 | */ |
| 117 | updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 118 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 119 | (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x8D, 0x02, 0x00, 0x00, //withdrawn len |
| 120 | 0x00, 0x76, //path attribute len |
| 121 | 0x04, 0x01, 0x01, 0x02, //origin |
| 122 | 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path |
| 123 | (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med |
| 124 | (byte) 0x80, 0x0e, 0x32, 0x40, 0x04, (byte) 0x80, //mpreach with safi = 80 vpn |
| 125 | 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop |
| 126 | 0x00, //reserved |
| 127 | 0x00, 0x01, 0x00, 0x25, //type ND LEN |
| 128 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, |
| 129 | 0x02, |
| 130 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 131 | 0x01, 0x00, 0x00, 0x10, |
| 132 | 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x02, (byte) 0xae, |
| 133 | 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, //node nlri |
| 134 | (byte) 0x80, 0x0f, 0x2C, 0x40, 0x04, (byte) 0x80, //mpUnreach with safi = 80 VPN |
| 135 | 0x00, 0x01, 0x00, 0x25, //type n len |
| 136 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, |
| 137 | 0x02, |
| 138 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 139 | 0x01, 0x00, 0x00, 0x10, |
| 140 | 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x04, (byte) 0xae, //AutonomousSystemTlv |
| 141 | 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02}; //BGPLSIdentifierTlv |
| 142 | return updateMsg; |
| 143 | case 7: |
| 144 | /** |
| 145 | * Node NLRI with same MpReach and MpUnReach with VPN. |
| 146 | */ |
| 147 | updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 148 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 149 | (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x8D, 0x02, 0x00, 0x00, //withdrawn len |
| 150 | 0x00, 0x76, //path attribute len |
| 151 | 0x04, 0x01, 0x01, 0x02, //origin |
| 152 | 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path |
| 153 | (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med |
| 154 | (byte) 0x80, 0x0e, 0x32, 0x40, 0x04, (byte) 0x80, //mpreach with safi = 80 vpn |
| 155 | 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop |
| 156 | 0x00, //reserved |
| 157 | 0x00, 0x01, 0x00, 0x25, //type ND LEN |
| 158 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, |
| 159 | 0x02, |
| 160 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 161 | 0x01, 0x00, 0x00, 0x10, |
| 162 | 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x09, (byte) 0xae, |
| 163 | 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, //node nlri |
| 164 | (byte) 0x80, 0x0f, 0x2C, 0x40, 0x04, (byte) 0x80, //mpUnreach with safi = 80 VPN |
| 165 | 0x00, 0x01, 0x00, 0x25, //type n len |
| 166 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, |
| 167 | 0x02, |
| 168 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 169 | 0x01, 0x00, 0x00, 0x10, |
| 170 | 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x09, (byte) 0xae, //AutonomousSystemTlv |
| 171 | 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02}; //BGPLSIdentifierTlv |
| 172 | return updateMsg; |
| 173 | case 17: |
| 174 | /** |
| 175 | * Node NLRI with VPN - MpReach. |
| 176 | */ |
| 177 | updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 178 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 179 | (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, 0x5E, 0x02, 0x00, 0x00, //withdrawn len |
| 180 | 0x00, 0x47, //path attribute len |
| 181 | 0x04, 0x01, 0x01, 0x02, //origin |
| 182 | 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path |
| 183 | (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med |
| 184 | (byte) 0x80, 0x0e, 0x32, 0x40, 0x04, (byte) 0x80, //mpreach with safi = 80 vpn |
| 185 | 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop |
| 186 | 0x00, //reserved |
| 187 | 0x00, 0x01, 0x00, 0x25, //type ND LEN |
| 188 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, |
| 189 | 0x02, |
| 190 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 191 | 0x01, 0x00, 0x00, 0x10, |
| 192 | 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x09, (byte) 0xae, |
| 193 | 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02}; //node nlri |
| 194 | return updateMsg; |
| 195 | default: return null; |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * Select update message buffer without VPN. |
| 201 | * |
| 202 | * @param select number to select update message buffer |
| 203 | * @return packet dump in byte array |
| 204 | */ |
| 205 | byte[] selectUpdateMsg(int select) { |
| 206 | switch (select) { |
| 207 | case 1: |
| 208 | /** |
| 209 | * Node NLRI - MpReach. |
| 210 | */ |
| 211 | byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 212 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 213 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, 0x56, 0x02, 0x00, 0x00, //withdrawn len |
| 214 | 0x00, 0x3F, 0x04, 0x01, 0x01, 0x02, //origin |
| 215 | 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path |
| 216 | (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med |
| 217 | (byte) 0x80, 0x0e, 0x2A, 0x40, 0x04, 0x47, //mpreach with safi = 71 |
| 218 | 0x04, 0x04, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x1D, 0x02, |
| 219 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x10, |
| 220 | 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x09, (byte) 0xae, |
| 221 | 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02}; //node nlri |
| 222 | return updateMsg; |
| 223 | case 2: |
| 224 | /** |
| 225 | * Node NLRI with same MpReach and MpUnReach. |
| 226 | */ |
| 227 | updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 228 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 229 | (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x7D, 0x02, 0x00, 0x00, //withdrawn len |
| 230 | 0x00, 0x66, 0x04, 0x01, 0x01, 0x02, 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, |
| 231 | (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med |
| 232 | (byte) 0x80, 0x0e, 0x2A, 0x40, 0x04, 0x47, //mpreach with safi = 71 |
| 233 | 0x04, 0x04, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x1D, //type n len |
| 234 | 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 235 | 0x01, 0x00, 0x00, 0x10, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x09, (byte) 0xae, |
| 236 | 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, //BGPLSIdentifierTlv |
| 237 | (byte) 0x80, 0x0f, 0x24, 0x40, 0x04, 0x47, //mpUnreach with safi = 71 |
| 238 | 0x00, 0x01, 0x00, 0x1D, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 239 | 0x01, 0x00, 0x00, 0x10, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x09, (byte) 0xae, |
| 240 | 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, //BGPLSIdentifierTlv |
| 241 | }; |
| 242 | return updateMsg; |
| 243 | case 3: |
| 244 | /** |
| 245 | * Link NLRI - MpReach. |
| 246 | */ |
| 247 | updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 248 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 249 | (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x8B, 0x02, 0x00, 0x04, |
| 250 | 0x18, 0x0a, 0x01, 0x01, 0x00, 0x70, //path attribute len |
| 251 | 0x04, 0x01, 0x01, 0x00, 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path |
| 252 | (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x10, //med |
| 253 | (byte) 0x80, 0x0e, 0x5B, 0x40, 0x04, 0x47, //mpreach safi 71 |
| 254 | 0x04, 0x04, 0x00, 0x00, 0x01, 0x00, 0x00, 0x02, 0x00, 0x4E, 0x02, |
| 255 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, //local node |
| 256 | 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, |
| 257 | 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, |
| 258 | 0x02, 0x03, 0x00, 0x07, 0x19, 0x00, (byte) 0x95, 0x02, 0x50, 0x21, 0x03, |
| 259 | 0x01, 0x01, 0x00, 0x1a, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, |
| 260 | 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, |
| 261 | 0x02, 0x03, 0x00, 0x06, 0x19, 0x00, (byte) 0x95, 0x02, 0x50, 0x21, //link nlri |
| 262 | 0x01, 0x03, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02 |
| 263 | }; |
| 264 | return updateMsg; |
| 265 | case 4: |
| 266 | /** |
| 267 | * Prefix NLRI - MpReach. |
| 268 | */ |
| 269 | updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 270 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 271 | (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, (byte) 0xd6, 0x02, 0x00, 0x04, |
| 272 | 0x18, 0x0a, 0x01, 0x01, 0x00, (byte) 0xbb, //path attribute len |
| 273 | 0x04, 0x01, 0x01, 0x00, 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path |
| 274 | (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x12, //med |
| 275 | (byte) 0x90, 0x0e, 0x00, (byte) 0xa5, 0x40, 0x04, 0x47, //mpreach |
| 276 | 0x04, 0x04, 0x00, 0x00, 0x01, 0x00, 0x00, 0x03, 0x00, 0x30, |
| 277 | 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1a, //local node |
| 278 | 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, |
| 279 | 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, 0x21, 0x68, 0x07, |
| 280 | 0x70, 0x01, 0x01, 0x09, 0x00, 0x05, 0x20, (byte) 0xc0, (byte) 0xa8, 0x4d, 0x01, //prefix des |
| 281 | 0x00, 0x03, 0x00, 0x30, 0x02, |
| 282 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1a, |
| 283 | 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, |
| 284 | 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, |
| 285 | 0x02, 0x03, 0x00, 0x06, 0x19, 0x00, (byte) 0x95, 0x02, 0x50, 0x21, |
| 286 | 0x01, 0x09, 0x00, 0x05, 0x20, 0x15, 0x15, 0x15, 0x15, 0x00, 0x03, 0x00, 0x30, |
| 287 | 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 288 | 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, |
| 289 | 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, |
| 290 | 0x02, 0x03, 0x00, 0x06, 0x02, 0x20, 0x22, 0x02, 0x20, 0x22, |
| 291 | 0x01, 0x09, 0x00, 0x05, 0x20, 0x16, 0x16, 0x16, 0x16}; // prefix nlri |
| 292 | return updateMsg; |
| 293 | case 8: |
| 294 | /** |
| 295 | * Node NLRI with different MpReach and MpUnReach with IsIsPseudonode. |
| 296 | */ |
| 297 | updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 298 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 299 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, |
| 300 | (byte) 0x91, 0x02, 0x00, 0x00, 0x00, 0x7A, //path attribute len |
| 301 | 0x04, 0x01, 0x01, 0x02, 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, |
| 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, 0x00, 0x00, 0x01, 0x00, |
| 305 | 0x27, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 306 | 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, |
| 307 | 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, |
| 308 | 0x00, 0x06, 0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58, |
| 309 | (byte) 0x80, 0x0f, 0x2E, 0x40, 0x04, 0x47, 0x00, 0x01, 0x00, 0x27, //mpUnreach |
| 310 | 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 311 | 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x09, (byte) 0xae, |
| 312 | 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, //BGPLSIdentifierTlv |
| 313 | 0x02, 0x03, 0x00, 0x06, 0x19, 0x00, (byte) 0x99, 0x01, (byte) 0x99, 0x58}; |
| 314 | return updateMsg; |
| 315 | case 9: |
| 316 | /** |
| 317 | * Node NLRI with same MpReach and MpUnReach. |
| 318 | */ |
| 319 | updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 320 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 321 | (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x7D, 0x02, 0x00, 0x00, //withdrawn len |
| 322 | 0x00, 0x66, 0x04, 0x01, 0x01, 0x02, //origin |
| 323 | 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path |
| 324 | (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med |
| 325 | (byte) 0x80, 0x0e, 0x2A, 0x40, 0x04, 0x47, //mpreach with safi = 71 |
| 326 | 0x04, 0x04, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x1D, //type n len |
| 327 | 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 328 | 0x01, 0x00, 0x00, 0x10, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x09, (byte) 0xae, |
| 329 | 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, //BGPLSIdentifierTlv |
| 330 | (byte) 0x80, 0x0f, 0x24, 0x40, 0x04, 0x47, //mpUnreach with safi = 71 |
| 331 | 0x00, 0x01, 0x00, 0x1D, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 332 | 0x01, 0x00, 0x00, 0x10, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x09, (byte) 0xae, |
| 333 | 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, //BGPLSIdentifierTlv |
| 334 | }; |
| 335 | return updateMsg; |
| 336 | case 10: |
| 337 | /** |
| 338 | * Node NLRI with different MpReach and MpUnReach. |
| 339 | */ |
| 340 | updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 341 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 342 | (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x7D, 0x02, 0x00, 0x00, //withdrawn len |
| 343 | 0x00, 0x66, 0x04, 0x01, 0x01, 0x02, //origin |
| 344 | 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path |
| 345 | (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med |
| 346 | (byte) 0x80, 0x0e, 0x2A, 0x40, 0x04, 0x47, //mpreach with safi = 71 |
| 347 | 0x04, 0x04, 0x00, 0x00, 0x01, 0x00, //reserved |
| 348 | 0x00, 0x01, 0x00, 0x1D, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 349 | 0x01, 0x00, 0x00, 0x10, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x09, (byte) 0xae, |
| 350 | 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, //BGPLSIdentifierTlv |
| 351 | (byte) 0x80, 0x0f, 0x24, 0x40, 0x04, 0x47, //mpUnreach with safi = 71 |
| 352 | 0x00, 0x01, 0x00, 0x1D, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 353 | 0x01, 0x00, 0x00, 0x10, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, |
| 354 | 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, //BGPLSIdentifierTlv |
| 355 | }; |
| 356 | return updateMsg; |
| 357 | case 12: |
| 358 | /** |
| 359 | * Node NLRI with same MpReach and MpUnReach with IsIsPseudonode. |
| 360 | */ |
| 361 | updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 362 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
| 363 | (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x91, 0x02, 0x00, 0x00, //withdrawn len |
| 364 | 0x00, 0x7A, 0x04, 0x01, 0x01, 0x02, //origin |
| 365 | 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path |
| 366 | (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med |
| 367 | (byte) 0x80, 0x0e, 0x34, 0x40, 0x04, 0x47, //mpreach with safi = 71 |
| 368 | 0x04, 0x04, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x27, //type n len |
| 369 | 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 370 | 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x09, (byte) 0xae, |
| 371 | 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, //BGPLSIdentifierTlv |
| 372 | 0x02, 0x03, 0x00, 0x06, 0x19, 0x00, (byte) 0x99, 0x01, (byte) 0x99, 0x58, |
| 373 | (byte) 0x80, 0x0f, 0x2E, 0x40, 0x04, 0x47, //mpUnreach with safi = 71 |
| 374 | 0x00, 0x01, 0x00, 0x27, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 375 | 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x09, (byte) 0xae, //AutonomousSystemTlv |
| 376 | 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, //BGPLSIdentifierTlv |
| 377 | 0x02, 0x03, 0x00, 0x06, 0x19, 0x00, (byte) 0x99, 0x01, (byte) 0x99, 0x58}; |
| 378 | return updateMsg; |
| 379 | default: return null; |
| 380 | } |
| 381 | } |
| 382 | |
Vidyashree Rama | 7bd3d78 | 2015-11-23 08:46:33 +0530 | [diff] [blame] | 383 | @Override |
| 384 | public void channelConnected(ChannelHandlerContext ctx, |
| 385 | ChannelStateEvent channelEvent) throws InterruptedException { |
| 386 | this.savedCtx = ctx; |
| 387 | |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 388 | BgpOpenMsgVer4 openMsg = new BgpOpenMsgVer4(DEFAULT_OPEN_HEADER, |
Vidyashree Rama | 7bd3d78 | 2015-11-23 08:46:33 +0530 | [diff] [blame] | 389 | this.version, |
| 390 | this.asNumber, |
| 391 | this.holdTime, |
| 392 | this.bgpId, |
| 393 | this.capabilityTlv); |
| 394 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 395 | openMsg.writeTo(buffer); |
| 396 | ctx.getChannel().write(buffer); |
| 397 | |
| 398 | TimeUnit.MILLISECONDS.sleep(100); |
| 399 | |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 400 | BgpKeepaliveMsgVer4 keepaliveMsg = new BgpKeepaliveMsgVer4(); |
Vidyashree Rama | 7bd3d78 | 2015-11-23 08:46:33 +0530 | [diff] [blame] | 401 | ChannelBuffer buffer1 = ChannelBuffers.dynamicBuffer(); |
| 402 | keepaliveMsg.writeTo(buffer1); |
| 403 | ctx.getChannel().write(buffer1); |
Priyanka B | 249027e | 2015-12-14 12:42:41 +0530 | [diff] [blame] | 404 | |
| 405 | if (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getAddress().equals( |
| 406 | new InetSocketAddress("127.0.0.1", 0).getAddress())) { |
| 407 | return; |
| 408 | } else if (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getAddress().equals( |
| 409 | new InetSocketAddress("127.0.0.9", 0).getAddress())) { |
| 410 | ChannelBuffer bufferUp = ChannelBuffers.dynamicBuffer(); |
| 411 | bufferUp.writeBytes(selectUpdateMsg(1)); |
| 412 | ctx.getChannel().write(bufferUp); |
| 413 | } else if (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getAddress().equals( |
| 414 | new InetSocketAddress("127.0.0.33", 0).getAddress())) { |
| 415 | ChannelBuffer bufferUp = ChannelBuffers.dynamicBuffer(); |
| 416 | bufferUp.writeBytes(selectUpdateMsg(2)); |
| 417 | ctx.getChannel().write(bufferUp); |
| 418 | } else if (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getAddress().equals( |
| 419 | new InetSocketAddress("127.0.0.10", 0).getAddress())) { |
| 420 | ChannelBuffer bufferUp = ChannelBuffers.dynamicBuffer(); |
| 421 | bufferUp.writeBytes(selectUpdateMsg(3)); |
| 422 | ctx.getChannel().write(bufferUp); |
| 423 | } else if (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getAddress().equals( |
| 424 | new InetSocketAddress("127.0.0.20", 0).getAddress())) { |
| 425 | |
| 426 | ChannelBuffer bufferUp = ChannelBuffers.dynamicBuffer(); |
| 427 | bufferUp.writeBytes(selectUpdateMsg(4)); |
| 428 | ctx.getChannel().write(bufferUp); |
| 429 | } else if (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getAddress().equals( |
| 430 | new InetSocketAddress("127.0.0.30", 0).getAddress())) { |
| 431 | |
| 432 | ChannelBuffer bufferUp = ChannelBuffers.dynamicBuffer(); |
| 433 | bufferUp.writeBytes(selectUpdateMessageVpn(5)); |
| 434 | ctx.getChannel().write(bufferUp); |
| 435 | } else if (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getAddress().equals( |
| 436 | new InetSocketAddress("127.0.0.40", 0).getAddress())) { |
| 437 | |
| 438 | ChannelBuffer bufferUp = ChannelBuffers.dynamicBuffer(); |
| 439 | bufferUp.writeBytes(selectUpdateMessageVpn(6)); |
| 440 | ctx.getChannel().write(bufferUp); |
| 441 | } else if (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getAddress().equals( |
| 442 | new InetSocketAddress("127.0.0.50", 0).getAddress())) { |
| 443 | |
| 444 | ChannelBuffer bufferUp = ChannelBuffers.dynamicBuffer(); |
| 445 | bufferUp.writeBytes(selectUpdateMessageVpn(7)); |
| 446 | ctx.getChannel().write(bufferUp); |
| 447 | } else if (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getAddress().equals( |
| 448 | new InetSocketAddress("127.0.0.60", 0).getAddress())) { |
| 449 | |
| 450 | ChannelBuffer bufferUp = ChannelBuffers.dynamicBuffer(); |
| 451 | bufferUp.writeBytes(selectUpdateMsg(8)); |
| 452 | ctx.getChannel().write(bufferUp); |
| 453 | } else if (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getAddress().equals( |
| 454 | new InetSocketAddress("127.0.0.70", 0).getAddress())) { |
| 455 | |
| 456 | ChannelBuffer bufferUp = ChannelBuffers.dynamicBuffer(); |
| 457 | bufferUp.writeBytes(selectUpdateMsg(9)); |
| 458 | ctx.getChannel().write(bufferUp); |
| 459 | } else if (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getAddress().equals( |
| 460 | new InetSocketAddress("127.0.0.80", 0).getAddress())) { |
| 461 | |
| 462 | ChannelBuffer bufferUp = ChannelBuffers.dynamicBuffer(); |
| 463 | bufferUp.writeBytes(selectUpdateMsg(10)); |
| 464 | ctx.getChannel().write(bufferUp); |
| 465 | } else if (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getAddress().equals( |
| 466 | new InetSocketAddress("127.0.0.90", 0).getAddress())) { |
| 467 | |
| 468 | ChannelBuffer bufferUp = ChannelBuffers.dynamicBuffer(); |
| 469 | bufferUp.writeBytes(selectUpdateMsg(8)); |
| 470 | ctx.getChannel().write(bufferUp); |
| 471 | } else if (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getAddress().equals( |
| 472 | new InetSocketAddress("127.0.0.92", 0).getAddress())) { |
| 473 | |
| 474 | ChannelBuffer bufferUp = ChannelBuffers.dynamicBuffer(); |
| 475 | bufferUp.writeBytes(selectUpdateMsg(12)); |
| 476 | ctx.getChannel().write(bufferUp); |
| 477 | } else if (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getAddress().equals( |
| 478 | new InetSocketAddress("127.0.0.91", 0).getAddress())) { |
| 479 | |
| 480 | ChannelBuffer bufferUp = ChannelBuffers.dynamicBuffer(); |
| 481 | bufferUp.writeBytes(selectUpdateMsg(1)); |
| 482 | ctx.getChannel().write(bufferUp); |
| 483 | } else if (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getAddress().equals( |
| 484 | new InetSocketAddress("127.0.0.9", 0).getAddress())) { |
| 485 | |
| 486 | ChannelBuffer bufferUp = ChannelBuffers.dynamicBuffer(); |
| 487 | bufferUp.writeBytes(selectUpdateMsg(1)); |
| 488 | ctx.getChannel().write(bufferUp); |
| 489 | } else if (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getAddress().equals( |
| 490 | new InetSocketAddress("127.0.0.99", 0).getAddress())) { |
| 491 | |
| 492 | ChannelBuffer bufferUp = ChannelBuffers.dynamicBuffer(); |
| 493 | bufferUp.writeBytes(selectUpdateMsg(1)); |
| 494 | ctx.getChannel().write(bufferUp); |
| 495 | } else if (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getAddress().equals( |
| 496 | new InetSocketAddress("127.0.0.94", 0).getAddress())) { |
| 497 | |
| 498 | ChannelBuffer bufferUp = ChannelBuffers.dynamicBuffer(); |
| 499 | bufferUp.writeBytes(selectUpdateMsg(1)); |
| 500 | ctx.getChannel().write(bufferUp); |
| 501 | } else if (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getAddress().equals( |
| 502 | new InetSocketAddress("127.0.0.35", 0).getAddress())) { |
| 503 | |
| 504 | ChannelBuffer bufferUp = ChannelBuffers.dynamicBuffer(); |
| 505 | bufferUp.writeBytes(selectUpdateMessageVpn(17)); |
| 506 | ctx.getChannel().write(bufferUp); |
| 507 | } else if (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getAddress().equals( |
| 508 | new InetSocketAddress("127.0.0.95", 0).getAddress())) { |
| 509 | |
| 510 | ChannelBuffer bufferUp = ChannelBuffers.dynamicBuffer(); |
| 511 | bufferUp.writeBytes(selectUpdateMsg(1)); |
| 512 | ctx.getChannel().write(bufferUp); |
| 513 | } |
Vidyashree Rama | 7bd3d78 | 2015-11-23 08:46:33 +0530 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | @Override |
| 517 | public void channelDisconnected(ChannelHandlerContext ctx, |
| 518 | ChannelStateEvent channelEvent) { |
| 519 | //Do Nothing |
| 520 | } |
| 521 | } |