예제 #1
0
 private void UpdatePendingRequests(IPv4 ipAddress,
                                    EthernetAddress macAddress)
 {
     using (pendingRequestsLock.Lock()) {
         //Sigh...we're missing a linked list in the current Singularity C# runtime
         foreach (PendingArpRequest pendingRequest in pendingRequests)
         {
             VTable.Assert(pendingRequest != null);
             if (pendingRequest.address == ipAddress)
             {
                 pendingRequest.active = false;
                 DebugStub.WriteLine("found waiting arp request...sending on out");
                 VectorQueueByte txBuffer = pendingRequest.txContainer.Acquire();
                 Bytes           header   = txBuffer.ExtractHead();
                 Bytes           buffer   = txBuffer.ExtractHead();
                 VTable.Assert(header != null);
                 VTable.Assert(buffer != null);
                 pendingRequest.txContainer.Release(txBuffer);
                 //Format ethernet header
                 EthernetHeader.Write(header, pendingRequest.localMac, macAddress, EthernetHeader.PROTOCOL_IP);
                 //send it!
                 VTable.Assert(pendingRequest.adapter != null);
                 pendingRequest.adapter.PopulateTxRing(header, buffer);
                 continue;
             }
         }
     }
 }
예제 #2
0
 // create a new entry
 public ArpEntry(IPv4 ipAddress, EthernetAddress mac, bool dynamic)
 {
     this.ipAddress = ipAddress;
     this.mac       = mac;
     this.dynamic   = dynamic;
     this.entryAge  = ArpTable.MaxAge;
 }
예제 #3
0
        public void ArpRequest(IPv4 sourceIP,
                               IPv4 targetIP,
                               EthernetAddress localMac,
                               Bytes header,
                               Bytes buffer,
                               IAdapter adapter)
        {
            //            AutoResetEvent requestComplete =
            AddPendingRequest(targetIP, TimeSpan.FromSeconds(3), localMac, header, buffer, adapter);

            // initiate an arp request...
            DebugPrint("Initiating request " +
                       "({0},{1}) --> ({2},{3})\n",
                       sourceIP, localMac, targetIP, EthernetAddress.Zero);

            //eventially we'll want to follow Orion's conservation of
            //packets philosophy
            Bytes arpHeader = new Bytes(new byte [EthernetHeader.Size]);
            Bytes arpMsg    = new Bytes(new byte [ArpHeader.Size]);

            //xxx I'd like to get rid of EthernetHeader eventually...

            EthernetHeader.Write(arpHeader,
                                 localMac,
                                 EthernetAddress.Broadcast,
                                 EthernetHeader.PROTOCOL_ARP);

            ArpHeader.Write(arpMsg, localMac, sourceIP,
                            ArpHeader.ARP_REQUEST, EthernetAddress.Zero,
                            targetIP);
            adapter.PopulateTxRing(arpHeader, arpMsg);
            //            DebugPrint("ArpRequest: waiting for reply\n");
            //requestComplete.WaitOne();
            //            DebugPrint("ArpRequest: reply received!\n");
        }
예제 #4
0
        // methods:
        public static int Write(byte [] !pkt,
                                int offset,
                                EthernetAddress srchw,
                                IPv4 srcip,
                                Type operation,
                                EthernetAddress targethw,
                                IPv4 targetip)
        {
            int o = offset;

            pkt[o++] = 0x00; pkt[o++] = 0x01; // hardware type = 0x0001
            pkt[o++] = 0x08; pkt[o++] = 0x00; // protocol type = 0x0800
            pkt[o++] = 0x06;                  // hardware addr len (bytes)
            pkt[o++] = 0x04;                  // protocol address len (bytes)
            pkt[o++] = (byte)(((ushort)operation) >> 8);
            pkt[o++] = (byte)(((ushort)operation) & 0xff);

            srchw.CopyOut(pkt, o);
            o += EthernetAddress.Length;

            srcip.CopyOut(pkt, o);
            o += IPv4.Length;

            targethw.CopyOut(pkt, o);
            o += EthernetAddress.Length;

            targetip.CopyOut(pkt, o);
            o += IPv4.Length;

            return(o);
        }
