Beispiel #1
0
        private void btCreateLink_Click(object sender, EventArgs e)
        {
            lblLink.Text         = "...";
            btCreateLink.Enabled = false;
            TH = new TrafficHandler(m_dataLocation, m_stepLength_Sec, cbxLogging.Enabled);

            if (TH.Valid)
            {
                bool ret = TH.EstablishLink(IP, (uint)numTotalAC.Value, (uint)numVFR.Value);
                if (ret)
                {
                    TH.TrafficEvent       += TH_TrafficEvent;
                    btCreateLink.BackColor = Color.ForestGreen;
                    timer1.Interval        = 1000; // 1 sec only
                    timer1.Enabled         = true;
                }
                else
                {
                    // error on establish link
                    lblLink.Text           = TH.Error;
                    btCreateLink.Enabled   = true;
                    btCreateLink.BackColor = Color.IndianRed;
                }
            }
            else
            {
                // invalid datafile..
                lblLink.Text         = TH.Error;
                btCreateLink.Enabled = true;
            }
        }
        public MainWindow()
        {
            Process.Start(@"..\..\Ampelsteuerung.exe");
            InitializeComponent();
            StartAmpelsteuerung();

            mqhandler = new RabbitMQ.RabbitMQHandler();


            dispatchTimer          = new DispatcherTimer();
            dispatchTimer.Tick    += dispatchTimer_Tick;
            dispatchTimer.Interval = new TimeSpan(0, 0, 0, 0, 50);


            ap      = new GUI.AmpelHandler(myCanvas);
            builder = new EnvironmentHandler(myCanvas, ref ap, ref trafficlight);
            oh      = new ObjectHandler(myCanvas, ref builder);
            I_ENV_VKTeilnehmer iTeilnehmer = builder;
            IObject            iObject     = oh;

            th = TrafficHandler.getInstance(ref iTeilnehmer, ref iObject, ref mqhandler);

            th.createNewVerkehrsteilnehmer(210, 155, 4, (int)TrafficObject.Fahrzeugtyp.Car, (int)TrafficObject.Dir.Right, (int)TrafficObject.Dir.Right);
            th.createNewVerkehrsteilnehmer(35, 155, 4, (int)TrafficObject.Fahrzeugtyp.Car, (int)TrafficObject.Dir.Right, (int)TrafficObject.Dir.Right);
            th.createNewVerkehrsteilnehmer(10, 155, 4, (int)TrafficObject.Fahrzeugtyp.Car, (int)TrafficObject.Dir.Right, (int)TrafficObject.Dir.Right);
            th.createNewVerkehrsteilnehmer(280, 145, 4, (int)TrafficObject.Fahrzeugtyp.Car, (int)TrafficObject.Dir.Left, (int)TrafficObject.Dir.Down);
            th.createNewVerkehrsteilnehmer(255, 285, 4, (int)TrafficObject.Fahrzeugtyp.Car, (int)TrafficObject.Dir.Up, (int)TrafficObject.Dir.Up);
            th.createNewVerkehrsteilnehmer(320, 355, 4, (int)TrafficObject.Fahrzeugtyp.Car, (int)TrafficObject.Dir.Right, (int)TrafficObject.Dir.Right);
            th.createNewVerkehrsteilnehmer(255, 655, 4, (int)TrafficObject.Fahrzeugtyp.Car, (int)TrafficObject.Dir.Up, (int)TrafficObject.Dir.Up);
            th.createNewVerkehrsteilnehmer(255, 645, 4, (int)TrafficObject.Fahrzeugtyp.Car, (int)TrafficObject.Dir.Up, (int)TrafficObject.Dir.Up);


            dispatchTimer.Start();
        }
        public static void EstablishConnection()
        {
            try
            {
                while (!Login.Credentials.Check())
                {
                    if (Resources.ServerResources.client != null)
                    {
                        if (Resources.ServerResources.client.Connected)
                        {
                            Resources.ServerResources.stream.Close();
                            Resources.ServerResources.client.Close();
                        }
                    }
                    Resources.ServerResources.client = new System.Net.Sockets.TcpClient();
                    Resources.ServerResources.client.Connect(Resources.ServerResources.IPAddress, Resources.ServerResources.Port);
                    Resources.ServerResources.stream = new System.Net.Sockets.NetworkStream(Resources.ServerResources.client.Client);
                    if (Resources.ServerResources.AutoLogin)
                    {
                        Resources.ServerResources.Username = Resources.ServerResources.settings.lastUsername;
                        Resources.ServerResources.Password = Resources.ServerResources.settings.password;
                    }
                    else
                    {
                        Resources.ServerResources.LoginForm.ShowDialog();
                    }
                }
                Resources.ServerResources.LoginForm.Close();

                if (!Resources.ServerResources.AutoLogin)
                {
                    //Login-Daten werden gespeichert
                    Resources.ServerResources.settings.lastUsername = Crypto.Encrypt.String(Resources.ServerResources.Username);
                    Resources.ServerResources.settings.password     = Crypto.Encrypt.String(Resources.ServerResources.Password);
                    Resources.Services.FileCreater.UpdateSettingsFile(Resources.ServerResources.settings);
                }
            }
            catch (System.Net.Sockets.SocketException)
            {
                Events.ErrorEvents.ConnectionError.OnAppear(new Events.Args.EventArgs.ErrorEventArgs()
                {
                    ErrorMessage = "Der Server ist zur Zeit nicht erreichbar."
                });
            }
            catch (System.IO.IOException)
            {
                Events.ErrorEvents.NetworkStreamError.OnAppear(new Events.Args.EventArgs.ErrorEventArgs()
                {
                    ErrorMessage = "Fehler beim beziehen des Network Streams aus dem Verbundenen Stream!"
                });
            }
            catch (Exception)
            {
                throw new Exception();
            }
            //Einkommende Daten vom Server werden empfangen
            TrafficHandler.HandleServerTraffic();
        }
        public RabbitMQHandler()
        {
            th = TrafficHandler.getInstance();

            //remoteTransaction = new RemoteTransaction(10.1, "PKW");
            //Send(remoteTransaction, "group3");

            Receive();
        }
