![]() |
User Manual, Developers Guide and API Documentation |
![]() |
00001 /******************************************************************************* 00002 * This file is part of openWNS (open Wireless Network Simulator) 00003 * _____________________________________________________________________________ 00004 * 00005 * Copyright (C) 2004-2007 00006 * Chair of Communication Networks (ComNets) 00007 * Kopernikusstr. 5, D-52074 Aachen, Germany 00008 * phone: ++49-241-80-27910, 00009 * fax: ++49-241-80-22242 00010 * email: info@openwns.org 00011 * www: http://www.openwns.org 00012 * _____________________________________________________________________________ 00013 * 00014 * openWNS is free software; you can redistribute it and/or modify it under the 00015 * terms of the GNU Lesser General Public License version 2 as published by the 00016 * Free Software Foundation; 00017 * 00018 * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY 00019 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 00020 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00021 * details. 00022 * 00023 * You should have received a copy of the GNU Lesser General Public License 00024 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00025 * 00026 ******************************************************************************/ 00027 00028 #include <IP/VirtualDHCP.hpp> 00029 #include <WNS/module/Base.hpp> 00030 #include <WNS/logger/Logger.hpp> 00031 00032 using namespace ip; 00033 00034 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00035 VirtualDHCP, 00036 wns::node::component::Interface, 00037 "ip.VDHCP", 00038 wns::node::component::ConfigCreator); 00039 00040 VirtualDHCPService::VirtualDHCPService(): 00041 log("IP", "VDHCP", wns::simulator::getMasterLogger()) 00042 { 00043 MESSAGE_SINGLE(NORMAL, log, "Starting VDHCP Service."); 00044 } 00045 00046 void 00047 VirtualDHCPService::addSubnet(std::string subnetIdentifier, 00048 VirtualDHCP* server) 00049 { 00050 servers.insert(subnetIdentifier, server); 00051 } 00052 00053 VirtualDHCP* 00054 VirtualDHCPService::getZoneManager(std::string subnetIdentifier) 00055 { 00056 return servers.find(subnetIdentifier); 00057 } 00058 00059 VirtualDHCP::VirtualDHCP(wns::node::Interface* _node, const wns::pyconfig::View& _pyco) : 00060 wns::node::component::Component(_node, _pyco), 00061 log(_pyco.get("logger")), 00062 ipPool(_pyco.get<simTimeType>("unbindDelay"), 00063 VirtualDHCP::Address(_pyco.get<std::string>("startAddress")), 00064 VirtualDHCP::Address(_pyco.get<std::string>("endAddress"))), 00065 subnetMask(_pyco.get<std::string>("subnetMask")) 00066 { 00067 } 00068 00069 00070 DHCPAck 00071 VirtualDHCP::request() 00072 { 00073 VirtualDHCP::Address ip = ipPool.suggestPort(); 00074 ipPool.bind(ip); 00075 00076 MESSAGE_BEGIN(NORMAL, log, m, "Received request. Leasing "); 00077 m << ip; 00078 MESSAGE_END(); 00079 00080 return DHCPAck(ip, subnetMask); 00081 } 00082 00083 void 00084 VirtualDHCP::release(VirtualDHCP::Address address) 00085 { 00086 MESSAGE_BEGIN(NORMAL, log, m, "Received release for address "); 00087 m << address; 00088 MESSAGE_END(); 00089 } 00090 00091 00092 VirtualDHCP::~VirtualDHCP() 00093 { 00094 } 00095 00096 void 00097 VirtualDHCP::doStartup() 00098 { 00099 TheDHCPService::Instance().addSubnet(getConfig().get<std::string>("subnetIdentifier"), 00100 this); 00101 MESSAGE_BEGIN(NORMAL, log, m, "New DHCP zone for "); 00102 m << getConfig().get<std::string>("subnetIdentifier"); 00103 m << " (Start : " << getConfig().get<std::string>("startAddress"); 00104 m << " End : " << getConfig().get<std::string>("endAddress") << ")"; 00105 MESSAGE_END(); 00106 00107 MESSAGE_SINGLE(NORMAL, log, "SubnetMask is : " << subnetMask); 00108 00109 00110 } 00111 00112 void 00113 VirtualDHCP::onNodeCreated() 00114 { 00115 } 00116 00117 void 00118 VirtualDHCP::onWorldCreated() 00119 { 00120 } 00121 00122 void 00123 VirtualDHCP::onShutdown() 00124 { 00125 } 00126 00127 00128
1.5.5