Skip to content

Commit e75d2d8

Browse files
committed
pcn-firewall: add insert/delete actions; porting to new codegen
this commit introduces support for insert/delete rules this commit uses last version of code generation Signed-off-by: Matteo Bertrone <m.bertrone@gmail.com>
1 parent 98c90ea commit e75d2d8

53 files changed

Lines changed: 1886 additions & 447 deletions

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-firewall/datamodel/firewall.yang

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,26 @@ module firewall {
230230
}
231231
}
232232

233+
action insert {
234+
input {
235+
leaf id {
236+
type uint32;
237+
}
238+
uses "firewall:rule-fields";
239+
}
240+
output {
241+
leaf id {
242+
type uint32;
243+
}
244+
}
245+
}
246+
247+
action delete {
248+
input {
249+
uses "firewall:rule-fields";
250+
}
251+
}
252+
233253
action reset-counters {
234254
description "Reset the counters to 0 for the chain.";
235255
output {

src/services/pcn-firewall/src/CMakeLists.txt

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,33 @@ include(${PROJECT_SOURCE_DIR}/cmake/LoadFileAsVariable.cmake)
22

33
aux_source_directory(serializer SERIALIZER_SOURCES)
44
aux_source_directory(api API_SOURCES)
5-
aux_source_directory(default-src SRC_SOURCES)
65
aux_source_directory(modules MODULES)
6+
aux_source_directory(base BASE_SOURCES)
77

88
include_directories(serializer)
9-
include_directories(interface)
10-
include_directories(default-src)
119
include_directories(modules)
1210

11+
if (NOT DEFINED POLYCUBE_STANDALONE_SERVICE OR POLYCUBE_STANDALONE_SERVICE)
12+
find_package(PkgConfig REQUIRED)
13+
pkg_check_modules(POLYCUBE libpolycube)
14+
include_directories(${POLYCUBE_INCLUDE_DIRS})
15+
endif(NOT DEFINED POLYCUBE_STANDALONE_SERVICE OR POLYCUBE_STANDALONE_SERVICE)
16+
1317
# Needed to load files as variables
1418
include_directories(${CMAKE_CURRENT_BINARY_DIR})
1519

1620
add_library(pcn-firewall SHARED
1721
${SERIALIZER_SOURCES}
1822
${API_SOURCES}
19-
${SRC_SOURCES}
2023
${MODULES}
24+
${BASE_SOURCES}
2125
Chain.cpp
2226
ChainRule.cpp
2327
ChainStats.cpp
2428
SessionTable.cpp
2529
Firewall.cpp
26-
Firewall-lib.cpp
27-
Utils.cpp)
30+
Utils.cpp
31+
Firewall-lib.cpp)
2832

2933
# load ebpf datapath code in std::string variables
3034
load_file_as_variable(pcn-firewall datapaths/Firewall_ActionLookup_dp.c firewall_code_actionlookup)
@@ -41,11 +45,11 @@ load_file_as_variable(pcn-firewall datapaths/Firewall_Parser_dp.c firewall_code_
4145
load_file_as_variable(pcn-firewall datapaths/Firewall_TcpFlagsLookup_dp.c firewall_code_tcpflagslookup)
4246

4347
# load datamodel in a variable
44-
load_file_as_variable(pcn-firewall ../datamodel/firewall.yang firewall_datamodel)
48+
load_file_as_variable(pcn-firewall
49+
../datamodel/firewall.yang
50+
firewall_datamodel)
4551

46-
target_link_libraries(pcn-firewall
47-
polycube
48-
uuid)
52+
target_link_libraries(pcn-firewall ${POLYCUBE_LIBRARIES})
4953

5054
# Specify shared library install directory
5155

src/services/pcn-firewall/src/Chain.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include "Chain.h"
1818
#include "Firewall.h"
1919

20-
Chain::Chain(Firewall &parent, const ChainJsonObject &conf) : parent_(parent) {
20+
Chain::Chain(Firewall &parent, const ChainJsonObject &conf) : ChainBase(parent) {
2121
update(conf);
2222
}
2323

@@ -608,3 +608,11 @@ void Chain::delRuleList() {
608608
applyRules();
609609
}
610610
}
611+
612+
ChainInsertOutputJsonObject Chain::insert(ChainInsertInputJsonObject input) {
613+
throw std::runtime_error("Chain::ChainInsertOutput: Method not implemented");
614+
}
615+
616+
void Chain::deletes(ChainDeleteInputJsonObject input) {
617+
throw std::runtime_error("Chain::: Method not implemented");
618+
}

src/services/pcn-firewall/src/Chain.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,18 @@
2121
#include <mutex>
2222
#include <thread>
2323

24-
#include "../interface/ChainInterface.h"
24+
#include "base/ChainBase.h"
25+
2526
#include "ChainRule.h"
2627
#include "ChainStats.h"
2728
#include "Firewall.h"
2829

2930
class Firewall;
3031
class ChainRule;
3132

32-
using namespace io::swagger::server::model;
33+
using namespace polycube::service::model;
3334

34-
class Chain : public ChainInterface {
35+
class Chain : public ChainBase {
3536
friend class ChainRule;
3637
friend class ChainStats;
3738

@@ -79,13 +80,14 @@ class Chain : public ChainInterface {
7980
void delRuleList() override;
8081

8182
ChainAppendOutputJsonObject append(ChainAppendInputJsonObject input) override;
83+
ChainInsertOutputJsonObject insert(ChainInsertInputJsonObject input) override;
84+
void deletes(ChainDeleteInputJsonObject input) override;
8285
ChainResetCountersOutputJsonObject resetCounters() override;
8386
ChainApplyRulesOutputJsonObject applyRules() override;
8487

8588
uint32_t getNrRules();
8689

8790
private:
88-
Firewall &parent_;
8991
ActionEnum defaultAction = ActionEnum::DROP;
9092
ChainNameEnum name;
9193
std::vector<std::shared_ptr<ChainRule>> rules_;

src/services/pcn-firewall/src/ChainRule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "Firewall.h"
2020

2121
ChainRule::ChainRule(Chain &parent, const ChainRuleJsonObject &conf)
22-
: parent_(parent), id(conf.getId()) {
22+
: ChainRuleBase(parent), id(conf.getId()) {
2323
update(conf);
2424
}
2525

src/services/pcn-firewall/src/ChainRule.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,15 @@
1616

1717
#pragma once
1818

19-
#include "../interface/ChainRuleInterface.h"
2019
#include "defines.h"
2120

22-
#include <inttypes.h>
23-
#include <spdlog/spdlog.h>
21+
#include "base/ChainRuleBase.h"
2422

2523
class Chain;
2624

27-
using namespace io::swagger::server::model;
25+
using namespace polycube::service::model;
2826

29-
class ChainRule : public ChainRuleInterface {
27+
class ChainRule : public ChainRuleBase {
3028
friend class ChainStats;
3129
friend class Chain;
3230

@@ -102,8 +100,6 @@ class ChainRule : public ChainRuleInterface {
102100
static int ChainRuleConntrackEnum_to_int(const ConntrackstatusEnum &status);
103101

104102
private:
105-
Chain &parent_;
106-
107103
uint32_t id;
108104

109105
ConntrackstatusEnum conntrack;

src/services/pcn-firewall/src/ChainStats.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "Firewall.h"
1919

2020
ChainStats::ChainStats(Chain &parent, const ChainStatsJsonObject &conf)
21-
: parent_(parent) {
21+
: ChainStatsBase(parent) {
2222
this->counter = conf;
2323
}
2424

src/services/pcn-firewall/src/ChainStats.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@
1616

1717
#pragma once
1818

19-
#include "../interface/ChainStatsInterface.h"
20-
21-
#include <spdlog/spdlog.h>
19+
#include "base/ChainStatsBase.h"
2220

2321
class Chain;
2422

25-
using namespace io::swagger::server::model;
23+
using namespace polycube::service::model;
2624

27-
class ChainStats : public ChainStatsInterface {
25+
class ChainStats : public ChainStatsBase {
2826
friend class ChainRule;
2927
friend class Chain;
3028

@@ -98,7 +96,6 @@ class ChainStats : public ChainStatsInterface {
9896
uint32_t getId() override;
9997

10098
private:
101-
Chain &parent_;
10299
ChainStatsJsonObject counter;
103100

104101
static std::shared_ptr<ChainStats> getDefaultActionCounters(Chain &parent);

src/services/pcn-firewall/src/Firewall-lib.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22
* firewall API
33
* firewall API generated from firewall.yang
44
*
5-
* OpenAPI spec version: 1.0.0
6-
*
7-
* NOTE: This class is auto generated by the swagger code generator program.
8-
* https://github.com/polycube-network/swagger-codegen.git
9-
* branch polycube
5+
* NOTE: This file is auto generated by polycube-codegen
6+
* https://github.com/polycube-network/polycube-codegen
107
*/
118

129

@@ -16,7 +13,7 @@
1613
#include "../datamodel/firewall.h" // generated from datamodel
1714

1815
#define SERVICE_PYANG_GIT ""
19-
#define SERVICE_SWAGGER_CODEGEN_GIT "implement_help_in_framework/be2c60c"
16+
#define SERVICE_SWAGGER_CODEGEN_GIT "GIT_REPO_ID"
2017

2118
#include <polycube/services/shared_library.h>
2219

src/services/pcn-firewall/src/Firewall.cpp

Lines changed: 2 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "Firewall_dp.h"
1919

2020
Firewall::Firewall(const std::string name, const FirewallJsonObject &conf)
21-
: TransparentCube(conf.getBase(), {firewall_code}, {firewall_code}) {
21+
: TransparentCube(conf.getBase(), {firewall_code}, {firewall_code}), FirewallBase(name) {
2222
logger()->set_pattern("[%Y-%m-%d %H:%M:%S.%e] [Firewall] [%n] [%l] %v");
2323
logger()->info("Creating Firewall instance");
2424

@@ -95,50 +95,6 @@ Firewall::~Firewall() {
9595
TransparentCube::dismount();
9696
}
9797

98-
void Firewall::update(const FirewallJsonObject &conf) {
99-
// This method updates all the object/parameter in Firewall object specified
100-
// in the conf JsonObject.
101-
TransparentCube::set_conf(conf.getBase());
102-
103-
if (conf.chainIsSet()) {
104-
for (auto &i : conf.getChain()) {
105-
auto name = i.getName();
106-
auto m = getChain(name);
107-
m->update(i);
108-
}
109-
}
110-
111-
if (conf.acceptEstablishedIsSet()) {
112-
setAcceptEstablished(conf.getAcceptEstablished());
113-
}
114-
115-
if (conf.conntrackIsSet()) {
116-
setConntrack(conf.getConntrack());
117-
}
118-
119-
if (conf.interactiveIsSet()) {
120-
setInteractive(conf.getInteractive());
121-
}
122-
}
123-
124-
FirewallJsonObject Firewall::toJsonObject() {
125-
FirewallJsonObject conf;
126-
conf.setBase(TransparentCube::to_json());
127-
128-
// Remove comments when you implement all sub-methods
129-
for (auto &i : getChainList()) {
130-
conf.addChain(i->toJsonObject());
131-
}
132-
133-
conf.setConntrack(getConntrack());
134-
135-
conf.setAcceptEstablished(getAcceptEstablished());
136-
137-
conf.setInteractive(getInteractive());
138-
139-
return conf;
140-
}
141-
14298
void Firewall::packet_in(polycube::service::Sense sense,
14399
polycube::service::PacketInMetadata &md,
144100
const std::vector<uint8_t> &packet) {
@@ -361,24 +317,10 @@ void Firewall::addChain(const ChainNameEnum &name,
361317
std::forward_as_tuple(*this, namedChain));
362318
}
363319

364-
void Firewall::addChainList(const std::vector<ChainJsonObject> &conf) {
365-
for (auto &i : conf) {
366-
ChainNameEnum name_ = i.getName();
367-
addChain(name_, i);
368-
}
369-
}
370-
371-
void Firewall::replaceChain(const ChainNameEnum &name,
372-
const ChainJsonObject &conf) {
373-
delChain(name);
374-
ChainNameEnum name_ = conf.getName();
375-
addChain(name_, conf);
376-
}
377-
378320
void Firewall::delChain(const ChainNameEnum &name) {
379321
throw std::runtime_error("Method not supported.");
380322
}
381323

382324
void Firewall::delChainList() {
383325
throw std::runtime_error("Method not supported.");
384-
}
326+
}

0 commit comments

Comments
 (0)