Skip to content

Commit c185ed3

Browse files
Add method to send packets to the namespace from the slowpath
Signed-off-by: francescomessina <francescomessina92@hotmail.com>
1 parent 4c2b43f commit c185ed3

5 files changed

Lines changed: 20 additions & 0 deletions

File tree

src/libs/polycube/include/polycube/services/port.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class Port {
4040
Port(std::shared_ptr<PortIface> port);
4141
~Port();
4242
void send_packet_out(EthernetII &packet, bool recirculate = false);
43+
void send_packet_ns(EthernetII &packet);
4344
int index() const;
4445
std::string name() const;
4546
void set_peer(const std::string &peer);

src/libs/polycube/include/polycube/services/port_iface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class PortIface {
4242
public:
4343
virtual void send_packet_out(const std::vector<uint8_t> &packet,
4444
bool recirculate = false) = 0;
45+
virtual void send_packet_ns(const std::vector<uint8_t> &packet) = 0;
4546
virtual uint16_t index() const = 0;
4647
virtual bool operator==(const PortIface &rhs) const = 0;
4748
virtual std::string name() const = 0;

src/libs/polycube/src/port.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Port::impl {
3232
impl(Port &op);
3333
~impl();
3434
void send_packet_out(EthernetII &packet, bool recirculate);
35+
void send_packet_ns(EthernetII &packet);
3536
int index() const;
3637
std::string name() const;
3738
void set_peer(const std::string &peer);
@@ -104,6 +105,10 @@ void Port::impl::send_packet_out(EthernetII &packet, bool recirculate) {
104105
port_->send_packet_out(packet.serialize(), recirculate);
105106
}
106107

108+
void Port::impl::send_packet_ns(EthernetII &packet) {
109+
port_->send_packet_ns(packet.serialize());
110+
}
111+
107112
PortStatus Port::impl::get_status() const {
108113
return port_->get_status();
109114
}
@@ -129,6 +134,10 @@ void Port::send_packet_out(EthernetII &packet, bool recirculate) {
129134
return pimpl_->send_packet_out(packet, recirculate);
130135
}
131136

137+
void Port::send_packet_ns(EthernetII &packet) {
138+
return pimpl_->send_packet_ns(packet);
139+
}
140+
132141
int Port::index() const {
133142
return pimpl_->index();
134143
}

src/polycubed/src/port.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include "polycubed_core.h"
2424
extern polycube::polycubed::PolycubedCore *core;
2525

26+
const std::string prefix_port = "ns_port_";
27+
2628
namespace polycube {
2729
namespace polycubed {
2830

@@ -199,6 +201,12 @@ void Port::send_packet_out(const std::vector<uint8_t> &packet,
199201
c.send_packet_to_cube(module, port, packet);
200202
}
201203

204+
void Port::send_packet_ns(const std::vector<uint8_t> &packet) {
205+
std::string name_ns_port = prefix_port + name_;
206+
std::shared_ptr<PortIface> port_ns = parent_.get_port(name_ns_port);
207+
port_ns->send_packet_out(packet);
208+
}
209+
202210
void Port::update_indexes() {
203211
int i;
204212

src/polycubed/src/port.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class Port : public polycube::service::PortIface, public PeerIface {
7070
const std::string &peer() const;
7171
void send_packet_out(const std::vector<uint8_t> &packet,
7272
bool recirculate = false);
73+
void send_packet_ns(const std::vector<uint8_t> &packet);
7374
PortStatus get_status() const;
7475
PortType get_type() const;
7576

0 commit comments

Comments
 (0)