Skip to content

Commit

Permalink
Merge pull request #131 from polycube-network/pr/remove_mac_simple_br…
Browse files Browse the repository at this point in the history
…idge

pcn-simplebridge: remove mac from ports
  • Loading branch information
frisso committed May 22, 2019
2 parents a434057 + f9187f9 commit 8659149
Show file tree
Hide file tree
Showing 11 changed files with 3 additions and 120 deletions.
12 changes: 1 addition & 11 deletions src/services/pcn-simplebridge/datamodel/simplebridge.yang
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,7 @@ module simplebridge {
polycube-base:service-name "simplebridge";
polycube-base:service-min-kernel-version "4.11.0";

uses "polycube-standard-base:standard-base-yang-module" {
augment ports {
leaf mac {
type yang:mac-address;
description "MAC address of the port";
config true;
polycube-base:init-only-config;
polycube-base:cli-example "C5:13:2D:36:27:9B";
}
}
}
uses "polycube-standard-base:standard-base-yang-module";

container fdb {
leaf aging-time {
Expand Down
16 changes: 1 addition & 15 deletions src/services/pcn-simplebridge/src/Ports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,7 @@
Ports::Ports(polycube::service::Cube<Ports> &parent,
std::shared_ptr<polycube::service::PortIface> port,
const PortsJsonObject &conf)
: PortsBase(parent, port) {
// This MAC address is not used in the datapath. We set only the variable here
if (conf.macIsSet()) {
mac_ = conf.getMac();
} else {
mac_ = utils::get_random_mac();
logger()->info("[Ports] New port add with random mac: {0}", mac_);
}
}
: PortsBase(parent, port) {}

Ports::~Ports() {
try {
Expand All @@ -53,9 +45,3 @@ Ports::~Ports() {
e.what());
}
}

std::string Ports::getMac() {
// This method retrieves the mac value.
return mac_;
}

5 changes: 0 additions & 5 deletions src/services/pcn-simplebridge/src/Ports.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ class Ports : public PortsBase {
const PortsJsonObject &conf);
virtual ~Ports();

/// <summary>
/// MAC address of the port
/// </summary>
std::string getMac() override;

private:
std::string mac_;
};
25 changes: 0 additions & 25 deletions src/services/pcn-simplebridge/src/api/SimplebridgeApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,31 +486,6 @@ Response read_simplebridge_ports_list_by_id_handler(
}
}

Response read_simplebridge_ports_mac_by_id_handler(
const char *name, const Key *keys,
size_t num_keys ) {
// Getting the path params
std::string unique_name { name };
std::string unique_portsName;
for (size_t i = 0; i < num_keys; ++i) {
if (!strcmp(keys[i].name, "ports_name")) {
unique_portsName = std::string { keys[i].value.string };
break;
}
}


try {

auto x = read_simplebridge_ports_mac_by_id(unique_name, unique_portsName);
nlohmann::json response_body;
response_body = x;
return { kOk, ::strdup(response_body.dump().c_str()) };
} catch(const std::exception &e) {
return { kGenericError, ::strdup(e.what()) };
}
}

Response replace_simplebridge_by_id_handler(
const char *name, const Key *keys,
size_t num_keys ,
Expand Down
1 change: 0 additions & 1 deletion src/services/pcn-simplebridge/src/api/SimplebridgeApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ Response read_simplebridge_fdb_entry_port_by_id_handler(const char *name, const
Response read_simplebridge_list_by_id_handler(const char *name, const Key *keys, size_t num_keys);
Response read_simplebridge_ports_by_id_handler(const char *name, const Key *keys, size_t num_keys);
Response read_simplebridge_ports_list_by_id_handler(const char *name, const Key *keys, size_t num_keys);
Response read_simplebridge_ports_mac_by_id_handler(const char *name, const Key *keys, size_t num_keys);
Response replace_simplebridge_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value);
Response replace_simplebridge_fdb_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value);
Response replace_simplebridge_fdb_entry_by_id_handler(const char *name, const Key *keys, size_t num_keys, const char *value);
Expand Down
18 changes: 0 additions & 18 deletions src/services/pcn-simplebridge/src/api/SimplebridgeApiImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,24 +451,6 @@ read_simplebridge_ports_list_by_id(const std::string &name) {
return m;
}

/**
* @brief Read mac by ID
*
* Read operation of resource: mac*
*
* @param[in] name ID of name
* @param[in] portsName ID of ports_name
*
* Responses:
* std::string
*/
std::string
read_simplebridge_ports_mac_by_id(const std::string &name, const std::string &portsName) {
auto simplebridge = get_cube(name);
auto ports = simplebridge->getPorts(portsName);
return ports->getMac();

}

/**
* @brief Replace fdb by ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ namespace SimplebridgeApiImpl {
std::vector<SimplebridgeJsonObject> read_simplebridge_list_by_id();
PortsJsonObject read_simplebridge_ports_by_id(const std::string &name, const std::string &portsName);
std::vector<PortsJsonObject> read_simplebridge_ports_list_by_id(const std::string &name);
std::string read_simplebridge_ports_mac_by_id(const std::string &name, const std::string &portsName);
void replace_simplebridge_by_id(const std::string &name, const SimplebridgeJsonObject &value);
void replace_simplebridge_fdb_by_id(const std::string &name, const FdbJsonObject &value);
void replace_simplebridge_fdb_entry_by_id(const std::string &name, const std::string &address, const FdbEntryJsonObject &value);
Expand Down
1 change: 0 additions & 1 deletion src/services/pcn-simplebridge/src/base/PortsBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ PortsJsonObject PortsBase::toJsonObject() {
conf.setBase(Port::to_json());

conf.setName(getName());
conf.setMac(getMac());

return conf;
}
Expand Down
7 changes: 1 addition & 6 deletions src/services/pcn-simplebridge/src/base/PortsBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,11 @@ class PortsBase: public polycube::service::Port {
public:
PortsBase(polycube::service::Cube<Ports> &parent,
std::shared_ptr<polycube::service::PortIface> port);

virtual ~PortsBase();
virtual void update(const PortsJsonObject &conf);
virtual PortsJsonObject toJsonObject();

/// <summary>
/// MAC address of the port
/// </summary>
virtual std::string getMac() = 0;

std::shared_ptr<spdlog::logger> logger();
protected:
Simplebridge &parent_;
Expand Down
27 changes: 0 additions & 27 deletions src/services/pcn-simplebridge/src/serializer/PortsJsonObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,17 @@ namespace model {

PortsJsonObject::PortsJsonObject() {
m_nameIsSet = false;
m_macIsSet = false;
}

PortsJsonObject::PortsJsonObject(const nlohmann::json &val) :
JsonObjectBase(val) {
m_nameIsSet = false;
m_macIsSet = false;


if (val.count("name")) {
setName(val.at("name").get<std::string>());
}

if (val.count("mac")) {
setMac(val.at("mac").get<std::string>());
}
}

nlohmann::json PortsJsonObject::toJson() const {
Expand All @@ -47,10 +42,6 @@ nlohmann::json PortsJsonObject::toJson() const {
val["name"] = m_name;
}

if (m_macIsSet) {
val["mac"] = m_mac;
}

return val;
}

Expand All @@ -69,24 +60,6 @@ bool PortsJsonObject::nameIsSet() const {



std::string PortsJsonObject::getMac() const {
return m_mac;
}

void PortsJsonObject::setMac(std::string value) {
m_mac = value;
m_macIsSet = true;
}

bool PortsJsonObject::macIsSet() const {
return m_macIsSet;
}

void PortsJsonObject::unsetMac() {
m_macIsSet = false;
}


}
}
}
Expand Down
10 changes: 0 additions & 10 deletions src/services/pcn-simplebridge/src/serializer/PortsJsonObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,9 @@ class PortsJsonObject : public JsonObjectBase {
void setName(std::string value);
bool nameIsSet() const;

/// <summary>
/// MAC address of the port
/// </summary>
std::string getMac() const;
void setMac(std::string value);
bool macIsSet() const;
void unsetMac();

private:
std::string m_name;
bool m_nameIsSet;
std::string m_mac;
bool m_macIsSet;
};

}
Expand Down

0 comments on commit 8659149

Please sign in to comment.