A Configuration class for the DHCP Lease Controller
Exemplo n.º 1
0
        public static DHCPConfig BasicConfig()
        {
            DHCPConfig config = new DHCPConfig();

            config.LeaseTime = 10;
            config.Namespace = "Test";
            return(config);
        }
Exemplo n.º 2
0
        ///<summary>Creates a DhtIpopNode.</summary>
        /// <param name="NodeConfig">NodeConfig object</param>
        /// <param name="IpopConfig">IpopConfig object</param>
        public DhtIpopNode(NodeConfig node_config, IpopConfig ipop_config,
        DHCPConfig dhcp_config)
            : base(node_config, ipop_config, dhcp_config)
        {
            _address_resolver = new DhtAddressResolver(Dht, _ipop_config.IpopNamespace);

              _connected = false;
              Brunet.StateChangeEvent += StateChangeHandler;
              StateChangeHandler(Brunet, Brunet.ConState);
        }
Exemplo n.º 3
0
    ///<summary>Creates a DhtIpopNode.</summary>
    /// <param name="NodeConfig">NodeConfig object</param>
    /// <param name="IpopConfig">IpopConfig object</param>
    public DhtIpopNode(NodeConfig node_config, IpopConfig ipop_config,
        DHCPConfig dhcp_config) : base(node_config, ipop_config, dhcp_config)
    {
      DhtAddressResolver dar = new DhtAddressResolver(AppNode.Dht, _ipop_config.IpopNamespace);
      Shutdown.OnExit += dar.Stop;
      _address_resolver = dar;

      _connected = false;
      AppNode.Node.StateChangeEvent += StateChangeHandler;
      StateChangeHandler(AppNode.Node, AppNode.Node.ConState);
    }
Exemplo n.º 4
0
        /// <summary></summary>
        public DhcpServer(DHCPConfig config)
        {
            Config = config;
              Netmask = Utils.StringToBytes(config.Netmask, '.');
              BaseIP = Utils.StringToBytes(config.IPBase, '.');

              // just in case someone is cute
              for(int i = 0; i < BaseIP.Length; i++) {
            BaseIP[i] = (byte) (Netmask[i] & BaseIP[i]);
              }

              if(config.ReservedIPs != null) {
            _reserved_ips = new byte[config.ReservedIPs.Length + 2][];
            _reserved_masks = new byte[config.ReservedIPs.Length + 2][];
            for(int i = 0; i < config.ReservedIPs.Length; i++) {
              _reserved_ips[i] = Utils.StringToBytes(config.ReservedIPs[i].IPBase, '.');
              _reserved_masks[i] = Utils.StringToBytes(config.ReservedIPs[i].Mask, '.');
            }
              } else {
            _reserved_ips = new byte[2][];
            _reserved_masks = new byte[2][];
              }

              // reserve broadcast and server ip
              int last = _reserved_ips.Length - 1;
              int slast = last - 1;
              _reserved_ips[last] = new byte[4];
              _reserved_ips[slast] = new byte[4];

              for(int i = 0; i < 4; i++) {
            _reserved_ips[slast][i] = (byte) (BaseIP[i] | ~Netmask[i]);
              }

              Broadcast = _reserved_ips[slast];
              ServerIP = new byte[4];
              BaseIP.CopyTo(ServerIP, 0);
              ServerIP[3] = 1;
              _reserved_ips[last] = BaseIP;
              _reserved_masks[last] = new byte[4] {255, 255, 255, 254};
              _reserved_masks[slast] = new byte[4] {255, 255, 255, 255};

              _mtu = MemBlock.Reference(new byte[2] {
              (byte) ((MTU >> 8) & 0xFF),
              (byte) (MTU & 0xFF)
            });

              _lease_time = MemBlock.Reference(new byte[4] {
              (byte) (Config.LeaseTime >> 24),
              (byte) (Config.LeaseTime >> 16),
              (byte) (Config.LeaseTime >> 8),
              (byte) (Config.LeaseTime),
            });
        }
