Beispiel #1
0
 public void ReceiveCSPPacket(CSPPacket packet, CSPBus bus)
 {
     if (packet.ErrorDetected)
     {
         //Log received packet
         EventLog.AddLog(new SimEvent(
                             "Module " + Name + " detected an error in received packet: " + packet.ToString() + ", the packet was discarded",
                             EventSeverity.ERROR));
     }
     else if (CommunicationDisabled)
     {
         //Log unreceived packet
         EventLog.AddLog(new SimEvent(
                             "Module " + Name + " could not receive packet " + packet.ToString() + " because it has lost connection",
                             EventSeverity.ERROR));
     }
     else
     {
         //Log received packet
         EventLog.AddLog(new SimEvent(
                             "Module " + Name + " received packet: " + packet.ToString(),
                             EventSeverity.INFO));
         //Processing
         if (packet.Command == ModuleCommand.PING)
         {
             //Respond to the ping with an equally sized packet over the same bus
             SendCSPPacket(
                 bus,
                 (byte)packet.Header[CSPPacket.SourceAddress],
                 (byte)packet.Header[CSPPacket.SourcePort],
                 (byte)packet.Header[CSPPacket.DestinationPort],
                 (byte)Priority,
                 packet.DataSize,
                 ModuleCommand.SEND
                 );
         }
     }
 }
Beispiel #2
0
        public void SendCSPPacket(CSPBus bus, byte destination_addr, byte destination_port, byte source_port, byte priority, short dataSize, ModuleCommand command)
        {
            var         rnd          = new Random();
            BitVector32 packetHeader = new BitVector32(0x00000000);

            packetHeader[CSPPacket.SourceAddress]      = randomSource ? ((byte)(rnd.Next(0, 32))) : Address;
            packetHeader[CSPPacket.DestinationAddress] = randomDestination ? ((byte)(rnd.Next(0, 32))) : destination_addr;
            packetHeader[CSPPacket.SourcePort]         = randomSourcePort ? ((byte)(rnd.Next(0, 64))) : source_port;
            packetHeader[CSPPacket.DestinationPort]    = randomDestinationPort ? ((byte)(rnd.Next(0, 64))) : destination_port;
            packetHeader[CSPPacket.Priority]           = randomPriority ? ((byte)(rnd.Next(0, 4))) : priority;
            CSPPacket packet = new CSPPacket(packetHeader, dataSize, command);

            if (bus == null)
            {
                //Log failed send
                EventLog.AddLog(new SimEvent(
                                    "Module " + Name + " failed to send a packet because the target bus does not exist (check that the bus in your script exists in the simulation)",
                                    EventSeverity.ERROR));
            }
            else if (CommunicationDisabled)
            {
                //Log failed send
                EventLog.AddLog(new SimEvent(
                                    "Module " + Name + " failed to send packet " + packet.ToString() + " because it has lost connection",
                                    EventSeverity.ERROR));
            }
            else if (BusConnections.Contains(bus))
            {
                //We are assuming that all packets with wrong bits/data are considered in error because the
                //probablity that the error is not detected is negligible
                if (randomPriority)
                {
                    packet.ErrorDetected = true;
                    //Log sending packet with random priority
                    EventLog.AddLog(new SimEvent(
                                        "Module " + Name + " sends a packet containing a random priority: " + packet.ToString() + " to bus " + bus.Name,
                                        EventSeverity.WARNING));
                }
                if (randomDestination)
                {
                    packet.ErrorDetected = true;
                    //Log sending packet with random destination
                    EventLog.AddLog(new SimEvent(
                                        "Module " + Name + " sends a packet containing a random destination address: " + packet.ToString() + " to bus " + bus.Name,
                                        EventSeverity.WARNING));
                }
                if (randomSource)
                {
                    packet.ErrorDetected = true;
                    //Log sending packet with random psource
                    EventLog.AddLog(new SimEvent(
                                        "Module " + Name + " sends a packet containing a random source address: " + packet.ToString() + " to bus " + bus.Name,
                                        EventSeverity.WARNING));
                }
                if (randomDestinationPort)
                {
                    packet.ErrorDetected = true;
                    //Log sending packet with random psource
                    EventLog.AddLog(new SimEvent(
                                        "Module " + Name + " sends a packet containing a random destination port: " + packet.ToString() + " to bus " + bus.Name,
                                        EventSeverity.WARNING));
                }
                if (randomSourcePort)
                {
                    packet.ErrorDetected = true;
                    //Log sending packet with random psource
                    EventLog.AddLog(new SimEvent(
                                        "Module " + Name + " sends a packet containing a random source port: " + packet.ToString() + " to bus " + bus.Name,
                                        EventSeverity.WARNING));
                }

                if (GarbageOutput)
                {
                    packet.ErrorDetected = true;
                }

                bus.EnqueuePacket(packet);
                if (!(randomPriority || randomDestination || randomSource || randomDestinationPort || randomSourcePort))
                {
                    //Log sending normal packet
                    EventLog.AddLog(new SimEvent(
                                        "Module " + Name + " sends packet " + packet.ToString() + " to bus " + bus.Name,
                                        EventSeverity.INFO));
                }
            }
            else
            {
                //Log failed send
                EventLog.AddLog(new SimEvent(
                                    "Module " + Name + " failed to send packet " + packet.ToString() + " because it is not connected to bus " + bus.Name,
                                    EventSeverity.ERROR));
            }
        }