Example #1
0
        /// <summary>
        /// Adds the connection.
        /// </summary>
        /// <param name="from">From parameter.</param>
        /// <param name="to">To parameter.</param>
        /// <param name="metric">The metric.</param>
        /// <returns>true if the connection was created; otherwise false.</returns>
        public bool AddConnection(string from, string to, int metric)
        {
            NetSimClient fromClient = this.Clients.FirstOrDefault(c => c.Id.Equals(from));
            NetSimClient toClient   = this.Clients.FirstOrDefault(c => c.Id.Equals(to));

            if (fromClient == null || toClient == null)
            {
                return(false);
            }

            NetSimConnection connection = new NetSimConnection()
            {
                EndPointA = fromClient,
                EndPointB = toClient,
                Id        = $"{from} - {to}",
                Metric    = metric
            };

            if (fromClient.Connections.ContainsKey(to) || toClient.Connections.ContainsKey(from))
            {
                return(false);
            }

            // forward updates
            connection.StateUpdated += this.OnUpdated;

            this.Connections.Add(connection);
            fromClient.Connections.Add(to, connection);
            toClient.Connections.Add(from, connection);

            this.OnUpdated();

            return(true);
        }
Example #2
0
        /// <summary>
        /// Removes the connection.
        /// EndPointA and B can be switched!
        /// </summary>
        /// <param name="endPointA">The end point a.</param>
        /// <param name="endPointB">The end point b.</param>
        /// <returns>true if the connection was removed; otherwise false.</returns>
        public bool RemoveConnection(string endPointA, string endPointB)
        {
            NetSimClient endPointAClient = this.Clients.FirstOrDefault(c => c.Id.Equals(endPointA));
            NetSimClient endPointBClient = this.Clients.FirstOrDefault(c => c.Id.Equals(endPointB));

            if (endPointAClient == null || endPointBClient == null)
            {
                return(false);
            }

            var delConnection =
                this.Connections.FirstOrDefault(
                    c => c.EndPointA.Id.Equals(endPointA) && c.EndPointB.Id.Equals(endPointB))
                ?? this.Connections.FirstOrDefault(
                    c => c.EndPointA.Id.Equals(endPointB) && c.EndPointB.Id.Equals(endPointA));

            if (delConnection == null)
            {
                return(false);
            }

            endPointAClient.Connections.Remove(endPointB);
            endPointBClient.Connections.Remove(endPointA);
            this.Connections.Remove(delConnection);

            return(true);
        }
Example #3
0
        /// <summary>
        /// Creates the client node.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <returns>The created element for the dsr node.</returns>
        private UIElement CreateDsrClientNode(NetSimClient node)
        {
            if (this.CurrentSelectedItem != null && node.Id.Equals(this.CurrentSelectedItem.Id))
            {
                return(this.CreateClientNode(node, Brushes.LightSalmon));
            }

            return(this.CreateClientNode(node, Brushes.OrangeRed));
        }
Example #4
0
        /// <summary>
        /// Creates the client node.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <returns>The created element for the dsdv node.</returns>
        private UIElement CreateDsdvClientNode(NetSimClient node)
        {
            if (this.CurrentSelectedItem != null && node.Id.Equals(this.CurrentSelectedItem.Id))
            {
                return(this.CreateClientNode(node, Brushes.DarkSeaGreen));
            }

            return(this.CreateClientNode(node, Brushes.YellowGreen));
        }
Example #5
0
        /// <summary>
        /// Creates the client node.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <returns>The create element.</returns>
        private UIElement CreateAodvClientNode(NetSimClient node)
        {
            if (this.CurrentSelectedItem != null && node.Id.Equals(this.CurrentSelectedItem.Id))
            {
                return(this.CreateClientNode(node, Brushes.LightSkyBlue));
            }

            return(this.CreateClientNode(node, Brushes.CornflowerBlue));
        }
Example #6
0
        /// <summary>
        /// Creates the protocol specific client node.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <returns>The created element for the protocol specific node.</returns>
        private UIElement CreateProtocolSpecificClientNode(NetSimClient node)
        {
            if (node.RoutingProtocol is DsdvRoutingProtocol)
            {
                return(this.CreateDsdvClientNode(node));
            }

            return(null);
        }