예제 #5
0
 public void SetHardwareAddress(EthernetAddress ea)
 {
     hlen   = 6;
     htype  = (byte)HType.Ethernet;
     chaddr = new byte[HardwareAddressLength];
     ea.CopyOut(chaddr, 0);
 }
예제 #6
0
            public Ethernet(byte[] _source, byte[] _destination)
            {
                source       = new EthernetAddress();
                source.byte0 = macManufacturer[0];
                source.byte1 = macManufacturer[1];
                source.byte2 = macManufacturer[2];
                if (_source != null)
                {
                    if (_source.Length == 3)
                    {
                        source.byte3 = _source[0];
                        source.byte4 = _source[1];
                        source.byte5 = _source[2];
                    }
                }

                destination       = new EthernetAddress();
                destination.byte0 = macManufacturer[0];
                destination.byte1 = macManufacturer[1];
                destination.byte2 = macManufacturer[2];
                if (_destination != null)
                {
                    if (_destination.Length == 3)
                    {
                        destination.byte3 = _destination[0];
                        destination.byte4 = _destination[1];
                        destination.byte5 = _destination[2];
                    }
                }

                type = htons(0x0800);
            }
예제 #7
0
        public static int Write(Bytes pkt,
                                EthernetAddress srchw,
                                IPv4 srcip,
                                ushort operation,
                                EthernetAddress targethw,
                                IPv4 targetip)
        {
            int o = 0;

            pkt[o++] = 0x00; pkt[o++] = 0x01; // hardware type = 0x0001
            pkt[o++] = 0x08; pkt[o++] = 0x00; // protocol type = 0x0800
            pkt[o++] = 0x06;                  // hardware addr len (bytes)
            pkt[o++] = 0x04;                  // protocol address len (bytes)
            pkt[o++] = (byte)(operation >> 8);
            pkt[o++] = (byte)(operation & 0xff);

            srchw.CopyOut(pkt.Array, pkt.Start + o);
            o += EthernetAddress.Length;

            srcip.CopyOut(pkt.Array, pkt.Start + o);
            o += IPv4.Length;

            targethw.CopyOut(pkt.Array, pkt.Start + o);
            o += EthernetAddress.Length;

            targetip.CopyOut(pkt.Array, pkt.Start + o);
            o += IPv4.Length;

            return(o);
        }
예제 #8
0
 private NetStatus SendResolved(NetPacket !packet,
                                Multiplexer !targetMux,
                                EthernetAddress localMac,
                                EthernetAddress remoteMac)
 {
     // set the ethernet data
     // TBC: make the ARPModule setup the packet
     {
         Session session = packet.SessionContext as Session;
         if (session != null)
         {
             DebugPrint("Sending packet for {0}/{1} ({2}-->{3})\n",
                        session.RemoteAddress, session.RemotePort,
                        localMac, remoteMac);
         }
         else
         {
             DebugPrint("Sending packet to {0}\n", remoteMac);
         }
     }
     Debug.Assert(packet.IsOneChunk);
     EthernetFormat.Write((byte[] !)packet.GetRawData(), 0,
                          localMac, remoteMac,
                          EthernetFormat.PROTOCOL_IP);
     targetMux.SendBuffered(packet);
     return(NetStatus.Code.PROTOCOL_OK);
 }
예제 #9
0
        internal override void EnterEvent()
        {
            client.StartNewTransaction();

            DhcpFormat dhcp =
                new DhcpFormat(DhcpFormat.MessageType.Discover);

            dhcp.TransactionID = client.TransactionID;
            dhcp.SetHardwareAddress(client.MacAddress);

#if ADVERTISE_CLIENT_ID
            // Add Client Identifier for self
            //
            // [2006-02-03 ohodson] This is disabled because the Windows
            // DHCP server allocates us a different address with the
            // client id present if we networked booted.  Thus having the
            // identifier breaks static DHCP entries which we use
            // for test machines.
            EthernetAddress macAddress = client.MacAddress;
            dhcp.AddOption(DhcpClientID.Create(macAddress.GetAddressBytes()));
#endif

            // Add parameters we'd like to know about
            dhcp.AddOption(DhcpParameterRequest.Create(
                               DhcpClient.StandardRequestParameters
                               )
                           );
            // dhcp.AddOption(DhcpAutoConfigure.Create(0));
            client.Send(EthernetAddress.Broadcast, dhcp);
            client.ChangeState(new DhcpClientStateSelecting(client));
        }