Beispiel #5
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 #6
0
 internal UDPClientHandler(int id, ushort serverKey, ushort clientKey, IPEndPoint remoteEP, UDPServer server, TrafficHandler trafficHandler)
 {
     this.Id             = id;
     this.ServerKey      = serverKey;
     this.ClientKey      = clientKey;
     this.RemoteEP       = remoteEP;
     this.server         = server;
     this.trafficHandler = trafficHandler;
 }
Beispiel #7
0
        protected override TrafficHandlerPort[] CreateTrafficHandlerPorts(TrafficHandler h, object param)
        {
            List <TrafficHandlerPort> lPorts = new List <TrafficHandlerPort>();

            lPorts.Add(CreateStandardInPort(h));
            lPorts.Add(CreateStandardOutPort(h));
            lPorts.Add(CreateClonePort(h));

            return(lPorts.ToArray());
        }
Beispiel #8
0
 /// <summary>
 /// Creates a new instance of this class with the given parameters
 /// </summary>
 /// <param name="hcController">The parent Handler Controller</param>
 /// <param name="thHandler">The TrafficHandler controlled by this port</param>
 /// <param name="strName">The name of this port</param>
 /// <param name="strDescription">The description of this port</param>
 /// <param name="pType">The type of this port</param>
 /// <param name="strAbbreviation">The abbreviation of this port's name</param>
 public TrafficHandlerPort(HandlerController hcController, TrafficHandler thHandler, string strName, string strDescription, PortType pType, string strAbbreviation)
 {
     ParentHandler     = thHandler;
     ParentController  = hcController;
     this.Description  = strDescription;
     this.Name         = strName;
     this.CanAttach    = true;
     this.PortType     = pType;
     this.Abbreviation = strAbbreviation;
 }
Beispiel #9
0
        protected override TrafficHandlerPort[] CreateTrafficHandlerPorts(TrafficHandler h, object param)
        {
            List <TrafficHandlerPort> lPorts = new List <TrafficHandlerPort>();

            lPorts.AddRange(CreateDefaultPorts(h, true, true, false, true, false));
            lPorts.Add(CreateExternalInPort());
            lPorts.Add(CreateExternalOutPort());

            return(lPorts.ToArray());
        }
Beispiel #10
0
        protected override TrafficHandlerPort[] CreateTrafficHandlerPorts(TrafficHandler h, object param)
        {
            List <TrafficHandlerPort> lPorts = new List <TrafficHandlerPort>();

            lPorts.Add(CreateOutPortA(h));
            lPorts.Add(CreateOutPortB(h));
            lPorts.Add(CreateStandardInPort(h));
            lPorts.Add(CreateDroppedTrafficAnalyzerPort(h));

            return(lPorts.ToArray());
        }
        protected override TrafficHandlerPort[] CreateTrafficHandlerPorts(TrafficHandler h, object param)
        {
            List <TrafficHandlerPort> lPorts = new List <TrafficHandlerPort>();

            lPorts.Add(CreateDirectInterfaceIOPort((DirectInterfaceIOHandler)h));
            lPorts.Add(CreateDroppedTrafficAnalyzerPort(h));
            lPorts.Add(CreateStandardInPort(h));
            lPorts.Add(CreateStandardOutPort(h));
            lPorts.Add(CreateRoutedTrafficAnalyzerPort(h));

            return(lPorts.ToArray());
        }
