Example #1
0
        public ClusterNic(AmClusterNetInterface clusNic, ClusterNetwork owningClusNet)
        {
            this.Name           = clusNic.Name;
            this.ClusterNetwork = owningClusNet;
            this.NodeName       = clusNic.GetNodeName();
            this.ClusterState   = clusNic.GetState(false);
            bool      flag      = false;
            string    address   = clusNic.GetAddress();
            IPAddress ipaddress = NetworkUtil.ConvertStringToIpAddress(address);

            if (ipaddress != null)
            {
                flag = true;
            }
            else
            {
                NetworkManager.TraceError("Ignoring invalid IPV4 address on NIC {0} since it has invalid ip={1}", new object[]
                {
                    this.Name,
                    address
                });
                string[] ipv6Addresses = clusNic.GetIPv6Addresses();
                if (ipv6Addresses != null && ipv6Addresses.Length > 0)
                {
                    ipaddress = NetworkUtil.ConvertStringToIpAddress(ipv6Addresses[0]);
                    if (ipaddress != null)
                    {
                        flag = true;
                    }
                }
            }
            if (flag)
            {
                this.IPAddress    = ipaddress;
                this.HasIPAddress = true;
                return;
            }
            NetworkManager.TraceError("ClusterNic '{0}' has no ip addr. Nic state is {1}", new object[]
            {
                this.Name,
                this.ClusterState
            });
        }
