Beispiel #1
0
        bool thClonePort_HandlerAttached(TrafficHandlerPort sender, TrafficHandlerPort attacher)
        {
            if (sender != ClonePort)
            {
                throw new InvalidOperationException("The Clone Port attach event was signalled by another sender than the Clone Port. This is a serious internal error.");
            }

            TrafficSplitter s = (TrafficSplitter)TrafficHandler;

            if (attacher.ParentHandler is TrafficAnalyzer)
            {
                if (!s.ContainsTrafficAnalyzer((TrafficAnalyzer)attacher.ParentHandler))
                {
                    s.AddTrafficAnalyzer((TrafficAnalyzer)attacher.ParentHandler);

                    return(true);
                }
                else
                {
                    throw new InvalidOperationException("The ports " + sender.Name + " and " + attacher.Name + " are already connected.");
                }
            }
            else
            {
                throw new InvalidOperationException("Only traffic analyzers can connect the " + ClonePort.Name + ".");
            }
        }
        bool thRoutedTrafficAnalyzerPort_HandlerDetached(TrafficHandlerPort sender, TrafficHandlerPort attacher)
        {
            if (sender != thRoutedTrafficAnalyzerPort)
            {
                throw new InvalidOperationException("The Routed Traffic Analyzer Port detach event was signalled by another sender than the Routed Traffic Analyzer Port. This is a serious internal error.");
            }

            Router rt = (Router)TrafficHandler;

            if (attacher.ParentHandler is TrafficAnalyzer)
            {
                if (rt.ContainsRoutedTrafficAnalyzer((TrafficAnalyzer)attacher.ParentHandler))
                {
                    rt.RemoveRoutingTrafficAnalyzer((TrafficAnalyzer)attacher.ParentHandler);

                    return(true);
                }
                else
                {
                    throw new InvalidOperationException("The ports " + sender.Name + " and " + attacher.Name + " are not connected.");
                }
            }
            else
            {
                throw new InvalidOperationException("Only traffic analyzers can connect the " + thRoutedTrafficAnalyzerPort.Name + ".");
            }
        }
        bool thInterfaceIO_HandlerStatusCallback(TrafficHandlerPort sender, TrafficHandlerPort attacher)
        {
            CheckPorts(sender, InterfaceIOPort);

            DirectInterfaceIOHandler thLocalHandler = (DirectInterfaceIOHandler)TrafficHandler;

            return(attacher.ParentHandler is IPInterface && thLocalHandler.ContainsInterface((IPInterface)attacher.ParentHandler));
        }
Beispiel #4
0
        protected TrafficHandlerPort CreateExternalInPort()
        {
            ExternalInPort = new TrafficHandlerPort(this, NATHandler.ExternalInputHandler, "External NAT In Port", "All frames pushed into this port will be translated to the internal addresses and pushed out to the Internal Output Port. This port is meant to be linked with the Router or DirectInterfaceIO.", PortType.Input, "erx");
            ExternalInPort.HandlerAttaching      += new TrafficHandlerPort.PortActionEventHandler(ExternalInPort_HandlerAttaching);
            ExternalInPort.HandlerStatusCallback += new TrafficHandlerPort.PortQueryEventHandler(ExternalInPort_HandlerStatusCallback);
            ExternalInPort.HandlerDetaching      += new TrafficHandlerPort.PortActionEventHandler(ExternalInPort_HandlerDetaching);

            return(ExternalInPort);
        }
        bool thInterfaceIO_HandlerDetached(TrafficHandlerPort sender, TrafficHandlerPort attacher)
        {
            if (sender != InterfaceIOPort)
            {
                throw new InvalidOperationException("The Interface IO Port detach event was signalled by another sender than the Interface IO Port. This is a serious internal error.");
            }

            return(DetachInterface(attacher));
        }
Beispiel #6
0
        private TrafficHandlerPort CreateOutPortA(TrafficHandler h)
        {
            OutPortA = new TrafficHandlerPort(this, "Traffic Handler Out Port A", "A port which pushes traffic to another traffic handler", PortType.Output, "A");
            OutPortA.HandlerStatusCallback += new TrafficHandlerPort.PortQueryEventHandler(thOutPortA_HandlerStatusCallback);
            OutPortA.HandlerAttaching      += new TrafficHandlerPort.PortActionEventHandler(OutPortA_HandlerAttaching);
            OutPortA.HandlerDetaching      += new TrafficHandlerPort.PortActionEventHandler(OutPortA_HandlerDetaching);

            return(OutPortA);
        }