Exemplo n.º 5
0
        public void Test()
        {
            DHCPConfig config = BasicConfig();

            config.Netmask               = "128.0.0.0";
            config.IPBase                = "128.0.0.0";
            config.ReservedIPs           = new DHCPConfig.ReservedIP[1];
            config.ReservedIPs[0]        = new DHCPConfig.ReservedIP();
            config.ReservedIPs[0].IPBase = "130.0.0.0";
            config.ReservedIPs[0].Mask   = "255.0.0.0";

            TestDhcpServer ds = new TestDhcpServer(config);

            byte[] ip = new byte[4] {
                128, 0, 0, 1
            };

            Assert.IsFalse(ds.ValidIP(ip), "Server IP");
            ip[0] = 129;
            Assert.IsTrue(ds.ValidIP(ip), "Non-Server IP");

            ip = new byte[4] {
                130, 0, 0, 0
            };
            ip[0] = 130;
            byte[] inc = ds.IncrementIP(ip);
            ip[0] = 131;
            Assert.AreEqual(MemBlock.Reference(ip), MemBlock.Reference(inc), "Invalid IPs before the first valid one");

            ip[0] = 255;
            ip[1] = 255;
            ip[2] = 255;
            ip[3] = 254;
            inc   = ds.IncrementIP(ip);
            ip[0] = 128;
            ip[1] = 0;
            ip[2] = 0;
            ip[3] = 2;
            Assert.AreEqual(MemBlock.Reference(ip), MemBlock.Reference(inc), "Skip broadcast and server");

            ip[0] = 127;
            Assert.IsFalse(ds.ValidIP(ip), "Out of range - 127");
            ip[0] = 0;
            Assert.IsFalse(ds.ValidIP(ip), "Out of range - 0");

            Assert.IsTrue(ds.ValidIP(ds.RandomIPAddress()), "Random");
        }
Exemplo n.º 6
0
        /// <summary></summary>
        public DhcpServer(DHCPConfig config)
        {
            Config  = config;
            Netmask = Utils.StringToBytes(config.Netmask, '.');
            BaseIP  = Utils.StringToBytes(config.IPBase, '.');

            // just in case someone is cute
            for (int i = 0; i < BaseIP.Length; i++)
            {
                BaseIP[i] = (byte)(Netmask[i] & BaseIP[i]);
            }

            if (config.ReservedIPs != null)
            {
                _reserved_ips   = new byte[config.ReservedIPs.Length + 2][];
                _reserved_masks = new byte[config.ReservedIPs.Length + 2][];
                for (int i = 0; i < config.ReservedIPs.Length; i++)
                {
                    _reserved_ips[i]   = Utils.StringToBytes(config.ReservedIPs[i].IPBase, '.');
                    _reserved_masks[i] = Utils.StringToBytes(config.ReservedIPs[i].Mask, '.');
                }
            }
            else
            {
                _reserved_ips   = new byte[2][];
                _reserved_masks = new byte[2][];
            }

            // reserve broadcast and server ip
            int last  = _reserved_ips.Length - 1;
            int slast = last - 1;

            _reserved_ips[last]  = new byte[4];
            _reserved_ips[slast] = new byte[4];

            for (int i = 0; i < 4; i++)
            {
                _reserved_ips[slast][i] = (byte)(BaseIP[i] | ~Netmask[i]);
            }

            Broadcast = _reserved_ips[slast];
            ServerIP  = new byte[4];
            BaseIP.CopyTo(ServerIP, 0);
            ServerIP[3]           = 1;
            _reserved_ips[last]   = BaseIP;
            _reserved_masks[last] = new byte[4] {
                255, 255, 255, 254
            };
            _reserved_masks[slast] = new byte[4] {
                255, 255, 255, 255
            };

            _mtu = MemBlock.Reference(new byte[2] {
                (byte)((MTU >> 8) & 0xFF),
                (byte)(MTU & 0xFF)
            });

            _lease_time = MemBlock.Reference(new byte[4] {
                (byte)(Config.LeaseTime >> 24),
                (byte)(Config.LeaseTime >> 16),
                (byte)(Config.LeaseTime >> 8),
                (byte)(Config.LeaseTime),
            });
        }
Exemplo n.º 7
0
 public TestDhcpServer(DHCPConfig config) : base(config)
 {
 }
