rib-manager: deleting expired entries from the rib and fib.
refs #1326
Change-Id: I865bff19da766560f920b1818bdf3eaa91e7dbb1
diff --git a/rib/rib-manager.cpp b/rib/rib-manager.cpp
index d04737c..c5f8666 100644
--- a/rib/rib-manager.cpp
+++ b/rib/rib-manager.cpp
@@ -186,7 +186,8 @@
if (!extractParameters(parameterComponent, parameters))
{
NFD_LOG_DEBUG("command result: malformed verb: " << verb);
- sendResponse(command, 400, "Malformed command");
+ if (static_cast<bool>(request))
+ sendResponse(command, 400, "Malformed command");
return;
}
@@ -201,7 +202,8 @@
else
{
NFD_LOG_DEBUG("Unsupported command: " << verb);
- sendResponse(request->getName(), 501, "Unsupported command");
+ if (static_cast<bool>(request))
+ sendResponse(request->getName(), 501, "Unsupported command");
}
}
@@ -214,7 +216,8 @@
if (!validateParameters(command, parameters))
{
NFD_LOG_DEBUG("register result: FAIL reason: malformed");
- sendResponse(request->getName(), 400, "Malformed command");
+ if (static_cast<bool>(request))
+ sendResponse(request->getName(), 400, "Malformed command");
return;
}
@@ -223,7 +226,25 @@
faceEntry.origin = parameters.getOrigin();
faceEntry.cost = parameters.getCost();
faceEntry.flags = parameters.getFlags();
- faceEntry.expires = time::steady_clock::now() + parameters.getExpirationPeriod();
+
+ if (parameters.getExpirationPeriod() != time::milliseconds::max())
+ {
+ faceEntry.expires = time::steady_clock::now() + parameters.getExpirationPeriod();
+
+ // Schedule a new event, the old one will be cancelled during rib insertion.
+ EventId eventId;
+ NFD_LOG_TRACE("scheduling unregistration at: " << faceEntry.expires);
+ eventId = scheduler::schedule(parameters.getExpirationPeriod(),
+ bind(&RibManager::unregisterEntry,
+ this, shared_ptr<Interest>(), parameters));
+
+ //set the NewEventId of this entry
+ faceEntry.setExpirationEvent(eventId);
+ }
+ else
+ {
+ faceEntry.expires = time::steady_clock::TimePoint::max();
+ }
NFD_LOG_TRACE("register prefix: " << faceEntry);
@@ -234,14 +255,22 @@
void
RibManager::unregisterEntry(const shared_ptr<const Interest>& request,
- ControlParameters& parameters)
+ ControlParameters& params)
{
ndn::nfd::RibUnregisterCommand command;
+ //passing all parameters gives error in validation.
+ //so passing only the required arguments.
+ ControlParameters parameters;
+ parameters.setName(params.getName());
+ parameters.setFaceId(params.getFaceId());
+ parameters.setOrigin(params.getOrigin());
+
if (!validateParameters(command, parameters))
{
- NFD_LOG_DEBUG("register result: FAIL reason: malformed");
- sendResponse(request->getName(), 400, "Malformed command");
+ NFD_LOG_DEBUG("unregister result: FAIL reason: malformed");
+ if (static_cast<bool>(request))
+ sendResponse(request->getName(), 400, "Malformed command");
return;
}
@@ -261,7 +290,8 @@
const std::string& failureInfo)
{
NFD_LOG_DEBUG("RibRequestValidationFailed: " << failureInfo);
- sendResponse(request->getName(), 403, failureInfo);
+ if (static_cast<bool>(request))
+ sendResponse(request->getName(), 403, failureInfo);
}
@@ -323,7 +353,8 @@
response.setText(os.str());
}
- sendResponse(request->getName(), response);
+ if (static_cast<bool>(request))
+ sendResponse(request->getName(), response);
}
void
@@ -339,7 +370,8 @@
NFD_LOG_TRACE("onRegSuccess: registered " << faceEntry);
- sendResponse(request->getName(), response);
+ if (static_cast<bool>(request))
+ sendResponse(request->getName(), response);
}
@@ -356,7 +388,8 @@
NFD_LOG_TRACE("onUnRegSuccess: unregistered " << faceEntry);
- sendResponse(request->getName(), response);
+ if (static_cast<bool>(request))
+ sendResponse(request->getName(), response);
}
void
@@ -374,7 +407,8 @@
response.setText("Success");
response.setBody(parameters.wireEncode());
- sendResponse(request->getName(), response);
+ if (static_cast<bool>(request))
+ sendResponse(request->getName(), response);
}
void
@@ -403,7 +437,8 @@
response.setText(os.str());
}
- sendResponse(request->getName(), response);
+ if (static_cast<bool>(request))
+ sendResponse(request->getName(), response);
}
void