Esempio n. 1
0
        private void TxExchange()
        {
            int toCount   = 0;
            int fromCount = 0;

            NicDeviceContract /*.Imp*/ imp = (NicDeviceContract)nicChannel.Acquire();

            try {
                PacketFifo src  = this.txFifo.Acquire();
                PacketFifo free = this.txFreeFifo.Acquire();

                toCount = src.Count;
                try {
                    src = imp.GiveTxPacketsToDevice(src);

                    fromCount = src.Count;
                    free.Push(src);
                }
                finally {
                    this.txFreeFifo.Release(free);
                    this.txFifo.Release(src);
                }
            }
            catch (Exception e) {
                DebugStub.Print("TxExchange FAILED arg {0}\n", DebugStub.ArgList(e.ToString()));
                DebugStub.Break();
            }
            finally {
                nicChannel.Release(imp);
            }
            DebugPrint("TxExchange out: {0} in: {1}\n",
                       toCount, fromCount);
        }
Esempio n. 2
0
        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();
        }
Esempio n. 3
0
        private void RxExchange()
        {
            NicDeviceContract /*.Imp*/ imp = (NicDeviceContract)nicChannel.Acquire();

            try {
                RxExchangeInternal(imp);
            }
            finally {
                this.nicChannel.Release(imp);
            }
        }
Esempio n. 4
0
        private bool StopIO()
        {
            NicDeviceContract /*.Imp*/ imp = (NicDeviceContract)nicChannel.Acquire();

            try {
                imp.StopIO();
                return(true);
            }
            finally {
                nicChannel.Release(imp);
            }
            //return false;
        }
Esempio n. 5
0
        private bool StartIO()
        {
            NicDeviceContract /*.Imp*/ imp = (NicDeviceContract)nicChannel.Acquire();

            try {
                imp.StartIO();
                RxExchangeInternal(imp);
                return(true);
            }
            finally {
                nicChannel.Release(imp);
            }
            //DebugStub.Break();
            //return false;
        }
Esempio n. 6
0
        //XXX On the first exchange we receive an empty fifo from the Nic
        //We fill it here...this should be special cased in the startio
        //routine...
        private void RxExchangeInternal(NicDeviceContract /*.Imp*/ imp)
        {
            int        toCount, fromCount;
            PacketFifo exFifo = this.rxFifo.Acquire();

            toCount = exFifo.Count;
            try {
                exFifo    = imp.GiveRxPacketsToDevice(exFifo);
                fromCount = exFifo.Count;
            }
            finally {
                this.rxFifo.Release(exFifo);
            }
            DebugPrint("RxExchange out: {0} in: {1}\n",
                       toCount, fromCount);
        }
Esempio n. 7
0
        CreateAndRegister(NicDeviceContract /*.Imp*/ imp,
                          string nicName)
        {
            Nic nic = null;

            try {
                //imp.RecvSuccess();
                DebugPrint("Nic channel transition\n");

                NicDeviceProperties np = GetNicProperties(imp);
                if (np == null)
                {
                    //delete imp;
                    return(false);
                }

                nic = new Nic(imp, np, nicName);
                //delete np;
                if (nic.Configure() == false)
                {
                    return(false);
                }

                DebugPrint("Nic.cs: Register adapter\n");
                HostConfiguration hostConfiguration = IP.GetHostConfiguration();
//                nic.filterAdapter= null;
#if false
                nic.filterAdapter = new FilterAdapter(nic);
                hostConfiguration.RegisterAdapter(nic.filterAdapter);
#endif

                hostConfiguration.RegisterAdapter(nic);

                nic.StartIO();

                Thread muxThread = new Thread(nic);
                muxThread.Start();


                return(true);
            }
            catch {
                //delete imp;
                DebugStub.Break();
                return(false);
            }
        }
Esempio n. 8
0
        bool Start()
        {
            try {
                ipManager.Start();
                routingManager.Start();

                for (int i = 0; i < nicRefs.Length; i++)
                {
                    NicDeviceContract /*.Imp*/ imp = (nicRefs[i]).Acquire();
                    Nic.CreateAndRegister(imp, String.Format("/dev/nic{0}", i));
                }

                return(true);
            }
            catch (Exception ex) {
                Dbg("An exception occurred during service startup: " + ex.Message);
                return(false);
            }
        }
Esempio n. 9
0
        internal static int AppMain(ServiceParameters parameters)
        {
            NicDeviceContract /*.Imp*/ nicImp = parameters.NicEndpointRef.Acquire();

            nicImp.RecvSuccess();
            //delete nicImp;
            DebugStub.WriteLine("Closed nic contract via reflection\n");

            ARP arp = new ARP();

            IP.Initialize(arp);
            Ethernet.Initialize(arp);

            NetStackApplication app = new NetStackApplication(parameters);

            try {
                return(app.Run());
            }
            finally {
                //delete app;
                Dbg("NetStack is terminating.");
            }
        }
Esempio n. 10
0
        private bool Configure()
        {
            NicDeviceContract /*.Imp*/ nicImp = (NicDeviceContract)nicChannel.Acquire();

            try {
                nicImp.ConfigureIO();
                if (ConfigureEventChannel(nicImp) == true &&
                    ConfigureChecksumProperties(nicImp) == true)
                {
                    return(true);
                }
            }
            catch (SystemException e) {
                DebugStub.WriteLine("System exception occurred in Nic.Configure().");
                DebugStub.WriteLine(e.ToString());
                DebugStub.Break();
            }
            finally {
                nicChannel.Release(nicImp);
            }
            DebugStub.Break();
            return(false);
        }
Esempio n. 11
0
 GetNicProperties(NicDeviceContract /*.Imp*/ imp)
 {
     return(imp.GetDeviceProperties());
 }
Esempio n. 12
0
 ConfigureChecksumProperties(NicDeviceContract /*.Imp*/ nicImp)
 {
     nicImp.SetChecksumProperties(0);
     return(true);
 }
Esempio n. 13
0
 ConfigureEventChannel(NicDeviceContract nicImp)
 {
     nicImp.RegisterForEvents(this);
     return(true);
 }