Exemplo n.º 8
0
 public TestDhcpServer(DHCPConfig config)
     : base(config)
 {
 }
Exemplo n.º 9
0
 public static DHCPConfig BasicConfig()
 {
     DHCPConfig config = new DHCPConfig();
       config.LeaseTime = 10;
       config.Namespace = "Test";
       return config;
 }
Exemplo n.º 10
0
 /**
 <summary>Creates a DhtDhcpLeaseController for a specific namespace</summary>
 <param name="dht">The dht object use to store lease information.</param>
 <param name="config">The DHCPConfig used to define the Lease
 parameters.</param>
 <param name="EnableMulticast">Defines if Multicast is to be enabled during
 the lease.</param>
 */
 public DhtDhcpServer(IDht dht, DHCPConfig config, bool EnableMulticast) :
   base(config)
 {
   _dht = dht;
   _multicast = EnableMulticast;
 }
Exemplo n.º 11
0
        /// <summary>Creates an IpopNode given a NodeConfig and an IpopConfig.
        /// Also sets up the Information, Ethernet device, and subscribes
        /// to Brunet for IP Packets</summary>
        /// <param name="node_config">The path to a NodeConfig xml file</param>
        /// <param name="ipop_config">The path to a IpopConfig xml file</param>
        public IpopNode(NodeConfig node_config, IpopConfig ipop_config,
        DHCPConfig dhcp_config)
            : base(node_config)
        {
            CreateNode();
              this.Brunet = _node;
              _ipop_config = ipop_config;

              Ethernet = new Ethernet(_ipop_config.VirtualNetworkDevice);
              Ethernet.Subscribe(this, null);

              _info = new Information(Brunet, "IpopNode");
              _info.UserData["IpopNamespace"] = _ipop_config.IpopNamespace;

              if(_ipop_config.EndToEndSecurity && _bso != null) {
            _secure_senders = true;
              } else {
            _secure_senders = false;
              }
              Brunet.GetTypeSource(PType.Protocol.IP).Subscribe(this, null);

              _sync = new object();
              _lock = 0;

              _ether_to_ip = new Dictionary<MemBlock, MemBlock>();
              _ip_to_ether = new Dictionary<MemBlock, MemBlock>();

              _dhcp_server_port = _ipop_config.DHCPPort != 0 ? _ipop_config.DHCPPort : 67;
              _dhcp_client_port = _dhcp_server_port + 1;
              ProtocolLog.WriteIf(IpopLog.DHCPLog, String.Format(
              "Setting DHCP Ports to: {0},{1}", _dhcp_server_port, _dhcp_client_port));
              _ether_to_dhcp_server = new Dictionary<MemBlock, DHCPServer>();
              _static_mapping = new Dictionary<MemBlock, SimpleTimer>();
              _dhcp_config = dhcp_config;
              if(_dhcp_config != null) {
            SetDNS();
            _dhcp_server = GetDHCPServer();
              }
              _checked_out = new Hashtable();

              Brunet.HeartBeatEvent += CheckNode;
              _last_check_node = DateTime.UtcNow;
        }