Example #2
0
        private void LoadMap(DagNetConfig cfg)
        {
            this.netConfig = cfg;
            Dictionary <string, DagNetChooser.OutboundNetInfo> dictionary = new Dictionary <string, DagNetChooser.OutboundNetInfo>(cfg.Networks.Count);

            foreach (DagNetwork dagNetwork in cfg.Networks)
            {
                if (dagNetwork.ReplicationEnabled)
                {
                    DagNetChooser.OutboundNetInfo outboundNetInfo = new DagNetChooser.OutboundNetInfo();
                    outboundNetInfo.Network = dagNetwork;
                    dictionary.Add(dagNetwork.Name, outboundNetInfo);
                }
            }
            foreach (DagNode dagNode in cfg.Nodes)
            {
                foreach (DagNode.Nic nic in dagNode.Nics)
                {
                    IPAddress ipaddress = NetworkUtil.ConvertStringToIpAddress(nic.IpAddress);
                    DagNetChooser.OutboundNetInfo outboundNetInfo2;
                    if (ipaddress != null && dictionary.TryGetValue(nic.NetworkName, out outboundNetInfo2))
                    {
                        if (MachineName.IsEffectivelyLocalComputerName(dagNode.Name))
                        {
                            outboundNetInfo2.SourceIPAddr = ipaddress;
                        }
                        else
                        {
                            if (outboundNetInfo2.Targets == null)
                            {
                                outboundNetInfo2.Targets = new Dictionary <string, DagNetChooser.OutboundNetInfo.TargetNicInfo>(cfg.Nodes.Count, MachineName.Comparer);
                            }
                            DagNetChooser.OutboundNetInfo.TargetNicInfo targetNicInfo;
                            if (outboundNetInfo2.Targets.TryGetValue(dagNode.Name, out targetNicInfo))
                            {
                                DagNetChooser.Tracer.TraceError((long)this.GetHashCode(), "LoadMap found dup ipAddr for node {0} on net {1} ip1 {2} ip2 {3}", new object[]
                                {
                                    dagNode.Name,
                                    nic.NetworkName,
                                    targetNicInfo.IPAddr,
                                    nic.IpAddress
                                });
                            }
                            else
                            {
                                targetNicInfo               = new DagNetChooser.OutboundNetInfo.TargetNicInfo();
                                targetNicInfo.IPAddr        = ipaddress;
                                targetNicInfo.IsCrossSubnet = true;
                                targetNicInfo.TargetPort    = this.netConfig.ReplicationPort;
                                if (dagNode.ReplicationPort != 0)
                                {
                                    targetNicInfo.TargetPort = dagNode.ReplicationPort;
                                }
                                outboundNetInfo2.Targets.Add(dagNode.Name, targetNicInfo);
                            }
                        }
                    }
                }
            }
            List <DagNetChooser.OutboundNetInfo> list = new List <DagNetChooser.OutboundNetInfo>(cfg.Networks.Count);
            int num = 0;

            foreach (DagNetChooser.OutboundNetInfo outboundNetInfo3 in dictionary.Values)
            {
                if (outboundNetInfo3.SourceIPAddr != null && outboundNetInfo3.Targets != null)
                {
                    if (outboundNetInfo3.Network.IsDnsMapped)
                    {
                        list.Add(outboundNetInfo3);
                    }
                    else
                    {
                        list.Insert(0, outboundNetInfo3);
                        num++;
                    }
                }
            }
            this.roundRobinIndex = 0;
            this.outboundNets    = list.ToArray();
            if (num > 0)
            {
                this.roundRobinLimit = num;
                return;
            }
            this.roundRobinLimit = this.outboundNets.Length;
        }
        public void RefreshMapiNetwork()
        {
            Exception ex = null;

            try
            {
                Dictionary <AmServerName, AmNetworkMonitor.Node> dictionary  = new Dictionary <AmServerName, AmNetworkMonitor.Node>();
                Dictionary <string, AmNetworkMonitor.Nic>        dictionary2 = new Dictionary <string, AmNetworkMonitor.Nic>();
                using (IAmCluster amCluster = ClusterFactory.Instance.Open())
                {
                    lock (this)
                    {
                        ExTraceGlobals.AmNetworkMonitorTracer.TraceDebug((long)this.GetHashCode(), "RefreshMapiNetwork running");
                        foreach (IAmClusterNode amClusterNode in amCluster.EnumerateNodes())
                        {
                            using (amClusterNode)
                            {
                                AmNetworkMonitor.Node node = new AmNetworkMonitor.Node(amClusterNode.Name);
                                dictionary.Add(node.Name, node);
                                IPAddress[] dnsAddresses = NetworkUtil.GetDnsAddresses(amClusterNode.Name.Fqdn, ref ex);
                                foreach (AmClusterNetInterface amClusterNetInterface in amClusterNode.EnumerateNetInterfaces())
                                {
                                    using (amClusterNetInterface)
                                    {
                                        bool      flag2     = false;
                                        IPAddress ipaddress = NetworkUtil.ConvertStringToIpAddress(amClusterNetInterface.GetAddress());
                                        if (ipaddress != null && NetworkUtil.IsAddressPresent(dnsAddresses, ipaddress))
                                        {
                                            flag2 = true;
                                            AmNetworkMonitor.Tracer.TraceDebug <string, IPAddress>((long)this.GetHashCode(), "NIC '{0}' on DNS at {1}", amClusterNetInterface.Name, ipaddress);
                                        }
                                        if (!flag2)
                                        {
                                            string[] ipv6Addresses = amClusterNetInterface.GetIPv6Addresses();
                                            if (ipv6Addresses != null && ipv6Addresses.Length > 0)
                                            {
                                                foreach (string text in ipv6Addresses)
                                                {
                                                    ipaddress = NetworkUtil.ConvertStringToIpAddress(text);
                                                    if (ipaddress != null && NetworkUtil.IsAddressPresent(dnsAddresses, ipaddress))
                                                    {
                                                        flag2 = true;
                                                        AmNetworkMonitor.Tracer.TraceDebug <string, string>((long)this.GetHashCode(), "NIC '{0}' on DNS at {1}", amClusterNetInterface.Name, text);
                                                        break;
                                                    }
                                                }
                                            }
                                        }
                                        if (flag2)
                                        {
                                            AmNetworkMonitor.Nic nic = new AmNetworkMonitor.Nic(amClusterNetInterface.Name, node);
                                            node.MapiNics.Add(nic);
                                            dictionary2.Add(nic.Name, nic);
                                        }
                                    }
                                }
                            }
                        }
                        this.m_nodeTable = dictionary;
                        this.m_nicTable  = dictionary2;
                    }
                }
            }
            catch (ClusterException ex2)
            {
                ex = ex2;
            }
            finally
            {
                this.m_firstRefreshCompleted.Set();
                this.m_firstRefreshCompleted.Close();
            }
            if (ex != null)
            {
                AmNetworkMonitor.Tracer.TraceError <Exception>(0L, "RefreshMapiNetwork fails:{0}", ex);
            }
        }