public override void Decode(byte[] data, int offset) { if ((PeerHeader.Flags & (1 << 7)) != 0) { var ipBytes = new byte[16]; Array.Copy(data, offset, ipBytes, 0, 4); LocalAddress = new IPAddress(ipBytes); } else { var ipBytes = new byte[4]; Array.Copy(data, offset + 12, ipBytes, 0, 4); LocalAddress = new IPAddress(ipBytes); } offset += 16; LocalPort = EndianBitConverter.Big.ToUInt16(data, offset); offset += 2; RemotePort = EndianBitConverter.Big.ToUInt16(data, offset); offset += 2; SentOpenMessage = BgpMessage.Create(data, offset) as BgpOpenMessage; offset += SentOpenMessage?.Header.Length ?? 0; ReceivedOpenMessage = BgpMessage.Create(data, offset) as BgpOpenMessage; }
public void BgpOpenDecodes(string value) { var data = Convert.FromBase64String(value); var msg = new BgpOpenMessage(); msg.Decode(data, 0); Assert.Equal(msg.MyAS, 23456); Assert.Equal(msg.Version, 4); Assert.Equal(msg.HoldTime, 90); }
public static BgpMessage Create(byte[] data, int offset) { var bgpHeaderLength = 19; var msgHeader = new BgpHeader(data, offset); BgpMessage msg; switch (msgHeader.Type) { case BgpMessageType.Open: msg = new BgpOpenMessage(); break; case BgpMessageType.Update: msg = new BgpUpdateMessage(); break; case BgpMessageType.Notification: msg = new BgpNotificationMessage(); break; case BgpMessageType.Keepalive: msg = new BgpKeepAliveMessage(); break; case BgpMessageType.RouteRefresh: msg = new BgpRouteRefreshMessage(); break; default: return(null); } msg.Header = msgHeader; offset += bgpHeaderLength; msg.Decode(data, offset); return(msg); }