Exemplo n.º 12
0
    /// <summary>Creates an IpopNode given a NodeConfig and an IpopConfig.
    /// Also sets up the Information, Ethernet device, and subscribes
    /// to Brunet for IP Packets</summary>
    /// <param name="node_config">The path to a NodeConfig xml file</param>
    /// <param name="ipop_config">The path to a IpopConfig xml file</param>
    public IpopNode(NodeConfig node_config, IpopConfig ipop_config,
        DHCPConfig dhcp_config) : base(node_config)
    {
      PublicNode = CreateNode(node_config);
      PublicNode.Node.DisconnectOnOverload = false;
      if(PublicNode.PrivateNode == null) {
        AppNode = PublicNode;
      } else {
        AppNode = PublicNode.PrivateNode;
        AppNode.Node.DisconnectOnOverload = false;
      }

      _ipop_config = ipop_config;

      Ethernet = new Ethernet(_ipop_config.VirtualNetworkDevice);
      Ethernet.Subscribe(this, null);

      Info = new Information(AppNode.Node, "IpopNode", AppNode.SecurityOverlord);
      Info.UserData["IpopNamespace"] = _ipop_config.IpopNamespace;
      if(PublicNode == AppNode) {
        PublicInfo = Info;
      } else {
        PublicInfo = new Information(PublicNode.Node, "PrivateIpopNode",
            PublicNode.SecurityOverlord);
        PublicInfo.UserData["IpopNamespace"] = _ipop_config.IpopNamespace;
      }

      if(_ipop_config.EndToEndSecurity && !AppNode.Config.Security.SecureEdges &&
          AppNode.Config.Security.Enabled)
      {
        _conn_handler = new Brunet.Security.PeerSec.Symphony.SecureConnectionHandler(
            PType.Protocol.IP, AppNode.Node, AppNode.SymphonySecurityOverlord);
      } else {
        _conn_handler = new ConnectionHandler(PType.Protocol.IP, AppNode.Node);
      }
      _conn_handler.Subscribe(this, null);

      _sync = new object();
      _lock = 0;

      _ether_to_ip = new Dictionary<MemBlock, MemBlock>();
      _ip_to_ether = new Dictionary<MemBlock, MemBlock>();

      _dhcp_server_port = _ipop_config.DHCPPort != 0 ? _ipop_config.DHCPPort : 67;
      _dhcp_client_port = _dhcp_server_port + 1;
      ProtocolLog.WriteIf(IpopLog.DhcpLog, String.Format(
          "Setting Dhcp Ports to: {0},{1}", _dhcp_server_port, _dhcp_client_port));
      _ether_to_dhcp_server = new Dictionary<MemBlock, DhcpServer>();
      _static_mapping = new Dictionary<MemBlock, SimpleTimer>();
      _dhcp_config = dhcp_config;
      if(_dhcp_config != null) {
        SetDns();
        SetTAAuth();
        _dhcp_server = GetDhcpServer();
      }
      _checked_out = new Hashtable();

      AppNode.Node.HeartBeatEvent += CheckNode;
      _last_check_node = DateTime.UtcNow;

      AppNode.Node.Rpc.AddHandler("Ipop", this);
    }
Exemplo n.º 13
0
        /// <summary>Creates an IpopNode given a NodeConfig and an IpopConfig.
        /// Also sets up the Information, Ethernet device, and subscribes
        /// to Brunet for IP Packets</summary>
        /// <param name="node_config">The path to a NodeConfig xml file</param>
        /// <param name="ipop_config">The path to a IpopConfig xml file</param>
        public IpopNode(NodeConfig node_config, IpopConfig ipop_config,
                        DHCPConfig dhcp_config) : base(node_config)
        {
            PublicNode = CreateNode(node_config);
            PublicNode.Node.DisconnectOnOverload = false;
            if (PublicNode.PrivateNode == null)
            {
                AppNode = PublicNode;
            }
            else
            {
                AppNode = PublicNode.PrivateNode;
                AppNode.Node.DisconnectOnOverload = false;
            }

            _ipop_config = ipop_config;

            Ethernet = new Ethernet(_ipop_config.VirtualNetworkDevice);
            Ethernet.Subscribe(this, null);

            Info = new Information(AppNode.Node, "IpopNode", AppNode.SecurityOverlord);
            Info.UserData["IpopNamespace"] = _ipop_config.IpopNamespace;
            if (PublicNode == AppNode)
            {
                PublicInfo = Info;
            }
            else
            {
                PublicInfo = new Information(PublicNode.Node, "PrivateIpopNode",
                                             PublicNode.SecurityOverlord);
                PublicInfo.UserData["IpopNamespace"] = _ipop_config.IpopNamespace;
            }

            if (_ipop_config.EndToEndSecurity && !AppNode.Config.Security.SecureEdges &&
                AppNode.Config.Security.Enabled)
            {
                _conn_handler = new Brunet.Security.PeerSec.Symphony.SecureConnectionHandler(
                    PType.Protocol.IP, AppNode.Node, AppNode.SymphonySecurityOverlord);
            }
            else
            {
                _conn_handler = new ConnectionHandler(PType.Protocol.IP, AppNode.Node);
            }
            _conn_handler.Subscribe(this, null);

            _sync = new object();
            _lock = 0;

            _ether_to_ip = new Dictionary <MemBlock, MemBlock>();
            _ip_to_ether = new Dictionary <MemBlock, MemBlock>();

            _dhcp_server_port = _ipop_config.DHCPPort != 0 ? _ipop_config.DHCPPort : 67;
            _dhcp_client_port = _dhcp_server_port + 1;
            ProtocolLog.WriteIf(IpopLog.DhcpLog, String.Format(
                                    "Setting Dhcp Ports to: {0},{1}", _dhcp_server_port, _dhcp_client_port));
            _ether_to_dhcp_server = new Dictionary <MemBlock, DhcpServer>();
            _static_mapping       = new Dictionary <MemBlock, SimpleTimer>();
            _dhcp_config          = dhcp_config;
            if (_dhcp_config != null)
            {
                SetDns();
                SetTAAuth();
                _dhcp_server = GetDhcpServer();
            }
            _checked_out = new Hashtable();

            AppNode.Node.HeartBeatEvent += CheckNode;
            _last_check_node             = DateTime.UtcNow;

            AppNode.Node.Rpc.AddHandler("Ipop", this);
        }
