Parcourir la source

[3705] Dhcp6Client improvements:

 - is now able to use specified relay information
 - stores received options
Tomek Mrugalski il y a 10 ans
Parent
commit
33f7238e0c
2 fichiers modifiés avec 29 ajouts et 8 suppressions
  1. 15 7
      src/bin/dhcp6/tests/dhcp6_client.cc
  2. 14 1
      src/bin/dhcp6/tests/dhcp6_client.h

+ 15 - 7
src/bin/dhcp6/tests/dhcp6_client.cc

@@ -76,6 +76,8 @@ Dhcp6Client::applyRcvdConfiguration(const Pkt6Ptr& reply) {
     for (Opts::const_iterator opt = opts.begin(); opt != opts.end(); ++opt) {
         Option6IAPtr ia = boost::dynamic_pointer_cast<Option6IA>(opt->second);
         if (!ia) {
+            // This is not IA, so let's just store it.
+            config_.options_.insert(*opt);
             continue;
         }
 
@@ -453,13 +455,19 @@ Dhcp6Client::sendMsg(const Pkt6Ptr& msg) {
     srv_->shutdown_ = false;
     // The client is configured to send through the relay. We achieve that
     // adding the relay structure.
-    if (use_relay_) {
-        Pkt6::RelayInfo relay;
-        relay.linkaddr_ = relay_link_addr_;
-        relay.peeraddr_ = asiolink::IOAddress("fe80::1");
-        relay.msg_type_ = DHCPV6_RELAY_FORW;
-        relay.hop_count_ = 1;
-        msg->relay_info_.push_back(relay);
+    if (use_relay_ || !relay_info_.empty()) {
+        if (relay_info_.empty()) {
+            // Let's craft the relay info by hand
+            Pkt6::RelayInfo relay;
+            relay.linkaddr_ = relay_link_addr_;
+            relay.peeraddr_ = asiolink::IOAddress("fe80::1");
+            relay.msg_type_ = DHCPV6_RELAY_FORW;
+            relay.hop_count_ = 1;
+            msg->relay_info_.push_back(relay);
+        } else {
+            // The test provided relay_info_, let's use that.
+            msg->relay_info_ = relay_info_;
+        }
     }
     // Repack the message to simulate wire-data parsing.
     msg->pack();

+ 14 - 1
src/bin/dhcp6/tests/dhcp6_client.h

@@ -74,10 +74,17 @@ public:
     /// @brief Holds the current client configuration obtained from the
     /// server over DHCP.
     ///
-    /// Currently it simply contains the collection of leases acquired.
+    /// Currently it simply contains the collection of leases acquired
+    /// and a list of options. Note: this is a simple copy of all
+    /// non-IA options and often includes "protocol" options, like
+    /// server-id and client-id.
     struct Configuration {
+        /// @brief List of received leases
         std::vector<LeaseInfo> leases_;
 
+        /// @brief List of received options
+        OptionCollection options_;
+
         /// @brief Status code received in the global option scope.
         uint16_t status_code_;
 
@@ -388,6 +395,12 @@ public:
     /// @brief Link address of the relay to be used for relayed messages.
     asiolink::IOAddress relay_link_addr_;
 
+    /// @brief RelayInfo (information about relays)
+    ///
+    /// Dhcp6Client will typically contruct this info itself, but if
+    /// it is provided here by the test, this data will be used as is.
+    std::vector<Pkt6::RelayInfo> relay_info_;
+
     /// @brief Controls whether the client will send ORO
     ///
     /// The actual content of the ORO is specified in oro_.