Пример #1
0
        public async void Update(Link.Link Link)
        {
            while (this.locked)
            {
                await Task.Delay(1);
            }

            this.locked = true;

            Link.Link existingLink = Links.Find(l => l.SourceNode == Link.SourceNode && l.TargetNode == Link.TargetNode); // && l.IPv4InterfaceAddress == Link.IPv4InterfaceAddress);

            if (existingLink == null && Link.OperationalStatus)
            {
                Links.Add(Link);

                this.OnLinkUpCallback?.Invoke(Link);
            }
            else
            {
                if (Link.OperationalStatus)
                {
                    Links[Links.IndexOf(existingLink)] = Link;
                }
                else
                {
                    Links.Remove(existingLink);

                    this.OnLinkDownCallback?.Invoke(Link);
                }
            }

            this.OnLinkUpdateCallback?.Invoke(Link);

            this.locked = false;
        }
Пример #2
0
        private void ProcessExaBgpBgpLsMessage(JObject data)
        {
            if ((string)data["type"] == "update")
            {
                var withdraw = data["neighbor"]["message"]["update"]["withdraw"];
                if (withdraw != null)
                {
                    foreach (var item in withdraw["bgp-ls bgp-ls"])
                    {
                        switch ((int)item["ls-nlri-type"])
                        {
                        case 1:

                            string psn = (string)item["node-descriptors"]["psn"];
                            string igp_router_identifier = (string)item["node-descriptors"]["router-id"] + psn;


                            Node.Node n = new Node.Node()
                            {
                                IgpRouterIdentifier = igp_router_identifier,
                                OperationalStatus   = false,
                                IsPseudonode        = !string.IsNullOrWhiteSpace(psn)
                            };

                            this.Update(n);

                            break;

                        case 2:
                            string local_node_id  = (string)item["local-node-descriptors"]["router-id"] + (string)item["local-node-descriptors"]["psn"];
                            string remote_node_id = (string)item["remote-node-descriptors"]["router-id"] + (string)item["remote-node-descriptors"]["psn"];

                            Link.Link l = new Link.Link()
                            {
                                SourceNode        = local_node_id,
                                TargetNode        = remote_node_id,
                                OperationalStatus = false
                            };

                            this.Update(l);

                            break;

                        default:
                            break;
                        }
                    }
                }

                var announce = data["neighbor"]["message"]["update"]["announce"];
                if (announce != null)
                {
                    foreach (var item in announce["bgp-ls bgp-ls"].First.Children())
                    {
                        var attribute = data["neighbor"]["message"]["update"]["attribute"];

                        foreach (var subitem in item.Children())
                        {
                            switch ((int)subitem["ls-nlri-type"])
                            {
                            case 1:

                                string psn = (string)subitem["node-descriptors"]["psn"];
                                string igp_router_identifier = (string)subitem["node-descriptors"]["router-id"] + psn;

                                Node.Node n = new Node.Node()
                                {
                                    IgpRouterIdentifier = igp_router_identifier,
                                    OperationalStatus   = true,
                                    IsPseudonode        = !string.IsNullOrWhiteSpace(psn)
                                };

                                if (attribute != null && attribute["bgp-ls"] != null)
                                {
                                    n.NodeName             = (string)attribute["bgp-ls"]["node-name"];
                                    n.IPv4RouterIdentifier = (string)attribute["bgp-ls"]["local-te-router-id"];
                                }

                                int psn_number = 0;
                                int.TryParse(psn, out psn_number);
                                n.Psn = psn_number;

                                if (n.IsPseudonode)
                                {
                                    n.NodeCost = 0;
                                }
                                else
                                {
                                    n.NodeCost = 1;
                                }

                                this.Update(n);

                                break;

                            case 2:
                                string local_node_id     = (string)subitem["local-node-descriptors"]["router-id"] + (string)subitem["local-node-descriptors"]["psn"];
                                string remote_node_id    = (string)subitem["remote-node-descriptors"]["router-id"] + (string)subitem["remote-node-descriptors"]["psn"];
                                string interface_address = (string)subitem["interface-address"]["interface-address"];

                                if (!string.IsNullOrWhiteSpace(interface_address))
                                {
                                    Link.Link l = new Link.Link()
                                    {
                                        SourceNode           = local_node_id,
                                        TargetNode           = remote_node_id,
                                        IPv4InterfaceAddress = interface_address,
                                        OperationalStatus    = true,
                                        Rtt = long.MaxValue
                                    };

                                    if (attribute != null && attribute["bgp-ls"] != null)
                                    {
                                        l.MaximumLinkBandwidth           = (double?)attribute["bgp-ls"]["maximum-link-bandwidth"];
                                        l.MaximumReservableLinkBandwidth = (double?)attribute["bgp-ls"]["maximum-reservable-link-bandwidth"];
                                        l.UnreservedBandwidth            = attribute["bgp-ls"]["unreserved-bandwidth"]?.Values <double>().ToArray();
                                        l.SharedRiskLinkGroups           = attribute["bgp-ls"]["shared-risk-link-groups"]?.Values <long>().ToArray();
                                    }

                                    if (Regex.IsMatch(l.SourceNode, @"^\d{12}\d+$") || Regex.IsMatch(l.TargetNode, @"^\d{12}\d+$"))
                                    {
                                        l.LinkCost = 0.5;
                                    }
                                    else
                                    {
                                        l.LinkCost = 1;
                                    }

                                    this.Update(l);
                                }

                                break;

                            default:
                                break;
                            }
                        }
                    }
                }
            }
        }