Пример #1
0
        public ManagedLink GetLink(string addr)
        {
            var lnk = new ManagedLink(addr);

            _ntw.Connect(lnk);

            return lnk;
        }
Пример #2
0
        public void setup()
        {
            _link = new ManagedLink("A");

            ntw = new ManagedSwitch();
            ntw.Connect(_link);

            _node = new Node("A", new List<string>() { "A" }, _link);
        }
Пример #3
0
        public void Connect(ManagedLink l1)
        {
            Links[l1.Host] = l1;

            if (!Deny.ContainsKey(l1.Host))
                Deny[l1.Host] = new List<string>();

            Task.Factory.StartNew(() =>
            {
                while (true)
                {
                    try
                    {
                        foreach (var source in Links)
                        {
                            while (source.Value.Out.Count > 0)
                            {
                                var tm = source.Value.Out.Take();
                                var toLink = Links[tm.To];

                                if (Deny[tm.From].Contains(tm.To))
                                {
                                    _logger.Info("Drop by ipt " + tm.Id);
                                    continue;
                                }

                                if ((PartitionA.Contains(tm.From) && PartitionB.Contains(tm.To)) ||
                                    (PartitionB.Contains(tm.From) && PartitionA.Contains(tm.To)))
                                {
                                    _logger.Info("Drop by prt " + tm.Id);
                                    continue;
                                }

                                toLink.Inject(tm);
                            }
                        }
                    }
                    catch (InvalidOperationException)
                    {
                        
                    }
                    catch (OperationCanceledException)
                    {
                        break;
                    }
                }
            }, 
                CancellationToken.None, 
                TaskCreationOptions.LongRunning, 
                TaskScheduler.Default);

            Thread.Sleep(5);
        }