// IProtocol interfaces
        // ------------------------
        public bool Initialize(ProtocolParams parameters)
        {
            Debug.Assert(parameters == null ||
                         parameters["name"] == moduleName);

            hostConfig = new HostConfiguration();
            version    = ProtocolParams.LookupInt32(parameters, "version", 4);

            bool fragment = ProtocolParams.LookupBoolean(parameters,
                                                         "fragment",
                                                         false);

            // save the routing protocol name, if exists
            if (version != 4 || fragment == true)
            {
                DebugPrint("Support only exists for V4 w/o fragments.\n");
                return(false);
            }

            Core core = Core.Instance();

            core.RegisterProtocol(this);
            if (!core.packetTypes.RegisterTypeHandler(PacketTypes.IP, this))
            {
                core.DeregisterProtocol(this);
                return(false);
            }
            return(true);
        }
Exemple #2
0
        // IProtocol interfaces
        // ------------------------
        public bool Initialize(ProtocolParams parameters)
        {
            Debug.Assert(parameters == null || parameters["name"] == "ARP");

            int size = ProtocolParams.LookupInt32(parameters, "cacheSize",
                                                  128);
            int age = ProtocolParams.LookupInt32(parameters, "max-age",
                                                 ArpTable.MaxAge);

            arpTable        = new ArpTable(size, age, this);
            pendingRequests = new ArrayList();

            Core core = Core.Instance();

            core.RegisterProtocol(this);
            if (!core.packetTypes.RegisterTypeHandler(PacketTypes.ARP, this))
            {
                core.DeregisterProtocol(this);
                return(false);
            }
            return(true);
        }
        // loads an adapter's driver and add the relevant data structures
        // for managing it.
        protected bool LoadAdapter(ProtocolParams args, string driversPath)
        {
            // the user can ignore an adapter
            // so ignore it...
            string ignore = args["ignore"];

            if (ignore != null && ignore == "true")
            {
                return(true);
            }

            string name =
                ProtocolParams.LookupString(args, "name", "unknown");
            string typeName =
                ProtocolParams.LookupString(args, "type", "unknown");
            string id =
                ProtocolParams.LookupString(args, "id", "unknown");

            int mtu = ProtocolParams.LookupInt32(args, "mtu",
                                                 EthernetFormat.MaxFrameSize);
            int txRing  = ProtocolParams.LookupInt32(args, "txRing", 64);
            int rxRing  = ProtocolParams.LookupInt32(args, "rxRing", 64);
            int fwQueue = ProtocolParams.LookupInt32(args, "fwQueue", 64);

            IAdapterFactory factory = null;
            IAdapter        adapter = null;

            try {
                string   factoryTypeName = typeName + "Factory";
                Assembly assembly        = Assembly.LoadFrom(driversPath);
                Type[]   types           = assembly.GetTypes();
                foreach (Type t in types)
                {
                    if (t.IsClass && t.Name.Equals(typeName))
                    {
                        factory = (IAdapterFactory)Activator.CreateInstance(t, null);
                        break;
                    }
                    if (factory == null)
                    {
                        throw new Exception("Can't find Adapter's Factory.");
                    }

                    adapter = factory.CreateAdapter(name, id, txRing, rxRing);
                    Core.Instance().RegisterAdapter(adapter, fwQueue);
                }
            }
            catch (Exception e) {
                adapter = null;
                Console.Out.WriteLine(e.Message);
                Environment.Exit(1);
            }

            IPModule          ipModule   = Core.Instance().GetProtocolByName("IP") as IPModule;
            HostConfiguration hostConfig = ipModule.HostConfiguration;

            for (int i = 0;; i++)
            {
                string ipTag      = String.Format("ip{0}", i);
                string maskTag    = String.Format("mask{0}", i);
                string gatewayTag = String.Format("gateway{0}", i);

                // XXX No point-to-point support here.
                IPv4 address = ProtocolParams.LookupIPv4(args, ipTag,
                                                         IPv4.AllOnes);
                IPv4 netmask = ProtocolParams.LookupIPv4(args, maskTag,
                                                         IPv4.AllOnes);
                IPv4 gateway = ProtocolParams.LookupIPv4(args, gatewayTag,
                                                         IPv4.Zero);
                if (address == IPv4.AllOnes || netmask == IPv4.AllOnes)
                {
                    break;
                }
                hostConfig.Bindings.Add(adapter,
                                        new InterfaceIPConfiguration(address, netmask, gateway, 128)
                                        );
            }

#if DEBUG
            System.Console.Out.WriteLine("[Interface {0}]", args["name"]);
            System.Console.Out.WriteLine("-----------------------------");
#endif
            return(true);
        }