Пример #1
0
            //Build the command packet in bytes according to the value of each field
            public static byte[] GetCommandPacket(SimulatorCommand sCommand, PhysicalAddress destMAC = null)
            {
                //If the command packet is for local NIC, we should set the MAC field to all 0
                //If the command packet is for remote NIC, we should set the MAC field to remote MAC address
                byte cmdByte = 0x00;

                byte[] macInBytes = null;
                switch (sCommand)
                {
                case SimulatorCommand.LoseLocalConnection:
                    cmdByte    = BuildCommandByte((byte)NESNICLocation.Local, (byte)NESCommand.Lose);
                    macInBytes = localUsedMac;
                    break;

                case SimulatorCommand.RestoreLocalConnection:
                    cmdByte    = BuildCommandByte((byte)NESNICLocation.Local, (byte)NESCommand.Restore);
                    macInBytes = localUsedMac;
                    break;

                case SimulatorCommand.LoseRemoteConnection:
                    cmdByte = BuildCommandByte((byte)NESNICLocation.Remote, (byte)NESCommand.Lose);
                    if (destMAC != null)
                    {
                        macInBytes = destMAC.GetAddressBytes();
                    }
                    break;

                case SimulatorCommand.RestoreRemoteConnection:
                    cmdByte = BuildCommandByte((byte)NESNICLocation.Remote, (byte)NESCommand.Restore);
                    if (destMAC != null)
                    {
                        macInBytes = destMAC.GetAddressBytes();
                    }
                    break;

                default:
                    break;
                }
                if (cmdByte == paddingByte || macInBytes == null)
                {
                    return(null);
                }

                int packetLength = guid.Length + 2 + macInBytes.Length; //The Length of Command Packet = GUID(16) + paddingByte(1) + commandByte(1) + MAC(1)
                int curIdx       = 0;

                byte[] res = new byte[packetLength];

                Array.Copy(guid, res, guid.Length);
                curIdx        = guid.Length;
                res[curIdx++] = paddingByte;
                res[curIdx++] = cmdByte;
                Array.Copy(macInBytes, 0, res, curIdx, macInBytes.Length);
                curIdx += macInBytes.Length;

                return(res);
            }
Пример #2
0
        private void Operations_SimulatorCommand(int EventID)
        {
            switch (EventID)
            {
            case SimulatorCommands.WaitForInterrupt:
                break;

            case SimulatorCommands.RefreshDisplay:
                SimulatorCommand?.Invoke(EventID);
                break;

            default:
                break;
            }
        }
Пример #3
0
        /// <summary>
        /// Sends command packet to control the MSProtocolTestSuiteNetworkEventSimulator filter
        /// </summary>
        /// <param name="sCommand">Flag to specify the command type</param>
        /// <param name="localMacAddress">The MAC address used to specify the local NIC used to send the command packet</param>
        /// <param name="remoteMacAddress">The MAC address specifying the target NIC</param>
        /// <returns>Flag to specify whether it has sent the command packet successfully</returns>
        private static bool SendCommand(SimulatorCommand sCommand, PhysicalAddress localMacAddress, PhysicalAddress remoteMacAddress = null)
        {
            IPAddress ipv4Address = GetIPAddress4FromMACAddress(localMacAddress);

            if (ipv4Address == null)
            {
                return(false);
            }
            BindLocalIP(ipv4Address);

            byte[] buffer = SimulatorCommandBuilder.GetCommandPacket(sCommand, remoteMacAddress);

            if (buffer == null)
            {
                return(false);
            }
            udpClient.Send(buffer, buffer.Length, broadcastHostname, nesPort);

            return(true);
        }
            //Build the command packet in bytes according to the value of each field
            public static byte[] GetCommandPacket(SimulatorCommand sCommand, PhysicalAddress destMAC = null)
            {
                //If the command packet is for local NIC, we should set the MAC field to all 0
                //If the command packet is for remote NIC, we should set the MAC field to remote MAC address
                byte cmdByte = 0x00;
                byte[] macInBytes = null;
                switch (sCommand)
                {
                    case SimulatorCommand.LoseLocalConnection:
                        cmdByte = BuildCommandByte((byte)NESNICLocation.Local, (byte)NESCommand.Lose);
                        macInBytes = localUsedMac;
                        break;
                    case SimulatorCommand.RestoreLocalConnection:
                        cmdByte = BuildCommandByte((byte)NESNICLocation.Local, (byte)NESCommand.Restore);
                        macInBytes = localUsedMac;
                        break;
                    case SimulatorCommand.LoseRemoteConnection:
                        cmdByte = BuildCommandByte((byte)NESNICLocation.Remote, (byte)NESCommand.Lose);
                        if (destMAC != null)
                            macInBytes = destMAC.GetAddressBytes();
                        break;
                    case SimulatorCommand.RestoreRemoteConnection:
                        cmdByte = BuildCommandByte((byte)NESNICLocation.Remote, (byte)NESCommand.Restore);
                        if (destMAC != null)
                            macInBytes = destMAC.GetAddressBytes();
                        break;
                    default:
                        break;
                }
                if (cmdByte == paddingByte || macInBytes == null)
                    return null;

                int packetLength = guid.Length + 2 + macInBytes.Length; //The Length of Command Packet = GUID(16) + paddingByte(1) + commandByte(1) + MAC(1)
                int curIdx = 0;
                byte[] res = new byte[packetLength];

                Array.Copy(guid, res, guid.Length);
                curIdx = guid.Length;
                res[curIdx++] = paddingByte;
                res[curIdx++] = cmdByte;
                Array.Copy(macInBytes, 0, res, curIdx, macInBytes.Length);
                curIdx += macInBytes.Length;

                return res;
            }
        /// <summary>
        /// Sends command packet to control the MSProtocolTestSuiteNetworkEventSimulator filter
        /// </summary>
        /// <param name="sCommand">Flag to specify the command type</param>
        /// <param name="localMacAddress">The MAC address used to specify the local NIC used to send the command packet</param>
        /// <param name="remoteMacAddress">The MAC address specifying the target NIC</param>
        /// <returns>Flag to specify whether it has sent the command packet successfully</returns>
        private static bool SendCommand(SimulatorCommand sCommand, PhysicalAddress localMacAddress, PhysicalAddress remoteMacAddress = null)
        {
            IPAddress ipv4Address = GetIPAddress4FromMACAddress(localMacAddress);
            if (ipv4Address == null)
                return false;
            BindLocalIP(ipv4Address);

            byte[] buffer = SimulatorCommandBuilder.GetCommandPacket(sCommand, remoteMacAddress);

            if (buffer == null)
                return false;
            udpClient.Send(buffer, buffer.Length, broadcastHostname, nesPort);

            return true;
        }