BgpOpenMessage DecodeBgpOpenMessage(Tlv tlv)
        {
            using (var dataStream = new MemoryStream(tlv.Data))
            {
                var version      = ReadNumber(dataStream, 1);
                var asNum        = ReadNumber(dataStream, 2);
                var holdTime     = ReadNumber(dataStream, 2);
                var identifier   = ReadNumber(dataStream, 4);
                var capabilities = ParseCapabilities(dataStream);

                return(new BgpOpenMessage(version, asNum, holdTime, identifier, capabilities));
            }
        }
        public IBgpMessage Decode(Tlv tlv)
        {
            switch (tlv.Type)
            {
            case 1:
                return(DecodeBgpOpenMessage(tlv));

            case 2:
                return(DecodeBgpUpdateMessage(tlv));

            case 3:
                return(new BgpKeepaliveMessage());

            case 4:
                return(DecodeBgpNotificationMessage(tlv));
            }
            throw new Exception("Could not decode message with type " + tlv.Type);
        }
Exemple #3
0
 public void Visit(BgpNotificationMessage notificationMessage)
 {
     tlv = new Tlv(4, notificationMessage.data);
 }
Exemple #4
0
 public void Visit(BgpKeepaliveMessage keepaliveMessage)
 {
     tlv = new Tlv(3, new byte[] { });
 }
Exemple #5
0
        public void Visit(BgpUpdateMessage updateMessage)
        {
            var data = EncodePrefixes(updateMessage.prefixes);

            tlv = new Tlv(2, data.ToArray());
        }
Exemple #6
0
 public void Encode(Stream stream, Tlv tlv)
 {
     WriteType(stream, tlv.Type);
     WriteData(stream, tlv.Data);
 }
 BgpNotificationMessage DecodeBgpNotificationMessage(Tlv tlv)
 {
     return(new BgpNotificationMessage(tlv.Data));
 }