BIND 10 trac992, updated. 0f4dd0cf9c1ca4cc397954d639692a8946edb284 [992] Getters/setters implemented in Pkt4.
BIND 10 source code commits
bind10-changes at lists.isc.org
Wed Nov 30 18:01:33 UTC 2011
The branch, trac992 has been updated
via 0f4dd0cf9c1ca4cc397954d639692a8946edb284 (commit)
via eb2e8615ae2ed35f9d70e632e970c42729853a19 (commit)
from ea709c77cdab1d2d91a923b913af869f865477bd (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 0f4dd0cf9c1ca4cc397954d639692a8946edb284
Author: Tomek Mrugalski <tomasz at isc.org>
Date: Wed Nov 30 19:00:57 2011 +0100
[992] Getters/setters implemented in Pkt4.
- Implemented several getters/setters
- Added reason comments for #if 0 code (dependency on other tickets)
- New test for implemented getters/setters
commit eb2e8615ae2ed35f9d70e632e970c42729853a19
Author: Tomek Mrugalski <tomasz at isc.org>
Date: Wed Nov 30 17:10:05 2011 +0100
[992] Compilation hack removed after IfaceMgr moved to lib.
-----------------------------------------------------------------------
Summary of changes:
src/bin/dhcp4/Makefile.am | 4 --
src/bin/dhcp4/dhcp4_srv.cc | 37 +++++++++--------
src/bin/dhcp4/main.cc | 6 +-
src/lib/dhcp/pkt4.h | 73 +++++++++++++++++++++++++++++++++-
src/lib/dhcp/tests/pkt4_unittest.cc | 17 ++++++++-
5 files changed, 109 insertions(+), 28 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/bin/dhcp4/Makefile.am b/src/bin/dhcp4/Makefile.am
index 1018aa2..71a4531 100644
--- a/src/bin/dhcp4/Makefile.am
+++ b/src/bin/dhcp4/Makefile.am
@@ -35,10 +35,6 @@ b10_dhcp4_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la
b10_dhcp4_LDADD += $(top_builddir)/src/lib/asiolink/libasiolink.la
b10_dhcp4_LDADD += $(top_builddir)/src/lib/log/liblog.la
-# TODO: This is ugly hack. iface_mgr should be moved to src/lib/dhcp
-b10_dhcp4_LDADD += $(top_builddir)/src/bin/dhcp6/iface_mgr.o
-
-
# TODO: config.h.in is wrong because doesn't honor pkgdatadir
# and can't use @datadir@ because doesn't expand default ${prefix}
b10_dhcp4dir = $(pkgdatadir)
diff --git a/src/bin/dhcp4/dhcp4_srv.cc b/src/bin/dhcp4/dhcp4_srv.cc
index 85b937f..bf9c133 100644
--- a/src/bin/dhcp4/dhcp4_srv.cc
+++ b/src/bin/dhcp4/dhcp4_srv.cc
@@ -48,6 +48,7 @@ Dhcpv4Srv::run() {
boost::shared_ptr<Pkt4> rsp; // server's response
#if 0
+ // uncomment this once ticket 1239 is merged.
query = IfaceMgr::instance().receive4();
#endif
@@ -80,25 +81,26 @@ Dhcpv4Srv::run() {
cout << "Received " << query->len() << " bytes packet type="
<< query->getType() << endl;
- /// DEBUG
+ // TODO: print out received packets only if verbose (or debug)
+ // mode is enabled
cout << query->toText();
if (rsp) {
-#if 0
- rsp->remote_addr_ = query->remote_addr_;
- rsp->local_addr_ = query->local_addr_;
- rsp->remote_port_ = DHCP6_CLIENT_PORT;
- rsp->local_port_ = DHCP6_SERVER_PORT;
- rsp->ifindex_ = query->ifindex_;
- rsp->iface_ = query->iface_;
-#endif
+ rsp->setRemoteAddr(query->getRemoteAddr());
+ rsp->setLocalAddr(query->getLocalAddr());
+ rsp->setRemotePort(DHCP4_CLIENT_PORT);
+ rsp->setLocalPort(DHCP4_SERVER_PORT);
+ rsp->setIface(query->getIface());
+ rsp->setIndex(query->getIndex());
+
cout << "Replying with:" << rsp->getType() << endl;
cout << rsp->toText();
cout << "----" << endl;
if (rsp->pack()) {
- cout << "#### pack successful." << endl;
+ cout << "Packet assembled correctly." << endl;
}
#if 0
+ // uncomment this once ticket 1240 is merged.
IfaceMgr::instance().send4(rsp);
#endif
}
@@ -113,9 +115,11 @@ Dhcpv4Srv::run() {
void
Dhcpv4Srv::setServerID() {
- /// TODO implement this for real once interface detection is done.
- /// Use hardcoded server-id for now
+ /// TODO implement this for real once interface detection (ticket 1237)
+ /// is done. Use hardcoded server-id for now.
+
#if 0
+ // uncomment this once ticket 1350 is merged.
IOAddress srvId("127.0.0.1");
serverid_ = boost::shared_ptr<Option>(
new Option4AddrLst(Option::V4, DHO_DHCP_SERVER_IDENTIFIER, srvId));
@@ -124,13 +128,13 @@ Dhcpv4Srv::setServerID() {
boost::shared_ptr<Pkt4>
Dhcpv4Srv::processDiscover(boost::shared_ptr<Pkt4> discover) {
- /// TODO: Echo mode. Implement this for real
+ /// TODO: Currently implemented echo mode. Implement this for real
return (discover);
}
boost::shared_ptr<Pkt4>
Dhcpv4Srv::processRequest(boost::shared_ptr<Pkt4> request) {
- /// TODO: Echo mode. Implement this for real
+ /// TODO: Currently implemented echo mode. Implement this for real
return (request);
}
@@ -138,14 +142,13 @@ void Dhcpv4Srv::processRelease(boost::shared_ptr<Pkt4> release) {
/// TODO: Implement this.
cout << "Received RELEASE on " << release->getIface() << " interface." << endl;
}
-
+
void Dhcpv4Srv::processDecline(boost::shared_ptr<Pkt4> decline) {
/// TODO: Implement this.
cout << "Received DECLINE on " << decline->getIface() << " interface." << endl;
}
boost::shared_ptr<Pkt4> processInform(boost::shared_ptr<Pkt4> inform) {
- /// TODO: Echo mode. Implement this for real
+ /// TODO: Currently implemented echo mode. Implement this for real
return (inform);
}
-
diff --git a/src/bin/dhcp4/main.cc b/src/bin/dhcp4/main.cc
index d92f369..ee40295 100644
--- a/src/bin/dhcp4/main.cc
+++ b/src/bin/dhcp4/main.cc
@@ -81,8 +81,8 @@ main(int argc, char* argv[]) {
int ret = 0;
- // TODO remainder of auth to dhcp6 code copy. We need to enable this in
- // dhcp6 eventually
+ // TODO remainder of auth to dhcp4 code copy. We need to enable this in
+ // dhcp4 eventually
#if 0
Session* cc_session = NULL;
Session* statistics_session = NULL;
@@ -104,7 +104,7 @@ main(int argc, char* argv[]) {
srv->run();
} catch (const std::exception& ex) {
- cerr << "[b10-dhcp6] Server failed: " << ex.what() << endl;
+ cerr << "[b10-dhcp4] Server failed: " << ex.what() << endl;
ret = 1;
}
diff --git a/src/lib/dhcp/pkt4.h b/src/lib/dhcp/pkt4.h
index 43a79b3..33554c8 100644
--- a/src/lib/dhcp/pkt4.h
+++ b/src/lib/dhcp/pkt4.h
@@ -311,6 +311,73 @@ public:
/// @return interface name
std::string getIface() { return iface_; };
+ /// @brief Sets interface name.
+ ///
+ /// Sets interface name over which packet was received or is
+ /// going to be transmitted.
+ ///
+ /// @return interface name
+ void setIface(const std::string& iface ) { iface_ = iface; };
+
+ /// @brief Sets interface index.
+ ///
+ /// @param ifindex specifies interface index.
+ void setIndex(uint32_t ifindex) { ifindex_ = ifindex; };
+
+ /// @brief Returns interface index.
+ ///
+ /// @return interface index
+ uint32_t getIndex() { return (ifindex_); };
+
+ /// @brief Sets remote address.
+ ///
+ /// @params remote specifies remote address
+ void setRemoteAddr(const isc::asiolink::IOAddress& remote) {
+ remote_addr_ = remote;
+ }
+
+ /// @brief Returns remote address
+ ///
+ /// @return remote address
+ const isc::asiolink::IOAddress& getRemoteAddr() {
+ return (remote_addr_);
+ }
+
+ /// @brief Sets local address.
+ ///
+ /// @params local specifies local address
+ void setLocalAddr(const isc::asiolink::IOAddress& local) {
+ local_addr_ = local;
+ }
+
+ /// @brief Returns local address.
+ ///
+ /// @return local address
+ const isc::asiolink::IOAddress& getLocalAddr() {
+ return (local_addr_);
+ }
+
+ /// @brief Sets local port.
+ ///
+ /// @params local specifies local port
+ void setLocalPort(uint16_t local) { local_port_ = local; }
+
+ /// @brief Returns local port.
+ ///
+ /// @return local port
+ uint16_t getLocalPort() { return (local_port_); }
+
+ /// @brief Sets remote port.
+ ///
+ /// @params remote specifies remote port
+ void setRemotePort(uint16_t remote) { remote_port_ = remote; }
+
+ /// @brief Returns remote port.
+ ///
+ /// @return remote port
+ uint16_t getRemotePort() { return (remote_port_); }
+
+
protected:
/// converts DHCP message type to BOOTP op type
@@ -335,13 +402,13 @@ protected:
/// Each network interface has assigned unique ifindex. It is functional
/// equvalent of name, but sometimes more useful, e.g. when using crazy
/// systems that allow spaces in interface names e.g. MS Windows)
- int ifindex_;
+ uint32_t ifindex_;
/// local UDP port
- int local_port_;
+ uint16_t local_port_;
/// remote UDP port
- int remote_port_;
+ uint16_t remote_port_;
/// @brief message operation code
///
diff --git a/src/lib/dhcp/tests/pkt4_unittest.cc b/src/lib/dhcp/tests/pkt4_unittest.cc
index c89743f..8d1363a 100644
--- a/src/lib/dhcp/tests/pkt4_unittest.cc
+++ b/src/lib/dhcp/tests/pkt4_unittest.cc
@@ -504,7 +504,7 @@ TEST(Pkt4Test, unpackOptions) {
vector<uint8_t> expectedFormat = generateTestPacket2();
- for (int i=0; i < sizeof(v4Opts); i++) {
+ for (int i = 0; i < sizeof(v4Opts); i++) {
expectedFormat.push_back(v4Opts[i]);
}
@@ -559,4 +559,19 @@ TEST(Pkt4Test, unpackOptions) {
EXPECT_EQ(0, memcmp(&x->getData()[0], v4Opts+22, 3)); // data len=3
}
+TEST(Pkt4Test, metaFields) {
+
+ Pkt4* pkt = new Pkt4(DHCPOFFER, 1234);
+ pkt->setIface("loooopback");
+ pkt->setIndex(42);
+ pkt->setRemoteAddr(IOAddress("1.2.3.4"));
+ pkt->setLocalAddr(IOAddress("4.3.2.1"));
+
+ EXPECT_EQ("loooopback", pkt->getIface());
+ EXPECT_EQ(42, pkt->getIndex());
+ EXPECT_EQ("1.2.3.4", pkt->getRemoteAddr().toText());
+ EXPECT_EQ("4.3.2.1", pkt->getLocalAddr().toText());
+
+}
+
} // end of anonymous namespace
More information about the bind10-changes
mailing list