Skip to content

Commit 0ffebeb

Browse files
Add new method to set nsid on namespaces
Signed-off-by: francescomessina <francescomessina92@hotmail.com>
1 parent 533bb17 commit 0ffebeb

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/polycubed/src/utils/ns.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,21 @@ void Namespace::set_id(int id) {
202202
throw std::runtime_error("Error constructing nlmsg");
203203
}
204204

205+
int Namespace::set_random_id() {
206+
int id = 0;
207+
again:
208+
id++;
209+
try {
210+
set_id(id);
211+
} catch (...) {
212+
if (id < 100)
213+
goto again;
214+
else
215+
throw std::runtime_error("set_random_id failed");
216+
}
217+
return id;
218+
}
219+
205220
std::string Namespace::get_name() const {
206221
return name_;
207222
}

src/polycubed/src/utils/ns.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class Namespace {
3434
void execute(std::function<void()> f);
3535
void remove();
3636
void set_id(int id);
37+
int set_random_id();
3738

3839
std::string get_name() const;
3940
int get_fd() const;

0 commit comments

Comments
 (0)