예제 #10
0
        private void Respond(DhcpFormat request, DhcpFormat.MessageType m)
        {
            DhcpFormat response = new DhcpFormat(m);

            response.TransactionID = request.TransactionID;

            EthernetAddress hwAddress = request.GetHardwareAddress();

            response.SetHardwareAddress(hwAddress);

            switch (m)
            {
            case DhcpFormat.MessageType.Offer:
                response.NextServerIPAddress = ServerAddress;
                response.AddOption(
                    DhcpIPAddressLeaseTime.Create(RebindingTime)
                    );
                goto case DhcpFormat.MessageType.Ack;

            case DhcpFormat.MessageType.Ack:
                response.YourIPAddress = HostAddress;
                assignedAddress        = HostAddress;
                FillOptions(request, response);
                break;

            case DhcpFormat.MessageType.Nak:
                // Nothing to do
                break;

            default:
                return;
            }
            SendResponsePacket(response);
        }
예제 #11
0
        public void ArpRequest(IPv4 sourceIP,
                               IPv4 targetIP,
                               Multiplexer !targetMux,
                               ArpRequestCallback callback,
                               object cookie,
                               TimeSpan timeout)
        {
            //
            //XXXX Check pending request does not already exist!
            //
            EthernetAddress localMac = targetMux.Adapter.HardwareAddress;

            AddPendingRequest(targetIP, callback, cookie, timeout);

            // initiate an arp request...
            DebugPrint("Initiating request " +
                       "({0},{1}) --> ({2},{3})\n",
                       sourceIP, localMac, targetIP, EthernetAddress.Zero);

            byte[] data = new byte[ArpFormat.Size + EthernetFormat.Size];
            int    pos  = EthernetFormat.Write(data, 0, localMac,
                                               EthernetAddress.Broadcast,
                                               EthernetFormat.PROTOCOL_ARP);

            ArpFormat.Write(data, pos, localMac, sourceIP,
                            ArpFormat.Type.ARP_REQUEST, EthernetAddress.Zero,
                            targetIP);

            NetPacket pkt = new NetPacket(data);

            pkt.Mux = targetMux;
            OnProtocolSend(pkt);
        }
예제 #12
0
 public EthernetAddress GetHardwareAddress()
 {
     if (htype != (byte)HType.Ethernet)
     {
         // XXX Throw some nasty exception
     }
     return(EthernetAddress.ParseBytes(chaddr, 0));
 }
예제 #13
0
 public FrameHeader(EthernetAddress origin,
                    EthernetAddress target,
                    ushort protocol)
 {
     this.origin   = origin;
     this.target   = target;
     this.protocol = protocol;
 }