Beispiel #12
0
 private void btDropLink_Click(object sender, EventArgs e)
 {
     timer1.Enabled = false;
     if (TH != null)
     {
         TH.TrafficEvent -= TH_TrafficEvent;
         TH.RemoveLink( );
         lblLink.Text = TH.Error;
     }
     btCreateLink.BackColor = btDropLink.BackColor; // reset
     TH = null;
     btCreateLink.Enabled = true;
 }
        /// <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);
        }
Beispiel #14
0
        public UDPServer(IUDPServer eventHandler)
        {
            this.eventHandler = eventHandler;
            trafficHandler    = new TrafficHandler(this);

            receivedCallbacks = new Dictionary <Packet.Type, Action <Packet> >();
            receivedCallbacks[Packet.Type.ConnectionRequest]  = OnConnectionRequestReceived;
            receivedCallbacks[Packet.Type.ChallengeResponse]  = OnChallengeResponseReceived;
            receivedCallbacks[Packet.Type.Event]              = OnEventReceived;
            receivedCallbacks[Packet.Type.Challenge]          = OnUnknownPacketReceived;
            receivedCallbacks[Packet.Type.ConnectionAccepted] = OnUnknownPacketReceived;
            receivedCallbacks[Packet.Type.ConnectionRejected] = OnUnknownPacketReceived;
            receivedCallbacks[Packet.Type.None] = OnUnknownPacketReceived;
        }
Beispiel #15
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 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);
        }
        public void Send(RemoteTransaction transaction, String group)
        {
            th = TrafficHandler.getInstance();
            var factory = new ConnectionFactory();

            factory.Uri = "amqp://*****:*****@rabbit.binna.eu/";  //Insert your own user and password

            using (var connection = factory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    var transactionString = JsonConvert.SerializeObject(transaction); //Awesome function

                    var properties = channel.CreateBasicProperties();
                    properties.Persistent = true;

                    channel.BasicPublish(exchange: "car.production",  //Choose between bank.development and bank.production depending of the queue (e.g. 70 is production, 71 is development)
                                         routingKey: group,           //This relates to the queue name of the receiver bank
                                         basicProperties: properties, //Set the properties to persistent, otherwise the messages will get lost if the server restarts
                                         body: GetBytes(transactionString));
                }
        }
        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);
            }
        }
Beispiel #19
0
        /// <summary>
        /// Creates a new instance of this class with the given params
        /// </summary>
        /// <param name="ipaStart">The start IP address of the range to scan</param>
        /// <param name="ipaEnd">The end IP address of the range to scan</param>
        /// <param name="ipLocal">The IP address which should be spoofed during scanning</param>
        /// <param name="thOut">The traffic handler to which the generated ARP frames should be forwarded. It is wise to assign an ARP net scanner here</param>
        protected ScanTask(IPAddress ipaStart, IPAddress ipaEnd, IPAddress ipLocal, TrafficHandler thOut)
        {
            if (IPAddressAnalysis.Compare(ipaStart, ipaEnd) == -1)
            {
                this.StartAddress = ipaStart;
                this.EndAddress   = ipaEnd;
            }
            else
            {
                this.StartAddress = ipaEnd;
                this.EndAddress   = ipaStart;
            }

            this.SourceAddress = ipLocal;
            this.OutputHandler = thOut;
            this.bIsFinished   = false;

            this.byteStartIP  = this.StartAddress.GetAddressBytes();
            this.byteEndIP    = this.EndAddress.GetAddressBytes();
            this.ScannedCount = 0;

            ScanCount = IPAddressAnalysis.GetIpCount(ipaStart, ipaEnd);
        }
        /// <summary>
        /// Automatically creates the default traffic handler ports.
        /// </summary>
        /// <param name="h">The traffic handler to create the ports with</param>
        /// <param name="bCreateStandardInPort">A bool which defines whether to create a Traffic Handler In Port</param>
        /// <param name="bCreateStandardOutPort">A bool which defines whether to create a Traffic Handler Out Port</param>
        /// <param name="bCreateInterfaceIOPort">A bool which defines whether to create an Interface IO Port</param>
        /// <param name="bCreateDroppedTrafficAnalyzerPort">A bool which defines whether to create a Dropped Traffic Analyzer Port</param>
        /// <param name="bCreateInterfacePort">A bool which defines whether to create an Interface Port</param>
        /// <returns></returns>
        protected TrafficHandlerPort[] CreateDefaultPorts(TrafficHandler h, bool bCreateStandardInPort,
                                                          bool bCreateStandardOutPort,
                                                          bool bCreateInterfaceIOPort,
                                                          bool bCreateDroppedTrafficAnalyzerPort,
                                                          bool bCreateInterfacePort)
        {
            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");
            }

            List <TrafficHandlerPort> lPorts = new List <TrafficHandlerPort>();

            if (bCreateStandardInPort)
            {
                lPorts.Add(CreateStandardInPort(h));
            }
            if (bCreateStandardOutPort)
            {
                lPorts.Add(CreateStandardOutPort(h));
            }
            if (bCreateInterfaceIOPort)
            {
                lPorts.Add(CreateDirectInterfaceIOPort((DirectInterfaceIOHandler)h));
            }
            if (bCreateDroppedTrafficAnalyzerPort)
            {
                lPorts.Add(CreateDroppedTrafficAnalyzerPort(h));
            }
            if (bCreateInterfacePort)
            {
                lPorts.Add(CreateDirectInterfacePort((IPInterface)h));
            }

            return(lPorts.ToArray());
        }
 protected override TrafficHandlerPort[] CreateTrafficHandlerPorts(TrafficHandler h, object param)
 {
     return(CreateDefaultPorts(h, true, false, false, false, false));
 }
 protected override HandlerConfigurationWriter CreateConfigurationWriter(TrafficHandler h, object param)
 {
     return(null);
 }
 protected override HandlerConfigurationWriter CreateConfigurationWriter(TrafficHandler h, object param)
 {
     return(new WANEmulatorConfigurationWriter(h));
 }