Beispiel #7
0
        protected TrafficHandlerPort CreateExternalOutPort()
        {
            ExternalOutPort = new TrafficHandlerPort(this, "External NAT Out Port", "All frames send out this port are translated to their external addresses, ready for sending. This port is meant to be linked with the Router or DirectInterfaceIO.", PortType.Output, "etx");
            ExternalOutPort.HandlerAttaching      += new TrafficHandlerPort.PortActionEventHandler(ExternalOutPort_HandlerAttached);
            ExternalOutPort.HandlerStatusCallback += new TrafficHandlerPort.PortQueryEventHandler(ExternalOutPort_HandlerStatusCallback);
            ExternalOutPort.HandlerDetaching      += new TrafficHandlerPort.PortActionEventHandler(ExternalOutPort_HandlerDetached);

            return(ExternalOutPort);
        }
        bool thStandardInPort_HandlerDetached(TrafficHandlerPort sender, TrafficHandlerPort attacher)
        {
            CheckPorts(sender, StandardInPort);

            if (attacher.PortType == PortType.Output)
            {
                return(true);
            }

            throw new InvalidOperationException("The " + StandardInPort.Name + " can only interact with output ports.");
        }
        bool thRoutedTrafficAnalyzerPort_HandlerStatusCallback(TrafficHandlerPort sender, TrafficHandlerPort attacher)
        {
            if (sender != thRoutedTrafficAnalyzerPort)
            {
                throw new InvalidOperationException("The Routed Traffic Analyzer Port query callback was called by another sender than the Routed Traffic Analyzer Port. This is a serious internal error.");
            }

            Router rt = (Router)TrafficHandler;

            return(attacher.ParentHandler is TrafficAnalyzer && rt.ContainsRoutedTrafficAnalyzer((TrafficAnalyzer)attacher.ParentHandler));
        }
Beispiel #10
0
        bool ExternalInPort_HandlerAttaching(TrafficHandlerPort sender, TrafficHandlerPort attacher)
        {
            CheckPorts(sender, ExternalInPort);

            if (attacher.PortType == PortType.Output)
            {
                return(true);
            }

            throw new InvalidOperationException("The " + ExternalInPort.Name + " can only interact with output ports.");
        }
Beispiel #11
0
        bool thOutPortB_HandlerStatusCallback(TrafficHandlerPort sender, TrafficHandlerPort attacher)
        {
            if (sender != OutPortB)
            {
                throw new InvalidOperationException("The Out Port B query callback was called by another sender than the Out Port B. This is a serious internal error.");
            }

            ConditionalTrafficSplitter thSplitter = (ConditionalTrafficSplitter)TrafficHandler;

            return(thSplitter.OutputB == attacher.ParentHandler);
        }
 protected void CheckPorts(TrafficHandlerPort port, TrafficHandlerPort check)
 {
     if (check == null)
     {
         throw new InvalidOperationException(port.Name + " called an event for a port which was not even created. This is a serious internal error.");
     }
     if (port != check)
     {
         throw new InvalidOperationException("A " + check.Name + " event was called by another sender (" + port.Name + ") than the " + check.Name + ". This is a serious internal error.");
     }
 }
        /// <summary>
        /// Creates a Routed Traffic Analyzer port
        /// </summary>
        /// <param name="h">The traffic handler to create the port for</param>
        /// <returns>The created port</returns>
        protected TrafficHandlerPort CreateRoutedTrafficAnalyzerPort(TrafficHandler h)
        {
            if (h != TrafficHandler)
            {
                throw new InvalidOperationException("It's not allowed to create a port with a traffic handler which was not created by this definition");
            }

            thRoutedTrafficAnalyzerPort = new TrafficHandlerPort(this, "Routed Traffic Analyzer Port", "This port provides the possibility to analyze routed traffic", PortType.Output, "r+");
            thRoutedTrafficAnalyzerPort.HandlerAttaching      += new TrafficHandlerPort.PortActionEventHandler(thRoutedTrafficAnalyzerPort_HandlerAttached);
            thRoutedTrafficAnalyzerPort.HandlerStatusCallback += new TrafficHandlerPort.PortQueryEventHandler(thRoutedTrafficAnalyzerPort_HandlerStatusCallback);
            thRoutedTrafficAnalyzerPort.HandlerDetaching      += new TrafficHandlerPort.PortActionEventHandler(thRoutedTrafficAnalyzerPort_HandlerDetached);
            return(thRoutedTrafficAnalyzerPort);
        }
        bool thInterfacePort_HandlerAttached(TrafficHandlerPort sender, TrafficHandlerPort attacher)
        {
            CheckPorts(sender, InterfacePort);

            if (attacher.PortType == PortType.InterfaceIO)
            {
                return(true);
            }
            else
            {
                throw new InvalidOperationException("The " + InterfacePort.Name + " can only be used with Interface IO ports.");
            }
        }
        /// <summary>
        /// Creates a standard Traffic Handler In Port
        /// </summary>
        /// <param name="h">The traffic handler to create the port for</param>
        /// <returns>The created port</returns>
        protected TrafficHandlerPort CreateStandardInPort(TrafficHandler h)
        {
            if (h != TrafficHandler)
            {
                throw new InvalidOperationException("It's not allowed to create a port with a traffic handler which was not created by this definition");
            }

            StandardInPort = new TrafficHandlerPort(this, "Traffic Handler In Port", "A port which receives traffic from another traffic handler", PortType.Input, "rx");
            StandardInPort.HandlerAttaching      += new TrafficHandlerPort.PortActionEventHandler(thStandardInPort_HandlerAttached);
            StandardInPort.HandlerStatusCallback += new TrafficHandlerPort.PortQueryEventHandler(thStandardInPort_HandlerStatusCallback);
            StandardInPort.HandlerDetaching      += new TrafficHandlerPort.PortActionEventHandler(thStandardInPort_HandlerDetached);

            return(StandardInPort);
        }
