Skip to content

Commit a3f8dab

Browse files
authored
Merge pull request #93 from polycube-network/remove_static_functions
Remove static functions
2 parents 3d71200 + e09356c commit a3f8dab

137 files changed

Lines changed: 3034 additions & 5314 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/services/pcn-ddosmitigator/src/BlacklistDst.cpp

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -58,96 +58,6 @@ BlacklistDstJsonObject BlacklistDst::toJsonObject() {
5858
return conf;
5959
}
6060

61-
void BlacklistDst::create(Ddosmitigator &parent, const std::string &ip,
62-
const BlacklistDstJsonObject &conf) {
63-
// This method creates the actual BlacklistDst object given thee key param.
64-
// Please remember to call here the create static method for all sub-objects
65-
// of BlacklistDst.
66-
parent.logger()->debug("BlacklistDst create");
67-
68-
try {
69-
// TODO check if dst ip rules are already present
70-
// and reinject datapath with dstblacklist ps
71-
72-
if (parent.blacklistdst_.size() >= 0) {
73-
parent.setDstMatch(true);
74-
parent.reloadCode();
75-
}
76-
77-
auto dstblacklist =
78-
parent.get_percpuhash_table<uint32_t, uint64_t>("dstblacklist");
79-
dstblacklist.set(utils::ip_string_to_be_uint(ip), 0);
80-
} catch (...) {
81-
throw std::runtime_error("unable to add element to map");
82-
}
83-
84-
BlacklistDstJsonObject configuration;
85-
configuration.setIp(ip);
86-
87-
parent.blacklistdst_.emplace(std::piecewise_construct,
88-
std::forward_as_tuple(ip),
89-
std::forward_as_tuple(parent, configuration));
90-
}
91-
92-
std::shared_ptr<BlacklistDst> BlacklistDst::getEntry(Ddosmitigator &parent,
93-
const std::string &ip) {
94-
// This method retrieves the pointer to BlacklistDst object specified by its
95-
// keys.
96-
parent.logger()->debug("BlacklistDst getEntry");
97-
98-
return std::shared_ptr<BlacklistDst>(&parent.blacklistdst_.at(ip),
99-
[](BlacklistDst *) {});
100-
}
101-
102-
void BlacklistDst::removeEntry(Ddosmitigator &parent, const std::string &ip) {
103-
// This method removes the single BlacklistDst object specified by its keys.
104-
// Remember to call here the remove static method for all-sub-objects of
105-
// BlacklistDst.
106-
parent.logger()->debug("BlacklistDst removeEntry");
107-
108-
// ebpf map remove is performed in destructor
109-
parent.blacklistdst_.erase(ip);
110-
111-
if (parent.blacklistdst_.size() == 0) {
112-
parent.setDstMatch(false);
113-
parent.reloadCode();
114-
}
115-
116-
return;
117-
}
118-
119-
std::vector<std::shared_ptr<BlacklistDst>> BlacklistDst::get(
120-
Ddosmitigator &parent) {
121-
// This methods get the pointers to all the BlacklistDst objects in
122-
// Ddosmitigator.
123-
parent.logger()->debug("BlacklistDst get vector");
124-
125-
std::vector<std::shared_ptr<BlacklistDst>> blacklistdst;
126-
127-
for (auto &it : parent.blacklistdst_) {
128-
blacklistdst.push_back(BlacklistDst::getEntry(parent, it.first));
129-
}
130-
131-
return blacklistdst;
132-
}
133-
134-
void BlacklistDst::remove(Ddosmitigator &parent) {
135-
// This method removes all BlacklistDst objects in Ddosmitigator.
136-
// Remember to call here the remove static method for all-sub-objects of
137-
// BlacklistDst.
138-
parent.logger()->debug("BlacklistDst remove");
139-
140-
// ebpf maps remove performed in destructor
141-
parent.blacklistdst_.clear();
142-
143-
if (parent.blacklistdst_.size() == 0) {
144-
parent.setDstMatch(false);
145-
parent.reloadCode();
146-
}
147-
148-
return;
149-
}
150-
15161
std::string BlacklistDst::getIp() {
15262
// This method retrieves the ip value.
15363
logger()->debug("BlacklistDst getIp {0} ", this->ip_);

src/services/pcn-ddosmitigator/src/BlacklistDst.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,6 @@ class BlacklistDst : public BlacklistDstInterface {
3131
BlacklistDst(Ddosmitigator &parent, const BlacklistDstJsonObject &conf);
3232
virtual ~BlacklistDst();
3333

34-
static void create(Ddosmitigator &parent, const std::string &ip,
35-
const BlacklistDstJsonObject &conf);
36-
static std::shared_ptr<BlacklistDst> getEntry(Ddosmitigator &parent,
37-
const std::string &ip);
38-
static void removeEntry(Ddosmitigator &parent, const std::string &ip);
39-
static std::vector<std::shared_ptr<BlacklistDst>> get(Ddosmitigator &parent);
40-
static void remove(Ddosmitigator &parent);
4134
std::shared_ptr<spdlog::logger> logger();
4235
void update(const BlacklistDstJsonObject &conf) override;
4336
BlacklistDstJsonObject toJsonObject() override;

src/services/pcn-ddosmitigator/src/BlacklistSrc.cpp

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -57,97 +57,6 @@ BlacklistSrcJsonObject BlacklistSrc::toJsonObject() {
5757
return conf;
5858
}
5959

60-
void BlacklistSrc::create(Ddosmitigator &parent, const std::string &ip,
61-
const BlacklistSrcJsonObject &conf) {
62-
// This method creates the actual BlacklistSrc object given thee key param.
63-
// Please remember to call here the create static method for all sub-objects
64-
// of BlacklistSrc.
65-
parent.logger()->debug("BlacklistSrc create");
66-
67-
try {
68-
parent.logger()->debug("blacklist size {0} ", parent.blacklistsrc_.size());
69-
// TODO check if src ip rules are already present
70-
// and reinject datapath with srcblacklist ps
71-
72-
if (parent.blacklistsrc_.size() >= 0) {
73-
parent.setSrcMatch(true);
74-
parent.reloadCode();
75-
}
76-
77-
auto srcblacklist =
78-
parent.get_percpuhash_table<uint32_t, uint64_t>("srcblacklist");
79-
srcblacklist.set(utils::ip_string_to_be_uint(ip), 0);
80-
} catch (...) {
81-
throw std::runtime_error("unable to add element to map");
82-
}
83-
84-
BlacklistSrcJsonObject configuration;
85-
configuration.setIp(ip);
86-
87-
parent.blacklistsrc_.emplace(std::piecewise_construct,
88-
std::forward_as_tuple(ip),
89-
std::forward_as_tuple(parent, configuration));
90-
}
91-
92-
std::shared_ptr<BlacklistSrc> BlacklistSrc::getEntry(Ddosmitigator &parent,
93-
const std::string &ip) {
94-
// This method retrieves the pointer to BlacklistSrc object specified by its
95-
// keys.
96-
parent.logger()->debug("BlacklistSrc getEntry");
97-
98-
return std::shared_ptr<BlacklistSrc>(&parent.blacklistsrc_.at(ip),
99-
[](BlacklistSrc *) {});
100-
}
101-
102-
void BlacklistSrc::removeEntry(Ddosmitigator &parent, const std::string &ip) {
103-
// This method removes the single BlacklistSrc object specified by its keys.
104-
// Remember to call here the remove static method for all-sub-objects of
105-
// BlacklistSrc.
106-
parent.logger()->debug("BlacklistSrc removeEntry");
107-
108-
// ebpf map remove is performed in destructor
109-
parent.blacklistsrc_.erase(ip);
110-
111-
if (parent.blacklistsrc_.size() == 0) {
112-
parent.setSrcMatch(false);
113-
parent.reloadCode();
114-
}
115-
116-
return;
117-
}
118-
119-
std::vector<std::shared_ptr<BlacklistSrc>> BlacklistSrc::get(
120-
Ddosmitigator &parent) {
121-
// This methods get the pointers to all the BlacklistSrc objects in
122-
// Ddosmitigator.
123-
parent.logger()->debug("BlacklistSrc get vector");
124-
125-
std::vector<std::shared_ptr<BlacklistSrc>> blacklistsrc;
126-
127-
for (auto &it : parent.blacklistsrc_) {
128-
blacklistsrc.push_back(BlacklistSrc::getEntry(parent, it.first));
129-
}
130-
131-
return blacklistsrc;
132-
}
133-
134-
void BlacklistSrc::remove(Ddosmitigator &parent) {
135-
// This method removes all BlacklistSrc objects in Ddosmitigator.
136-
// Remember to call here the remove static method for all-sub-objects of
137-
// BlacklistSrc.
138-
parent.logger()->debug("BlacklistSrc remove");
139-
140-
// ebpf maps remove performed in destructor
141-
parent.blacklistsrc_.clear();
142-
143-
if (parent.blacklistsrc_.size() == 0) {
144-
parent.setSrcMatch(false);
145-
parent.reloadCode();
146-
}
147-
148-
return;
149-
}
150-
15160
std::string BlacklistSrc::getIp() {
15261
logger()->debug("BlacklistSrc getIp {0} ", this->ip_);
15362

src/services/pcn-ddosmitigator/src/BlacklistSrc.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,6 @@ class BlacklistSrc : public BlacklistSrcInterface {
3131
BlacklistSrc(Ddosmitigator &parent, const BlacklistSrcJsonObject &conf);
3232
virtual ~BlacklistSrc();
3333

34-
static void create(Ddosmitigator &parent, const std::string &ip,
35-
const BlacklistSrcJsonObject &conf);
36-
static std::shared_ptr<BlacklistSrc> getEntry(Ddosmitigator &parent,
37-
const std::string &ip);
38-
static void removeEntry(Ddosmitigator &parent, const std::string &ip);
39-
static std::vector<std::shared_ptr<BlacklistSrc>> get(Ddosmitigator &parent);
40-
static void remove(Ddosmitigator &parent);
4134
std::shared_ptr<spdlog::logger> logger();
4235
void update(const BlacklistSrcJsonObject &conf) override;
4336
BlacklistSrcJsonObject toJsonObject() override;

0 commit comments

Comments
 (0)