Beispiel #24
0
 public RouterConfigurationLoader(TrafficHandler thHandler)
     : base(thHandler)
 {
     this.thHandler = (Router)thHandler;
 }
        public static void HandleLogin(Client client)
        {
            try
            {
                LoginPurpose.LoginPurposes loginPurpose = LoginPurpose.Check(client);
                if (loginPurpose == LoginPurpose.LoginPurposes.ClientLogIn)
                {
                    client = LoginCredentials.Receive(client);
                    if (client != null)
                    {
                        if (FileManager.UserFiles.CheckUser(client))
                        {
                            ClientRank rank = Rank.GetUserRank(client);
                            if (rank != 0)
                            {
                                client.UserRank = rank;
                                Resources.ConnectionResources.ConnectedClients.Add(client);
                                client.LoggedIn    = true;
                                client.IsConnected = true;
                                LoginCredentials.SendLsMessage(client);
                                TrafficHandler.HandleClient(client);
                            }
                            else
                            {
                                client.LoggedIn = false;
                                Events.ClientEvents.LoginFailed.OnClientLoginFailed(new Events.Args.ClientEventArgs()
                                {
                                    client = client
                                });
                                LoginCredentials.SendLsMessage(client);
                                Console.WriteLine("Rang nicht gefunden!");
                            }
                        }
                        else
                        {
                            client.LoggedIn = false;
                            //Send Login failed response
                            LoginCredentials.SendLsMessage(client);
                            Events.ClientEvents.LoginFailed.OnClientLoginFailed(new Events.Args.ClientEventArgs()
                            {
                                client = client
                            });
                        }
                    }
                    else
                    {
                        client.LoggedIn = false;
                        Console.WriteLine("False Login");
                        LoginCredentials.SendLsMessage(client);
                    }
                }
                else if (loginPurpose == LoginPurpose.LoginPurposes.DownloadSetup)
                {
                    Setup.SetupHandler.ProvideSetup(client);
                }

                /*
                 * else if(loginPurpose == LoginPurpose.LoginPurposes.None)
                 * {
                 *
                 * }
                 * else
                 * {
                 *
                 * }
                 */
            }
            catch
            {
                Events.ClientEvents.LoginFailed.OnClientLoginFailed(new Events.Args.ClientEventArgs()
                {
                    client = client
                });
            }
        }
 public TextStreamModifierConfigurationLoader(TrafficHandler thHandler)
     : base(thHandler)
 {
     this.thHandler = (TextStreamModifier)thHandler;
 }
 /// <summary>
 /// Creates a new instance of this class associated with the given traffic handler
 /// </summary>
 /// <param name="h">The traffic handler to associate with this configuration writer</param>
 public HandlerConfigurationWriter(TrafficHandler h)
 {
     this.hHandler = h;
 }
 protected override HandlerConfigurationLoader CreateConfigurationLoader(TrafficHandler h, object param)
 {
     return(new DHCPServerConfigurationLoader(h));
 }
Beispiel #29
0
 public DumperConfigurationWriter(TrafficHandler thToSave)
     : base(thToSave)
 {
     thHandler = (LibPcapDumper)thToSave;
 }
Beispiel #30
0
 public WANEmulatorConfigurationLoader(TrafficHandler thHandler)
     : base(thHandler)
 {
     this.thHandler = (WANEmulator)thHandler;
 }