Beispiel #1
0
        public MNode(INode node, ForwardDelegate forwardMethod, String defaultAlgorithm, IAlgorithm[] algorithms, IKeyTableFactory tableFactory)
            : base(node)
        {
            _passDownMethod = forwardMethod;
            _tableFactory   = tableFactory;
            _links          = tableFactory.MakeKeyTable <IMLink>();
            _neighbours     = tableFactory.MakeKeyTable <IMNodeInternal>();
            _algorithms     = new Dictionary <string, IAlgorithmNode>();

            foreach (IAlgorithm alg in algorithms)
            {
                IAlgorithmNode algNode = alg.MakeNode(this, SendPacket);
                _algorithms.Add(alg.Name, algNode);
                algNode.OnRouteChange     += RouteChangeListener;
                algNode.IsCurrentAlgorithm = alg.Name.Equals(defaultAlgorithm);
                if (algNode.IsCurrentAlgorithm)
                {
                    _currentAlgorithm = algNode;
                }
            }
            if (_currentAlgorithm == null)
            {
                throw new Exception("Test Node unable to set algorithm. '" + defaultAlgorithm + "' is not a valid algorithm.");
            }
            _currentAlgorithmName = defaultAlgorithm;

            _passDownMethod = forwardMethod;

            OnPacketReceived += (at, p) => {
                IMPacket packet = p as IMPacket;
                if (packet != null && packet.Type == PTypes.data)
                {
                    ReceiveData(packet);
                }
                else if (packet != null && _algorithms.ContainsKey(packet.Algorithm))
                {
                    _algorithms[packet.Algorithm].ProcessPacket(packet);
                }
            };
            _weightDelegate = (id, newWeight) => {
                if (OnWeightChange != null)
                {
                    OnWeightChange(id, newWeight);
                    Logger.Debug(Name + " triggered OnWeightChange for '" + Links[id].Name + "'.");
                }
            };
            _highlightDelegate = () => ResetHighlightAll();
            OnHighlightReset  += _highlightDelegate;
        }
Beispiel #2
0
        public MNode(INode node, ForwardDelegate forwardMethod, String defaultAlgorithm, IAlgorithm[]algorithms, IKeyTableFactory tableFactory)
            : base(node)
        {
            _passDownMethod = forwardMethod;
            _tableFactory = tableFactory;
            _links = tableFactory.MakeKeyTable<IMLink>();
            _neighbours = tableFactory.MakeKeyTable<IMNodeInternal>();
            _algorithms = new Dictionary<string, IAlgorithmNode>();

            foreach (IAlgorithm alg in algorithms) {
                IAlgorithmNode algNode = alg.MakeNode(this, SendPacket);
                _algorithms.Add(alg.Name, algNode);
                algNode.OnRouteChange += RouteChangeListener;
                algNode.IsCurrentAlgorithm = alg.Name.Equals(defaultAlgorithm);
                if (algNode.IsCurrentAlgorithm)
                    _currentAlgorithm = algNode;
            }
            if (_currentAlgorithm == null)
                throw new Exception("Test Node unable to set algorithm. '" + defaultAlgorithm + "' is not a valid algorithm.");
            _currentAlgorithmName = defaultAlgorithm;

            _passDownMethod = forwardMethod;

            OnPacketReceived += (at, p) => {
                IMPacket packet = p as IMPacket;
                if (packet != null && packet.Type == PTypes.data)
                    ReceiveData(packet);
                else if (packet != null && _algorithms.ContainsKey(packet.Algorithm))
                    _algorithms[packet.Algorithm].ProcessPacket(packet);
            };
            _weightDelegate = (id, newWeight) => {
                if (OnWeightChange != null) {
                    OnWeightChange(id, newWeight);
                    Logger.Debug(Name + " triggered OnWeightChange for '" + Links[id].Name + "'.");
                }
            };
            _highlightDelegate = () => ResetHighlightAll();
            OnHighlightReset += _highlightDelegate;
        }