예제 #14
0
파일: Nic.cs 프로젝트: Paul1nh0/Singularity
        public Nic(NicDeviceContract /*.Imp*/ nicImp,
                   NicDeviceProperties np,
                   string nicName)
        {
            this.nicChannel = new TRef(nicImp);
            //assume np.DriverName != null;
            //assume np.MacAddress != null;
            this.driverName              = np.DriverName;
            this.driverVersion           = np.DriverName;
            this.macAddress              = np.MacAddress;
            this.nicName                 = nicName;
            this.mtu                     = np.MtuBytes;
            this.maxTxPacketsInDevice    = np.MaxTxPacketsInDevice;
            this.maxRxPacketsInDevice    = np.MaxRxPacketsInDevice;
            this.maxTxFragmentsPerPacket = np.MaxTxFragmentsPerPacket;
            this.maxRxFragmentsPerPacket = np.MaxRxFragmentsPerPacket;

            this.muxEvent = new AutoResetEvent(false);
            // The following attributes are both integers yet
            // sgc is complaining it doesn't know to use
            // Math.Min(sbyte, sbyte) or Math.Min(byte, byte).
            int rxFifoSize = Math.Min(np.MaxRxPacketsInDevice,
                                      (int)Nic.MaxRxPacketsInDevice);

            this.rxFifo =
                new ExRefPacketFifo(
                    new PacketFifo(rxFifoSize),
                    false
                    );

            // The following attributes are both integers yet
            // sgc is complaining it doesn't know to use
            // Math.Min(sbyte, sbyte) or Math.Min(byte, byte).
            int txFifoSize = Math.Min(np.MaxTxPacketsInDevice,
                                      (int)Nic.MaxTxPacketsInDevice);

            this.txFifo =
                new ExRefPacketFifo(
                    new PacketFifo(txFifoSize),
                    true
                    );

            this.txFreeFifo =
                new ExRefPacketFifo(
                    new PacketFifo(txFifoSize),
                    true
                    );

            this.txCoalesceFifo =
                new ExRefPacketFifo(
                    new PacketFifo(txFifoSize),
                    true
                    );

            TxProvision();
            RxProvision();
        }
예제 #15
0
        private void SetupMac()
        {
            uint ral, rah;

            // Setup our Ethernet address
            macAddress = GetMacFromEeprom();

            DebugStub.Print("Setting Ethernet Mac Address to " + macAddress + ". ");

            GetMacHiLow(out ral, out rah, macAddress);
            rah = rah | RahRegister.ADDRESS_VALID;
            Write32(Register.RAL0, ral);
            Write32(Register.RAH0, rah);

            // Clear the mutlicast table array
            for (uint i = 0; i < MtaRegister.MTA_LENGTH; i++)
            {
                Write32(Register.MTA_START + (4 * i), 0);
            }

            // Setup Descriptor buffers for rx
            ResetRxRingBuffer();

            // Setup Receiever Control flags
            Write32(Register.RECV_CTRL, (RecvCtrlBits.BROADCAST_ACCEPT |
                                         RecvCtrlBits.STRIP_CRC |
                                         RecvCtrlBits.LOOPBACK_MODE_DISABLE |
                                         RecvCtrlBits.MULTICAST_OFFSET_47_36 |
                                         RecvCtrlBits.BUFFER_SIZE_2KB |
                                         RecvCtrlBits.RECV_DESC_THRESHOLD_QUARTER));
            // Note: If MTU ever changes (e.g. for jumbo frames), the
            // recv buffer size will need to be increased.

            // Setup the rx interrupt delay
            Write32(Register.RECV_DELAY_TIMER, RxDelayTimers.RECV_DELAY_TIMER);
            Write32(Register.RECV_INT_ABS_TIMER, RxDelayTimers.RECV_ABSOLUTE_TIMER);

            // Enable IP and TCP checksum calculation offloading
            Write32(Register.RECV_CHECKSUM, (RecvChecksumBits.IP_CHECKSUM_ENABLE |
                                             RecvChecksumBits.TCP_CHECKSUM_ENABLE |
                                             RecvChecksumBits.IP6_CHECKSUM_ENABLE));

            // Setup Descriptor buffers for tx
            ResetTxRingBuffer();

            // Setup Transmit Control flags
            Write32(Register.TSMT_CTRL,
                    TsmtCtrlBits.PAD_SHORT_PACKETS |
                    TsmtCtrlBits.COLL_THRESHOLD_DEFAULT |
                    TsmtCtrlBits.COLL_DISTANCE_DEFAULT);

            // Setup Transmit Inter Frame Gap
            Write32(Register.TSMT_IPG, TsmtIpg.DEFAULT_IPG);

            // TODO enable transmit checksum offloading
        }
예제 #16
0
 // Write an Ethernet header assuming that the header begins at offset 0
 public static void Write(Bytes header,
                          EthernetAddress src,
                          EthernetAddress dst,
                          ushort type)
 {
     dst.CopyOut(header.Array, header.Start);
     src.CopyOut(header.Array, header.Start + EthernetAddress.Length);
     header[12] = (byte)(type >> 8);
     header[13] = (byte)(type & 0xff);
 }