Beispiel #16
0
        /// <summary>
        /// Creates the Out Port B
        /// </summary>
        /// <param name="h">The traffic handler to create the port for</param>
        /// <returns>The created port</returns>
        protected TrafficHandlerPort CreateOutPortB(TrafficHandler h)
        {
            if (h != TrafficHandler)
            {
                throw new InvalidOperationException("It's not allowed to create a port with a traffic handler which was not created by this definition");
            }

            OutPortB = new TrafficHandlerPort(this, "Traffic Handler Out Port B", "A port which pushes traffic to another traffic handler", PortType.Output, "B");
            OutPortB.HandlerAttaching      += new TrafficHandlerPort.PortActionEventHandler(thOutPortB_HandlerAttached);
            OutPortB.HandlerStatusCallback += new TrafficHandlerPort.PortQueryEventHandler(thOutPortB_HandlerStatusCallback);
            OutPortB.HandlerDetaching      += new TrafficHandlerPort.PortActionEventHandler(thOutPortB_HandlerDetached);

            return(OutPortB);
        }
        /// <summary>
        /// Creates an Interface port
        /// </summary>
        /// <param name="h">The IPInterface to create the port for</param>
        /// <returns>The created port</returns>
        protected TrafficHandlerPort CreateDirectInterfacePort(IPInterface h)
        {
            if (h != TrafficHandler)
            {
                throw new InvalidOperationException("It's not allowed to create a port with a traffic handler which was not created by this definition");
            }

            InterfacePort = new TrafficHandlerPort(this, "Interface Port", "A port which receives and transmits data from and to this network interface", PortType.Interface, "I/O");
            InterfacePort.HandlerAttaching      += new TrafficHandlerPort.PortActionEventHandler(thInterfacePort_HandlerAttached);
            InterfacePort.HandlerStatusCallback += new TrafficHandlerPort.PortQueryEventHandler(thInterfacePort_HandlerStatusCallback);
            InterfacePort.HandlerDetaching      += new TrafficHandlerPort.PortActionEventHandler(thInterfacePort_HandlerDetached);

            return(InterfacePort);
        }
Beispiel #18
0
        bool ExternalOutPort_HandlerDetached(TrafficHandlerPort sender, TrafficHandlerPort attacher)
        {
            CheckPorts(sender, ExternalOutPort);

            if (attacher.PortType == PortType.Input)
            {
                if (NATHandler.ExternalOutputHandler == attacher.ParentHandler)
                {
                    NATHandler.ExternalOutputHandler = null;
                    return(true);
                }
                else
                {
                    throw new InvalidOperationException("The ports " + sender.Name + " and " + attacher.Name + " are not connected.");
                }
            }

            throw new InvalidOperationException("The " + sender.Name + " can only be used with input ports.");
        }