Exemplo n.º 14
0
        /// <summary>Creates an IpopNode given a NodeConfig and an IpopConfig.
        /// Also sets up the Information, Ethernet device, and subscribes
        /// to Brunet for IP Packets</summary>
        /// <param name="node_config">The path to a NodeConfig xml file</param>
        /// <param name="ipop_config">The path to a IpopConfig xml file</param>
        public IpopNode(NodeConfig node_config, IpopConfig ipop_config,
        DHCPConfig dhcp_config)
            : base(node_config)
        {
            AppNode = CreateNode(node_config);
              AppNode.Node.DisconnectOnOverload = false;
              _chota = AppNode.Node.Cco;
              _ipop_config = ipop_config;

              Ethernet = new Ethernet(_ipop_config.VirtualNetworkDevice);
              Ethernet.Subscribe(this, null);

              Info = new Information(AppNode.Node, "IpopNode");
              Info.UserData["IpopNamespace"] = _ipop_config.IpopNamespace;

              if(_ipop_config.EndToEndSecurity && AppNode.SecurityOverlord != null) {
            _secure_senders = true;
              } else {
            _secure_senders = false;
              }
              AppNode.Node.GetTypeSource(PType.Protocol.IP).Subscribe(this, null);

              _sync = new object();
              _lock = 0;

              _ether_to_ip = new Dictionary<MemBlock, MemBlock>();
              _ip_to_ether = new Dictionary<MemBlock, MemBlock>();

              _dhcp_server_port = _ipop_config.DHCPPort != 0 ? _ipop_config.DHCPPort : 67;
              _dhcp_client_port = _dhcp_server_port + 1;
              ProtocolLog.WriteIf(IpopLog.DhcpLog, String.Format(
              "Setting Dhcp Ports to: {0},{1}", _dhcp_server_port, _dhcp_client_port));
              _ether_to_dhcp_server = new Dictionary<MemBlock, DhcpServer>();
              _static_mapping = new Dictionary<MemBlock, SimpleTimer>();
              _dhcp_config = dhcp_config;
              if(_dhcp_config != null) {
            SetDns();
            _dhcp_server = GetDhcpServer();
              }
              _checked_out = new Hashtable();

              AppNode.Node.HeartBeatEvent += CheckNode;
              _last_check_node = DateTime.UtcNow;

              AppNode.Node.Rpc.AddHandler("Ipop", this);
        }
Exemplo n.º 15
0
 ///<summary>Creates a DhtIpopNode.</summary>
 /// <param name="NodeConfig">NodeConfig object</param>
 /// <param name="IpopConfig">IpopConfig object</param>
 public DhtIpopNode(NodeConfig node_config, IpopConfig ipop_config,
 DHCPConfig dhcp_config)
     : base(node_config, ipop_config, dhcp_config)
 {
     _address_resolver = new DhtAddressResolver(Dht, _ipop_config.IpopNamespace);
 }