예제 #17
0
 // parse "pkt" from "start" bytes in, and return the
 // "src" and "dst" Ethernet addresses, and the protocol
 // "type" Returns the byte offset of the next layer's
 // header.
 public static int Read(byte [] !pkt,
                        int start,
                        out EthernetAddress src,
                        out EthernetAddress dst,
                        out ushort type)
 {
     dst  = EthernetAddress.ParseBytes(pkt, start);
     src  = EthernetAddress.ParseBytes(pkt, start + 6);
     type = (ushort)((pkt[start + 12] << 8) | (pkt[start + 13]));
     return(start + 14);
 }
예제 #18
0
        public static bool Read(IBuffer !buf,
                                out EthernetAddress src,
                                out EthernetAddress dst,
                                out ushort type)
        {
            bool b;

            b  = buf.ReadEthernetAddress(out dst);
            b &= buf.ReadEthernetAddress(out src);
            b &= buf.ReadNet16(out type);
            return(b);
        }
예제 #19
0
 public bool ReadEthernetAddress(out EthernetAddress address)
 {
     try {
         address   = EthernetAddress.ParseBytes(data, position);
         position += EthernetAddress.Length;
     }
     catch (ArgumentException) {
         address = EthernetAddress.Zero;
         return(false);
     }
     return(true);
 }
예제 #20
0
 ///////////////////////////////////////////////////////////////////////
 //
 // Helper functions
 //
 internal void GetMacHiLow(out uint addr_low,
                           out uint addr_hi,
                           EthernetAddress mac)
 {
     byte[] macBytes = mac.GetAddressBytes();
     addr_hi = (uint)((macBytes[5] << 8) |
                      (macBytes[4]));
     addr_low = (uint)((macBytes[3] << 24) |
                       (macBytes[2] << 16) |
                       (macBytes[1] << 8) |
                       (macBytes[0]));
 }
예제 #21
0
        // an upper layer interface to get the mac
        // to a target IP. The upper protocol must
        // provide the Mux for the target IP.
        // if we have it then we return true + macAddress
        // and refresh the age to create a LRU list
        public bool Lookup(IPv4 targetIP, out EthernetAddress macAddress)
        {
            ArpEntry e = arpEntries[targetIP] as ArpEntry;

            if (e != null)
            {
                e.EntryAge = Age;
                macAddress = e.MacAddress;
                return(true);
            }
            macAddress = EthernetAddress.Zero;
            return(false);
        }
예제 #22
0
        // Write an Ethernet header to "pkt", starting at position "start".
        public static int Write(byte[] !pkt,
                                int start,
                                EthernetAddress src,
                                EthernetAddress dst,
                                ushort type)
        {
            dst.CopyOut(pkt, start);
            src.CopyOut(pkt, start + EthernetAddress.Length);

            pkt[start + 12] = (byte)(type >> 8);
            pkt[start + 13] = (byte)(type & 0xff);

            return(start + 14);
        }
예제 #23
0
        public ArpHeader(Bytes packet, ushort index)
        {
            //since this is already known to be an arp request
            //we skip the sanity checks...

            VTable.Assert(packet.Length - index >= 96);

            // check hardware type == 0x0001 (Ethernet)
            htype = NetworkBitConverter.ToUInt16(packet, index);
            DebugStub.Assert(htype == 0x001);
            index += 2;

            // check protocol type == 0x0800 (IP)
            ptype = NetworkBitConverter.ToUInt16(packet, index);
            DebugStub.Assert(ptype == 0x0800);
            index += 2;

            // check hardware address len is 6 bytes
            hlen = packet[index++];
            DebugStub.Assert(hlen == 6);


            // check IP address len is 4 bytes
            plen = packet[index++];
            DebugStub.Assert(plen == 4);

            op     = NetworkBitConverter.ToUInt16(packet, index);
            index += 2;

            senderEthernetAddr = EthernetAddress.ParseBytes(packet.Array, packet.Start + index);
            index += EthernetAddress.Length;

            uint addr = NetworkBitConverter.ToUInt32(packet, index);

            index       += 4;
            senderIPAddr = new IPv4(addr);


            destEthernetAddr = EthernetAddress.ParseBytes(packet.Array, packet.Start + index);
            index           += EthernetAddress.Length;

            addr       = NetworkBitConverter.ToUInt32(packet, index);
            index     += 4;
            destIPAddr = new IPv4(addr);
            //sgc complains
            pad0 = 0;
            pad1 = 0;
        }