Beispiel #19
0
        bool ExternalOutPort_HandlerAttached(TrafficHandlerPort sender, TrafficHandlerPort attacher)
        {
            CheckPorts(sender, ExternalOutPort);

            if (attacher.PortType == PortType.Input)
            {
                if (NATHandler.ExternalOutputHandler == null)
                {
                    NATHandler.ExternalOutputHandler = attacher.ParentHandler;
                    return(false);
                }
                else
                {
                    throw new InvalidOperationException("Another handler is already connected to the " + sender.Name + ".");
                }
            }

            throw new InvalidOperationException("The " + sender.Name + " can only be used with input ports.");
        }
        bool thDroppedAnalyzerPort_HandlerAttached(TrafficHandlerPort sender, TrafficHandlerPort attacher)
        {
            CheckPorts(sender, DroppedAnalyzerPort);

            if (attacher.ParentHandler is TrafficAnalyzer)
            {
                if (!TrafficHandler.ContainsDroppedTrafficAnalyzer((TrafficAnalyzer)attacher.ParentHandler))
                {
                    TrafficHandler.AddDroppedTrafficAnalyzer((TrafficAnalyzer)attacher.ParentHandler);

                    return(true);
                }
                else
                {
                    throw new InvalidOperationException("The ports " + sender.Name + " and " + attacher.Name + " are already connected.");
                }
            }
            else
            {
                throw new InvalidOperationException("Only traffic analyzers can interact with the " + DroppedAnalyzerPort.Name);
            }
        }
        private bool AttachInterface(TrafficHandlerPort h)
        {
            DirectInterfaceIOHandler thLocalHandler = (DirectInterfaceIOHandler)TrafficHandler;

            if (h.PortType == PortType.Interface)
            {
                if (h.ParentHandler is IPInterface)
                {
                    IPInterface ipi = (IPInterface)h.ParentHandler;
                    if (!thLocalHandler.ContainsInterface(ipi))
                    {
                        thLocalHandler.AddInterface(ipi);
                    }
                    else
                    {
                        throw new InvalidOperationException("The ports " + h.Name + " and " + InterfaceIOPort.Name + " are already connected.");
                    }
                    return(true);
                }
            }
            throw new InvalidOperationException("The " + InterfaceIOPort.Name + " cannot be used with other ports then interface ports or other devices then ip interfaces.");
        }
Beispiel #22
0
        bool OutPortA_HandlerDetaching(TrafficHandlerPort sender, TrafficHandlerPort attacher)
        {
            if (sender != OutPortA)
            {
                throw new InvalidOperationException("The Out Port A detach event was signalled by another sender than the Out Port A. This is a serious internal error.");
            }

            ConditionalTrafficSplitter thSplitter = (ConditionalTrafficSplitter)TrafficHandler;

            if (attacher.PortType == PortType.Input)
            {
                if (thSplitter.OutputA == attacher.ParentHandler)
                {
                    thSplitter.OutputA = null;
                    return(true);
                }
                else
                {
                    throw new InvalidOperationException("The specified ports are not connected.");
                }
            }

            throw new InvalidOperationException("This port can only be used with input ports.");
        }
Beispiel #23
0
        bool thOutPortB_HandlerAttached(TrafficHandlerPort sender, TrafficHandlerPort attacher)
        {
            if (sender != OutPortB)
            {
                throw new InvalidOperationException("The Out Port B attach event was signalled by another sender than the Out Port B. This is a serious internal error.");
            }

            ConditionalTrafficSplitter thSplitter = (ConditionalTrafficSplitter)TrafficHandler;

            if (attacher.PortType == PortType.Input)
            {
                if (thSplitter.OutputB == null)
                {
                    thSplitter.OutputB = attacher.ParentHandler;
                    return(false);
                }
                else
                {
                    throw new InvalidOperationException("Another handler is already connected to this port.");
                }
            }

            throw new InvalidOperationException("This port can only be used with input ports.");
        }
        bool thStandardInPort_HandlerStatusCallback(TrafficHandlerPort sender, TrafficHandlerPort attacher)
        {
            CheckPorts(sender, StandardInPort);

            return(false);
        }
        bool thDroppedAnalyzerPort_HandlerStatusCallback(TrafficHandlerPort sender, TrafficHandlerPort attacher)
        {
            CheckPorts(sender, DroppedAnalyzerPort);

            return(attacher.ParentHandler is TrafficAnalyzer && TrafficHandler.ContainsDroppedTrafficAnalyzer((TrafficAnalyzer)attacher.ParentHandler));
        }
        bool thInterfacePort_HandlerStatusCallback(TrafficHandlerPort sender, TrafficHandlerPort attacher)
        {
            CheckPorts(sender, InterfacePort);

            return(false);
        }
Beispiel #27
0
        bool ExternalInPort_HandlerStatusCallback(TrafficHandlerPort sender, TrafficHandlerPort attacher)
        {
            CheckPorts(sender, ExternalInPort);

            return(false);
        }
        bool thStandardOutPort_HandlerStatusCallback(TrafficHandlerPort sender, TrafficHandlerPort attacher)
        {
            CheckPorts(sender, StandardOutPort);

            return(TrafficHandler.OutputHandler == attacher.ParentHandler);
        }
        bool thInterfaceIO_HandlerAttached(TrafficHandlerPort sender, TrafficHandlerPort attacher)
        {
            CheckPorts(sender, InterfaceIOPort);

            return(AttachInterface(attacher));
        }
Beispiel #30
0
        bool ExternalOutPort_HandlerStatusCallback(TrafficHandlerPort sender, TrafficHandlerPort attacher)
        {
            CheckPorts(sender, ExternalOutPort);

            return(NATHandler.ExternalOutputHandler == attacher.ParentHandler);
        }