Example #7
0
        /// <summary>
        /// Creates the client node.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <param name="color">The color.</param>
        /// <param name="highlightBorder">if set to <c>true</c> highlight the border.</param>
        /// <returns>The create element for the node.</returns>
        private UIElement CreateClientNode(NetSimClient node, Brush color, bool highlightBorder = false)
        {
            var grid = new Grid {
                Tag = node
            };
            var ellipse = new Ellipse
            {
                Width   = 50,
                Height  = 50,
                Stroke  = Brushes.Black,
                Fill    = color,
                Tag     = node,
                ToolTip = node.RoutingProtocol?.Table?.ToString()
            };

            if (node.IsOffline || highlightBorder)
            {
                ellipse.StrokeThickness = 4;

                ellipse.Stroke          = highlightBorder ? Brushes.DarkOrange : Brushes.Red;
                ellipse.StrokeDashArray = new DoubleCollection(new List <double>()
                {
                    2, 2
                });
            }

            var textBlock = new TextBlock
            {
                Text = node.Id,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Center,
                Tag = node
            };

            grid.Children.Add(ellipse);
            grid.Children.Add(textBlock);

            // To Center on click point
            Canvas.SetLeft(grid, node.Location.Left - 25);
            Canvas.SetTop(grid, node.Location.Top - 25);

            return(grid);
        }
Example #8
0
        /// <summary>
        /// Adds the client.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <param name="left">The left.</param>
        /// <param name="top">The top.</param>
        /// <returns>The created client.</returns>
        public NetSimItem AddClient(string id, int left, int top)
        {
            var client = new NetSimClient(id, new NetSimLocation(left, top));

            // add client
            this.Clients.Add(client);

            // forward updates
            client.StateUpdated += this.OnUpdated;

            // if simulator already initialized
            if (this.IsInitialized)
            {
                // then intiailize new clients with same protocol
                client.InitializeProtocol(this.Protocol);
            }

            this.OnUpdated();

            return(client);
        }
Example #9
0
        /// <summary>
        /// Creates the client node.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <returns>The created element for the olsr node.</returns>
        private UIElement CreateOlsrClientNode(NetSimClient node)
        {
            if (this.CurrentSelectedItem != null)
            {
                if (node.Id.Equals(this.CurrentSelectedItem.Id))
                {
                    return(this.CreateClientNode(node, Brushes.Thistle));
                }

                OlsrRoutingProtocol currentSelectedNodeProtocol =
                    this.CurrentSelectedItem.RoutingProtocol as OlsrRoutingProtocol;

                if (currentSelectedNodeProtocol != null)
                {
                    // is mpr neighbor
                    if (currentSelectedNodeProtocol.IsMprNeighbor(node.Id))
                    {
                        return(this.CreateClientNode(node, Brushes.SteelBlue, true));
                    }

                    // is n(1 hop) neigbor
                    if (currentSelectedNodeProtocol.IsOneHopNeighbor(node.Id))
                    {
                        return(this.CreateClientNode(node, Brushes.SteelBlue));
                    }

                    // is n(2 hop) neighbor
                    if (currentSelectedNodeProtocol.IsTwoHopNeighbor(node.Id))
                    {
                        return(this.CreateClientNode(node, Brushes.PowderBlue));
                    }
                }
            }

            return(this.CreateClientNode(node, Brushes.Orchid));
        }
Example #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AodvRoutingProtocol"/> class.
 /// </summary>
 /// <param name="client">The client.</param>
 public AodvRoutingProtocol(NetSimClient client)
     : base(client)
 {
     this.handlerResolver = new MessageHandlerResolver(this.GetType());
 }
Example #11
0
        /// <summary>
        /// Creates the instance.
        /// </summary>
        /// <param name="protocolType">Type of the protocol.</param>
        /// <param name="client">The client.</param>
        /// <returns>The created routing protocol instance.</returns>
        public static NetSimRoutingProtocol CreateInstance(NetSimProtocolType protocolType, NetSimClient client)
        {
            switch (protocolType)
            {
            case NetSimProtocolType.AODV:
                return(new AodvRoutingProtocol(client));

            case NetSimProtocolType.DSDV:
                return(new DsdvRoutingProtocol(client));

            case NetSimProtocolType.DSR:
                return(new DsrRoutingProtocol(client));

            case NetSimProtocolType.OLSR:
                return(new OlsrRoutingProtocol(client));
            }

            return(null);
        }
Example #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ClientViewModel" /> class.
 /// </summary>
 /// <param name="client">The client.</param>
 public ClientViewModel(NetSimClient client)
 {
     this.Client          = client;
     this.SendMessageData = "Data";
     this.InitializeCommands();
 }
Example #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DsdvRoutingProtocol"/> class.
 /// </summary>
 /// <param name="client">The client.</param>
 public DsdvRoutingProtocol(NetSimClient client)
     : base(client)
 {
 }