コード例 #1
0
        private static RouteMonitoringModel ConvertToModel(RouteMonitoring msg)
        {
            var bgpMsg = msg.BgpUpdate;

            if (bgpMsg.Attributes.Count > 4)
            {
            }

            var peerHeaderModel = ConvertToModel(msg.PeerHeader);

            var asPath = bgpMsg.Attributes.FirstOrDefault(x => x.AttributeType == PathAttributeType.AsPath) as PathAttributeASPath;

            var model = new RouteMonitoringModel
            {
                DateTime = msg.PeerHeader.DateTime,
                Peer     = peerHeaderModel,
                Origin   = (PathAttributeOrigin)bgpMsg.Attributes.FirstOrDefault(x => x.AttributeType == PathAttributeType.Origin),
                AsPath   = asPath?.ASPaths[0].ASNs,
            };

            var communities = bgpMsg.Attributes.Where(x => x.AttributeType == PathAttributeType.Community).ToList();

            foreach (var community in communities)
            {
                model.Communities.Add(community.ToString());
            }

            if (bgpMsg.Nlri.Count > 0)
            {
                var nexthop  = bgpMsg.Attributes.FirstOrDefault(x => x.AttributeType == PathAttributeType.NextHop) as PathAttributeNextHop;
                var announce = ConvertToModel(AddressFamily.IP, SubsequentAddressFamily.Unicast, nexthop?.NextHop, bgpMsg.Nlri);
                model.Announce.Add(announce);
            }

            if (bgpMsg.WithdrawnRoutesLength > 0)
            {
                var withdraw = ConvertToModel(AddressFamily.IP, SubsequentAddressFamily.Unicast, bgpMsg.WithdrawnRoutes);
                model.Withdraw.Add(withdraw);
            }

            var mpReach = bgpMsg.Attributes.FirstOrDefault(x => x.AttributeType == PathAttributeType.MpReachNlri) as PathAttributeMPReachNlri;

            if (mpReach?.Nlri.Count > 0)
            {
                var announce = ConvertToModel(mpReach.Afi, mpReach.Safi, mpReach.NextHop, mpReach.Nlri);
                model.Announce.Add(announce);
            }

            var mpUnreach = bgpMsg.Attributes.FirstOrDefault(x => x.AttributeType == PathAttributeType.MpUnreachNlri) as PathAttributeMPUnreachNlri;

            if (mpUnreach?.WithdrawnRoutes.Count > 0)
            {
                var withdraw = ConvertToModel(mpUnreach.Afi, mpUnreach.Safi, mpUnreach.WithdrawnRoutes);
                model.Withdraw.Add(withdraw);
            }

            return(model);
        }
コード例 #2
0
ファイル: BmpMessage.cs プロジェクト: mstrother/BmpListener
        public static BmpMessage Create(byte[] data)
        {
            var commonHeaderLength  = 6;
            var perPeerHeaderLength = 42;

            var        msgHeader = new BmpHeader(data);
            BmpMessage msg;

            switch (msgHeader.MessageType)
            {
            case BmpMessageType.Initiation:
                msg = new BmpInitiation();
                break;

            case BmpMessageType.RouteMonitoring:
                msg = new RouteMonitoring();
                break;

            case BmpMessageType.StatisticsReport:
                msg = new StatisticsReport();
                break;

            case BmpMessageType.PeerDown:
                msg = new PeerDownNotification();
                break;

            case BmpMessageType.PeerUp:
                msg = new PeerUpNotification();
                break;

            case BmpMessageType.Termination:
                msg = new BmpTermination();
                break;

            default:
                return(null);
            }

            msg.BmpHeader = msgHeader;
            var offset = commonHeaderLength;

            if (msgHeader.MessageType != BmpMessageType.Initiation)
            {
                msg.PeerHeader = new PerPeerHeader(data, offset);
                offset        += perPeerHeaderLength;
            }

            msg.Decode(data, offset);
            return(msg);
        }