2525using namespace polycube ::service;
2626
2727Helloworld::Helloworld (const std::string name, const HelloworldJsonObject &conf)
28- : Cube(conf.getBase(), {helloworld_code_ingress}, {}) {
29- logger ()->set_pattern (" [%Y-%m-%d %H:%M:%S.%e] [helloworld] [%n] [%l] %v" );
30- logger ()->info (" Creating helloworld instance" );
31-
32- // TODO: action should have a default value, so the actionIsSet control could
33- // be ommitted.
34- if (conf.actionIsSet ()) {
35- setAction (conf.getAction ());
36- } else {
37- setAction (HelloworldActionEnum::DROP);
38- }
28+ : Cube(conf.getBase(), {helloworld_code_ingress}, {}),
29+ HelloworldBase (name) {
30+ logger ()->info (" Creating Helloworld instance" );
31+ setAction (conf.getAction ());
3932
4033 // set an initial state before doing any change to the configuration
4134 // UINT16_MAX means that the port is not connected
@@ -47,41 +40,7 @@ Helloworld::Helloworld(const std::string name, const HelloworldJsonObject &conf)
4740}
4841
4942Helloworld::~Helloworld () {
50- logger ()->info (" destroying helloworld instance" );
51- }
52-
53- void Helloworld::update (const HelloworldJsonObject &conf) {
54- // This method updates all the object/parameter in Helloworld object specified
55- // in the conf JsonObject.
56- // You can modify this implementation.
57-
58- // update base cube implementation
59- Cube::set_conf (conf.getBase ());
60-
61- if (conf.actionIsSet ()) {
62- setAction (conf.getAction ());
63- }
64-
65- if (conf.portsIsSet ()) {
66- for (auto &i : conf.getPorts ()) {
67- auto name = i.getName ();
68- auto m = getPorts (name);
69- m->update (i);
70- }
71- }
72- }
73-
74- HelloworldJsonObject Helloworld::toJsonObject () {
75- HelloworldJsonObject conf;
76- conf.setBase (Cube::to_json ());
77-
78- conf.setAction (getAction ());
79-
80- for (auto &i : getPortsList ()) {
81- conf.addPorts (i->toJsonObject ());
82- }
83-
84- return conf;
43+ logger ()->info (" Destroying Helloworld instance" );
8544}
8645
8746void Helloworld::packet_in (Ports &port, polycube::service::PacketInMetadata &md,
@@ -99,14 +58,6 @@ void Helloworld::setAction(const HelloworldActionEnum &value) {
9958 get_array_table<uint8_t >(" action_map" ).set (0x0 , action);
10059}
10160
102- std::shared_ptr<Ports> Helloworld::getPorts (const std::string &name) {
103- return get_port (name);
104- }
105-
106- std::vector<std::shared_ptr<Ports>> Helloworld::getPortsList () {
107- return get_ports ();
108- }
109-
11061void Helloworld::addPorts (const std::string &name,
11162 const PortsJsonObject &conf) {
11263 if (get_ports ().size () == 2 ) {
@@ -135,20 +86,6 @@ void Helloworld::addPorts(const std::string &name,
13586 ports_table.set (port_map_index, p->index ());
13687}
13788
138- void Helloworld::addPortsList (const std::vector<PortsJsonObject> &conf) {
139- for (auto &i : conf) {
140- std::string name_ = i.getName ();
141- addPorts (name_, i);
142- }
143- }
144-
145- void Helloworld::replacePorts (const std::string &name,
146- const PortsJsonObject &conf) {
147- delPorts (name);
148- std::string name_ = conf.getName ();
149- addPorts (name_, conf);
150- }
151-
15289void Helloworld::delPorts (const std::string &name) {
15390 int index = get_port (name)->index ();
15491
@@ -165,10 +102,3 @@ void Helloworld::delPorts(const std::string &name) {
165102 remove_port (name);
166103 logger ()->info (" port {0} was removed" , name);
167104}
168-
169- void Helloworld::delPortsList () {
170- auto ports = get_ports ();
171- for (auto it : ports) {
172- delPorts (it->name ());
173- }
174- }
0 commit comments