예제 #24
0
        private void UpdatePendingRequests(IPv4 ipAddress,
                                           EthernetAddress macAddress)
        {
            int i = 0;

            while (i != pendingRequests.Count)
            {
                PendingRequest request = (PendingRequest !)pendingRequests[i];
                if (request.address == ipAddress)
                {
                    request.callback(ipAddress, macAddress, request.cookie);
                    pendingRequests.RemoveAt(i);
                    continue;
                }
                i++;
            }
        }
예제 #25
0
        internal bool Send(EthernetAddress dstAddr, DhcpFormat dhcp)
        {
            int   packetSize = dhcp.Size;
            int   headerSize = EthernetHeader.Size + UDPHeader.Size + IpHeader.Size;
            Bytes packet     = new Bytes(new byte [packetSize]);
            Bytes header     = new Bytes(new byte [headerSize]);

            // Write out DHCP packet
            dhcp.Write(packet, 0);
            //the correct ports/addresses should already be bound up in instance of the UDP object
            udp.WriteCompleteUDPHeader(header, packet, dhcp.Size);
            // Add Ethernet Header
            EthernetHeader.Write(header, adapter.HardwareAddress,
                                 dstAddr, EthernetHeader.PROTOCOL_IP);
            adapter.PopulateTxRing(header, packet);
            return(true);
        }
예제 #26
0
        internal bool Send(EthernetAddress dstAddr, DhcpFormat !dhcp)
        {
            int packetSize = dhcp.Size + UdpFormat.Size +
                             IPFormat.Size + EthernetFormat.Size;

            byte [] packet = new byte [packetSize];

            // Write out DHCP packet
            int dhcpSize   = dhcp.Size;
            int dhcpOffset = packet.Length - dhcpSize;

            dhcp.Write(packet, dhcpOffset);

            // Create UDP Header
            UdpFormat.UdpHeader udpHeader = new UdpFormat.UdpHeader();
            udpHeader.srcPort = DhcpFormat.ClientPort;
            udpHeader.dstPort = DhcpFormat.ServerPort;
            udpHeader.length  = (ushort)(UdpFormat.Size + dhcpSize);

            // Create IP Header
            IPFormat.IPHeader ipHeader = new NetStack.Protocols.IPFormat.IPHeader();
            ipHeader.SetDefaults(IPFormat.Protocol.UDP);
            IPFormat.SetDontFragBit(ipHeader);

            ipHeader.Source      = IPv4.Any;
            ipHeader.Destination = IPv4.Broadcast;
            ipHeader.totalLength = (ushort)(IPFormat.Size + UdpFormat.Size + dhcpSize);

            // Write out IP and Header
            int udpOffset = packet.Length - dhcp.Size - UdpFormat.Size;
            int ipOffset  = udpOffset - IPFormat.Size;

            UdpFormat.WriteUdpPacket(packet, ipOffset,
                                     ipHeader, ref udpHeader,
                                     packet, dhcpOffset, dhcpSize);

            // Add Ethernet Header
            EthernetFormat.Write(packet, 0, adapter.HardwareAddress,
                                 dstAddr, EthernetFormat.PROTOCOL_IP);

            NetPacket np = new NetPacket(packet);

            return(udpSession.WritePacket(np));
        }
예제 #27
0
        private void ArpResponse(IPv4 address,
                                 EthernetAddress answer,
                                 object cookie)
        {
            NetPacket !packet = (NetPacket !)cookie;
            DebugPrint("Got ARP response for {0} -> {1}", address, answer);

            UnblockAssociatedSession(packet);
            if (answer != EthernetAddress.Zero)
            {
                Multiplexer mux = (Multiplexer !)packet.Mux;
                SendResolved(packet, mux, mux.Adapter.HardwareAddress, answer);
                Core.Instance().SignalOutboundPackets();
            }
            else
            {
                DebugPrint("ARP timed out for {0}", address);
            }
        }
예제 #28
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testMultithreaded() throws InterruptedException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        public virtual void testMultithreaded()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.List<Thread> threads = new java.util.ArrayList<Thread>();
            IList <Thread> threads = new List <Thread>();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final com.fasterxml.uuid.impl.TimeBasedGenerator timeBasedGenerator = com.fasterxml.uuid.Generators.timeBasedGenerator(com.fasterxml.uuid.EthernetAddress.fromInterface());
            TimeBasedGenerator timeBasedGenerator = Generators.timeBasedGenerator(EthernetAddress.fromInterface());
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.ConcurrentSkipListSet<String> generatedIds = new java.util.concurrent.ConcurrentSkipListSet<String>();
            ConcurrentSkipListSet <string> generatedIds = new ConcurrentSkipListSet <string>();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.ConcurrentSkipListSet<String> duplicatedIds = new java.util.concurrent.ConcurrentSkipListSet<String>();
            ConcurrentSkipListSet <string> duplicatedIds = new ConcurrentSkipListSet <string>();

            for (int i = 0; i < THREAD_COUNT; i++)
            {
                Thread thread = new Thread(() =>
                {
                    for (int j = 0; j < LOOP_COUNT; j++)
                    {
                        string id     = timeBasedGenerator.generate().ToString();
                        bool wasAdded = generatedIds.add(id);
                        if (!wasAdded)
                        {
                            duplicatedIds.add(id);
                        }
                    }
                });
                threads.Add(thread);
                thread.Start();
            }

            foreach (Thread thread in threads)
            {
                thread.Join();
            }

            Assert.assertEquals(THREAD_COUNT * LOOP_COUNT, generatedIds.size());
            Assert.assertTrue(duplicatedIds.Empty);
        }
예제 #29
0
        public LoopbackAdapter()
        {
            LoopbackAdapter.instantiations++;

            //
            // Microsoft OUI 00:50:F2:xx:xx:xx
            // It doesn't really matter, but something other
            // than zero is preferable for testing purposes.
            //
            int x = 0xFFFFFF - instantiations;

            address = new EthernetAddress(0x00, 0x50, 0xF2,
                                          (byte)((x >> 16) & 0xFF),
                                          (byte)((x >> 8) & 0xFF),
                                          (byte)((x >> 0) & 0xFF));

            writeEvent = new AutoResetEvent(false);
            readEvent  = new AutoResetEvent(false);

            rxBuffer           = new Queue(LoopbackAdapter.RingSize);
            txDeliveryComplete = 0;
            rxAvailable        = 0;
        }
예제 #30
0
        private AutoResetEvent AddPendingRequest(IPv4 address,
                                                 TimeSpan timeout,
                                                 EthernetAddress localMac,
                                                 Bytes header,
                                                 Bytes buffer,
                                                 IAdapter adapter
                                                 )
        {
            PendingArpRequest pendingRequest = (PendingArpRequest)pendingRequestsFreelist.Dequeue();

            VTable.Assert(pendingRequest != null);
            pendingRequest.address  = address;
            pendingRequest.active   = true;
            pendingRequest.localMac = localMac;
            pendingRequest.adapter  = adapter;
            VectorQueueByte txBuffer = pendingRequest.txContainer.Acquire();

            txBuffer.AddTail(header);
            txBuffer.AddTail(buffer);
            pendingRequest.txContainer.Release(txBuffer);

            using (pendingRequestsLock.Lock()) {
                pendingRequests.Enqueue(pendingRequest);
            }

            SchedulerTime expiration = SchedulerTime.Now;

            expiration = expiration.Add(timeout);
            pendingRequest.requestExpiration = expiration;

            //poke the wait thread
            if (pendingRequests.Count == 1)
            {
                arpHandle.Set();
            }
            return(pendingRequest.requestEvent);
        }