summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2016-12-25 12:54:09 +0200
committerimarom <imarom@cisco.com>2016-12-25 13:50:56 +0200
commit34cb66c9f06c7a43e68a17b4a8802f8d34298a65 (patch)
treeaa6b081213e5715cf09a18503cc7b0a20168c6fc /src
parent549f2750ab22db5695a8d29575c136ab06e37235 (diff)
refactor layer config on prot attributes
added guard against unconfigured MAC when going up with empty config file Signed-off-by: imarom <imarom@cisco.com>
Diffstat (limited to 'src')
-rwxr-xr-xsrc/bp_sim.h4
-rw-r--r--src/main_dpdk.cpp12
-rw-r--r--src/stateless/cp/trex_stateless_port.cpp30
-rw-r--r--src/trex_port_attr.cpp174
-rwxr-xr-xsrc/trex_port_attr.h214
5 files changed, 275 insertions, 159 deletions
diff --git a/src/bp_sim.h b/src/bp_sim.h
index a41349d0..328820cd 100755
--- a/src/bp_sim.h
+++ b/src/bp_sim.h
@@ -635,7 +635,8 @@ private:
typedef struct mac_align_t_ {
uint8_t dest[6];
uint8_t src[6];
- uint8_t pad[4];
+ uint8_t is_set;
+ uint8_t pad[3];
} mac_align_t ;
struct CMacAddrCfg {
@@ -643,6 +644,7 @@ public:
CMacAddrCfg (){
memset(u.m_data,0,sizeof(u.m_data));
u.m_mac.dest[3]=1;
+ u.m_mac.is_set = 0;
}
union {
mac_align_t m_mac;
diff --git a/src/main_dpdk.cpp b/src/main_dpdk.cpp
index ffeec82a..95ab22b1 100644
--- a/src/main_dpdk.cpp
+++ b/src/main_dpdk.cpp
@@ -1762,7 +1762,7 @@ bool DpdkTRexPortAttr::update_link_status_nowait(){
/* in case of link status change - notify the dest object */
if (new_link.link_status != m_link.link_status) {
- get_dest().on_link_down();
+ on_link_down();
}
}
@@ -3407,8 +3407,8 @@ void CGlobalTRex::pre_test() {
m_trex_stateless->get_port_by_id(port_id)->set_l3_mode(src_ipv4, dg, dst_mac);
}
- /* L2 mode */
- } else {
+ /* L2 mode */
+ } else if (CGlobalInfo::m_options.m_mac_addr[port_id].u.m_mac.is_set) {
m_trex_stateless->get_port_by_id(port_id)->set_l2_mode(dst_mac);
}
}
@@ -4041,7 +4041,7 @@ void CGlobalTRex::dump_links_status(FILE *fd){
bool CGlobalTRex::lookup_port_by_mac(const uint8_t *mac, uint8_t &port_id) {
for (int i = 0; i < m_max_ports; i++) {
- if (memcmp(m_ports[i].get_port_attr()->get_src_mac(), mac, 6) == 0) {
+ if (memcmp(m_ports[i].get_port_attr()->get_layer_cfg().get_ether().get_src(), mac, 6) == 0) {
port_id = i;
return true;
}
@@ -5364,6 +5364,8 @@ int update_global_info_from_platform_file(){
for (i=0; i<port_size; i++){
cg->m_mac_info[i].copy_src(( char *)CGlobalInfo::m_options.m_mac_addr[i].u.m_mac.src) ;
cg->m_mac_info[i].copy_dest(( char *)CGlobalInfo::m_options.m_mac_addr[i].u.m_mac.dest) ;
+ CGlobalInfo::m_options.m_mac_addr[i].u.m_mac.is_set = 1;
+
CGlobalInfo::m_options.m_ip_cfg[i].set_def_gw(cg->m_mac_info[i].get_def_gw());
CGlobalInfo::m_options.m_ip_cfg[i].set_ip(cg->m_mac_info[i].get_ip());
CGlobalInfo::m_options.m_ip_cfg[i].set_mask(cg->m_mac_info[i].get_mask());
@@ -7441,7 +7443,7 @@ int DpdkTRexPortAttr::set_rx_filter_mode(rx_filter_mode_e rx_filter_mode) {
bool DpdkTRexPortAttr::is_loopback() const {
uint8_t port_id;
- return g_trex.lookup_port_by_mac(m_dest.get_dest_mac(), port_id);
+ return g_trex.lookup_port_by_mac(m_layer_cfg.get_ether().get_dst(), port_id);
}
/**
diff --git a/src/stateless/cp/trex_stateless_port.cpp b/src/stateless/cp/trex_stateless_port.cpp
index e9b3c6d4..7d331c6e 100644
--- a/src/stateless/cp/trex_stateless_port.cpp
+++ b/src/stateless/cp/trex_stateless_port.cpp
@@ -1012,12 +1012,10 @@ TrexStatelessPort::set_l2_mode(const uint8_t *dest_mac) {
/* not valid under traffic */
verify_state(PORT_STATE_IDLE | PORT_STATE_STREAMS, "set_l2_mode");
- /* no IPv4 src */
- getPortAttrObj()->set_src_ipv4(0);
-
- /* set destination as MAC */
- getPortAttrObj()->get_dest().set_dest(dest_mac);
-
+ /* configure port attributes for L2 */
+ getPortAttrObj()->set_l2_mode(dest_mac);
+
+ /* update RX core */
TrexStatelessRxSetL2Mode *msg = new TrexStatelessRxSetL2Mode(m_port_id);
send_message_to_rx( (TrexStatelessCpToRxMsgBase *)msg );
}
@@ -1031,15 +1029,12 @@ TrexStatelessPort::set_l3_mode(uint32_t src_ipv4, uint32_t dest_ipv4) {
/* not valid under traffic */
verify_state(PORT_STATE_IDLE | PORT_STATE_STREAMS, "set_l3_mode");
- /* set src IPv4 */
- getPortAttrObj()->set_src_ipv4(src_ipv4);
-
- /* set dest IPv4 */
- getPortAttrObj()->get_dest().set_dest(dest_ipv4);
-
+ /* configure port attributes with L3 */
+ getPortAttrObj()->set_l3_mode(src_ipv4, dest_ipv4);
+
/* send RX core the relevant info */
CManyIPInfo ip_info;
- ip_info.insert(COneIPv4Info(src_ipv4, 0, getPortAttrObj()->get_src_mac()));
+ ip_info.insert(COneIPv4Info(src_ipv4, 0, getPortAttrObj()->get_layer_cfg().get_ether().get_src()));
TrexStatelessRxSetL3Mode *msg = new TrexStatelessRxSetL3Mode(m_port_id, ip_info, false);
send_message_to_rx( (TrexStatelessCpToRxMsgBase *)msg );
@@ -1054,15 +1049,12 @@ TrexStatelessPort::set_l3_mode(uint32_t src_ipv4, uint32_t dest_ipv4, const uint
verify_state(PORT_STATE_IDLE | PORT_STATE_STREAMS, "set_l3_mode");
- /* set src IPv4 */
- getPortAttrObj()->set_src_ipv4(src_ipv4);
-
- /* set dest IPv4 + resolved MAC */
- getPortAttrObj()->get_dest().set_dest(dest_ipv4, resolved_mac);
+ /* configure port attributes with L3 */
+ getPortAttrObj()->set_l3_mode(src_ipv4, dest_ipv4, resolved_mac);
/* send RX core the relevant info */
CManyIPInfo ip_info;
- ip_info.insert(COneIPv4Info(src_ipv4, 0, getPortAttrObj()->get_src_mac()));
+ ip_info.insert(COneIPv4Info(src_ipv4, 0, getPortAttrObj()->get_layer_cfg().get_ether().get_src()));
bool is_grat_arp_needed = !getPortAttrObj()->is_loopback();
diff --git a/src/trex_port_attr.cpp b/src/trex_port_attr.cpp
index 2a68fcb9..4c5ac9e4 100644
--- a/src/trex_port_attr.cpp
+++ b/src/trex_port_attr.cpp
@@ -17,96 +17,118 @@ limitations under the License.
#include "trex_port_attr.h"
#include "bp_sim.h"
-DestAttr::DestAttr(uint8_t port_id) {
- m_port_id = port_id;
+LayerConfigMAC::LayerConfigMAC(uint8_t port_id) {
+ /* use this for container (DP copies from here) */
+ m_src_mac = CGlobalInfo::m_options.m_mac_addr[port_id].u.m_mac.src;
+ m_dst_mac = CGlobalInfo::m_options.m_mac_addr[port_id].u.m_mac.dest;
- m_mac = CGlobalInfo::m_options.m_mac_addr[port_id].u.m_mac.dest;
- m_type = DEST_TYPE_MAC;
-
- /* save the default */
- memcpy(m_default_mac, m_mac, 6);
-}
-
-
-/**
- * set dest as an IPv4 unresolved
- */
-void
-DestAttr::set_dest(uint32_t ipv4) {
- assert(ipv4 != 0);
-
- m_ipv4 = ipv4;
- memset(m_mac, 0, 6); // just to be on the safe side
- m_type = DEST_TYPE_IPV4_UNRESOLVED;
+ m_state = STATE_UNCONFIGRED;
}
-/**
- * set dest as a resolved IPv4
- */
-void
-DestAttr::set_dest(uint32_t ipv4, const uint8_t *mac) {
- assert(ipv4 != 0);
-
- m_ipv4 = ipv4;
+Json::Value
+LayerConfigMAC::to_json() const {
+ Json::Value output;
+
+ output["src"] = utl_macaddr_to_str(m_src_mac);
+ output["dst"] = utl_macaddr_to_str(m_dst_mac);
+
+ switch (m_state) {
+ case STATE_CONFIGURED:
+ output["state"] = "configured";
+ break;
+ case STATE_UNCONFIGRED:
+ output["state"] = "unconfigured";
+ break;
+
+ default:
+ assert(0);
+ }
- /* source might be the same as dest (this shadows the datapath memory) */
- memmove(m_mac, mac, 6);
- m_type = DEST_TYPE_IPV4;
-}
-
-/**
- * dest dest as MAC
- *
- */
-void
-DestAttr::set_dest(const uint8_t *mac) {
-
- m_ipv4 = 0;
- /* source might be the same as dest (this shadows the datapath memory) */
- memmove(m_mac, mac, 6);
- m_type = DEST_TYPE_MAC;
+ return output;
}
-void
-DestAttr::to_json(Json::Value &output) const {
- switch (m_type) {
+Json::Value
+LayerConfigIPv4::to_json() const {
+ Json::Value output;
- case DEST_TYPE_IPV4:
- output["type"] = "ipv4";
- output["ipv4"] = utl_uint32_to_ipv4(m_ipv4);
- output["arp"] = utl_macaddr_to_str(m_mac);
+ switch (m_state) {
+ case STATE_NONE:
+ output["state"] = "none";
break;
- case DEST_TYPE_IPV4_UNRESOLVED:
- output["type"] = "ipv4_u";
- output["ipv4"] = utl_uint32_to_ipv4(m_ipv4);
+ case STATE_UNRESOLVED:
+ output["state"] = "unresolved";
break;
-
- case DEST_TYPE_MAC:
- output["type"] = "mac";
- output["mac"] = utl_macaddr_to_str(m_mac);
+
+ case STATE_RESOLVED:
+ output["state"] = "resolved";
break;
-
+
default:
assert(0);
}
+
+ if (m_state != STATE_NONE) {
+ output["src"] = utl_uint32_to_ipv4(m_src_ipv4);
+ output["dst"] = utl_uint32_to_ipv4(m_dst_ipv4);
+ }
+
+ return output;
+}
+
+void LayerConfig::set_l2_mode(const uint8_t *dst_mac) {
+ /* set dst MAC */
+ m_l2_config.set_dst(dst_mac);
+ m_l2_config.set_state(LayerConfigMAC::STATE_CONFIGURED);
+
+ /* remove any IPv4 configuration*/
+ m_l3_ipv4_config.set_state(LayerConfigIPv4::STATE_NONE);
+}
+void LayerConfig::set_l3_mode(uint32_t src_ipv4, uint32_t dst_ipv4) {
+
+ /* L2 config */
+ m_l2_config.set_state(LayerConfigMAC::STATE_UNCONFIGRED);
+
+ /* L3 config */
+ m_l3_ipv4_config.set_src(src_ipv4);
+ m_l3_ipv4_config.set_dst(dst_ipv4);
+ m_l3_ipv4_config.set_state(LayerConfigIPv4::STATE_UNRESOLVED);
}
-const uint8_t *
-TRexPortAttr::get_src_mac() const {
- return CGlobalInfo::m_options.get_src_mac_addr(m_port_id);
+void LayerConfig::set_l3_mode(uint32_t src_ipv4, uint32_t dst_ipv4, const uint8_t *resolved_mac) {
+
+ /* L2 config */
+ m_l2_config.set_dst(resolved_mac);
+ m_l2_config.set_state(LayerConfigMAC::STATE_CONFIGURED);
+
+ /* L3 config */
+ m_l3_ipv4_config.set_src(src_ipv4);
+ m_l3_ipv4_config.set_dst(dst_ipv4);
+ m_l3_ipv4_config.set_state(LayerConfigIPv4::STATE_RESOLVED);
}
void
-TRexPortAttr::set_src_ipv4(uint32_t addr) {
- m_src_ipv4 = addr;
+LayerConfig::on_link_down() {
+
+ m_l2_config.set_state(LayerConfigMAC::STATE_UNCONFIGRED);
- /* when IP source changes - consider this as link down */
- m_dest.on_link_down();
+ if (m_l3_ipv4_config.get_state() == LayerConfigIPv4::STATE_RESOLVED) {
+ m_l3_ipv4_config.set_state(LayerConfigIPv4::STATE_UNRESOLVED);
+ }
}
+
+Json::Value
+LayerConfig::to_json() const {
+ Json::Value output;
+ output["ether"] = m_l2_config.to_json();
+ output["ipv4"] = m_l3_ipv4_config.to_json();
+
+ return output;
+}
+
std::string
TRexPortAttr::get_rx_filter_mode() const {
switch (m_rx_filter_mode) {
@@ -119,34 +141,24 @@ TRexPortAttr::get_rx_filter_mode() const {
}
}
+void
+TRexPortAttr::on_link_down() {
+ m_layer_cfg.on_link_down();
+}
void
TRexPortAttr::to_json(Json::Value &output) {
- output["src_mac"] = utl_macaddr_to_str(get_src_mac());
output["promiscuous"]["enabled"] = get_promiscuous();
output["link"]["up"] = is_link_up();
output["speed"] = get_link_speed() / 1000; // make sure we have no cards of less than 1 Gbps
output["rx_filter_mode"] = get_rx_filter_mode();
- if (get_src_ipv4() != 0) {
- output["src_ipv4"] = utl_uint32_to_ipv4(get_src_ipv4());
- } else {
- output["src_ipv4"] = Json::nullValue;
- }
-
-
int mode;
get_flow_ctrl(mode);
output["fc"]["mode"] = mode;
- m_dest.to_json(output["dest"]);
-
+ output["layer_cfg"] = m_layer_cfg.to_json();
}
-void
-TRexPortAttr::update_src_dst_mac(uint8_t *raw_pkt) const {
- memcpy(raw_pkt, m_dest.get_dest_mac(), 6);
- memcpy(raw_pkt + 6, get_src_mac(), 6);
-}
diff --git a/src/trex_port_attr.h b/src/trex_port_attr.h
index 7336befa..01ffe424 100755
--- a/src/trex_port_attr.h
+++ b/src/trex_port_attr.h
@@ -27,84 +27,168 @@ limitations under the License.
#include <string.h>
/**
- * destination port attribute
- *
+ * holds L2 MAC configuration
*/
-class DestAttr {
-
+class LayerConfigMAC {
public:
-
- DestAttr(uint8_t port_id);
/**
- * dest can be either MAC IPv4, or IPv4 unresolved
+ * IPv4 state of resolution
*/
- enum dest_type_e {
- DEST_TYPE_IPV4 = 1,
- DEST_TYPE_IPV4_UNRESOLVED,
- DEST_TYPE_MAC,
+ enum ether_state_e {
+ STATE_UNCONFIGRED,
+ STATE_CONFIGURED
};
- /**
- * set dest as an IPv4 unresolved
- */
- void set_dest(uint32_t ipv4);
+ LayerConfigMAC(uint8_t port_id);
+
+ void set_src(const uint8_t *src_mac) {
+ memcpy(m_src_mac, src_mac, 6);
+ }
+
+ void set_dst(const uint8_t *dst_mac) {
+ memcpy(m_dst_mac, dst_mac, 6);
+ }
+
+ const uint8_t *get_src() const {
+ return m_src_mac;
+ }
+
+ const uint8_t *get_dst() const {
+ return m_dst_mac;
+ }
+
+ void set_state(ether_state_e state) {
+ m_state = state;
+ }
+
+ ether_state_e get_state() const {
+ return m_state;
+ }
+
+ Json::Value to_json() const;
+
+private:
+ uint8_t *m_src_mac;
+ uint8_t *m_dst_mac;
+ ether_state_e m_state;
+};
+
+/**
+ * holds L3 IPv4 configuration
+ */
+class LayerConfigIPv4 {
+
+public:
/**
- * set dest as a resolved IPv4
+ * IPv4 state of resolution
*/
- void set_dest(uint32_t ipv4, const uint8_t *mac);
+ enum ipv4_state_e {
+ STATE_NONE,
+ STATE_UNRESOLVED,
+ STATE_RESOLVED
+ };
+
+ LayerConfigIPv4() {
+ m_state = STATE_NONE;
+ }
+
+ void set_src(uint32_t src_ipv4) {
+ m_src_ipv4 = src_ipv4;
+ }
+
+ void set_dst(uint32_t dst_ipv4) {
+ m_dst_ipv4 = dst_ipv4;
+ }
+
+ void set_state(ipv4_state_e state) {
+ m_state = state;
+ }
+
+ uint32_t get_src() const {
+ return m_src_ipv4;
+ }
+
+ uint32_t get_dst() const {
+ return m_dst_ipv4;
+ }
+
+ ipv4_state_e get_state() const {
+ return m_state;
+ }
+
+ Json::Value to_json() const;
+
+private:
+ ipv4_state_e m_state;
+ uint32_t m_src_ipv4;
+ uint32_t m_dst_ipv4;
+};
+
+/**
+ * holds all layer configuration
+ *
+ * @author imarom (12/25/2016)
+ */
+class LayerConfig {
+public:
+
+ LayerConfig(uint8_t port_id) : m_l2_config(port_id) {
+ m_port_id = port_id;
+ }
/**
- * set dest as a plain MAC
+ * configure port for L2 (no L3)
+ *
*/
- void set_dest(const uint8_t *mac);
+ void set_l2_mode(const uint8_t *dst_mac);
-
/**
- * return true if destination is resolved
+ * configure port IPv4 (unresolved)
+ *
*/
- bool is_resolved() const {
- return (m_type != DEST_TYPE_IPV4_UNRESOLVED);
- }
+ void set_l3_mode(uint32_t src_ipv4, uint32_t dst_ipv4);
/**
- * get the dest mac
- * if the dest is not resolved
- * it will return the default MAC
+ * configure port IPv4 (resolved)
+ *
*/
- const uint8_t *get_dest_mac() const {
- return m_mac;
- }
+ void set_l3_mode(uint32_t src_ipv4, uint32_t dst_ipv4, const uint8_t *resolved_mac);
/**
- * when link gets down - this should be called
+ * event handler in case of a link down event
*
+ * @author imarom (12/22/2016)
*/
- void on_link_down() {
- if (m_type == DEST_TYPE_IPV4) {
- /* reset the IPv4 dest with no resolution */
- set_dest(m_ipv4);
- }
+ void on_link_down();
+
+ const LayerConfigMAC& get_ether() const {
+ return m_l2_config;
}
- void to_json(Json::Value &output) const;
+ const LayerConfigIPv4& get_ipv4() const {
+ return m_l3_ipv4_config;
+ }
+ /**
+ * write state to JSON
+ *
+ */
+ Json::Value to_json() const;
+
private:
- uint32_t m_ipv4;
- uint8_t *m_mac;
- dest_type_e m_type;
- uint8_t m_port_id;
-private:
- uint8_t m_default_mac[6];
+ uint8_t m_port_id;
+ LayerConfigMAC m_l2_config;
+ LayerConfigIPv4 m_l3_ipv4_config;
};
class TRexPortAttr {
public:
- TRexPortAttr(uint8_t port_id) : m_dest(port_id) {
+ TRexPortAttr(uint8_t port_id) : m_layer_cfg(port_id) {
m_src_ipv4 = 0;
}
@@ -135,15 +219,8 @@ public:
virtual void get_supported_speeds(supp_speeds_t &supp_speeds) = 0;
virtual bool is_loopback() const = 0;
- uint32_t get_src_ipv4() const {return m_src_ipv4;}
- DestAttr & get_dest() {return m_dest;}
-
- const uint8_t *get_src_mac() const;
std::string get_rx_filter_mode() const;
- /* for a raw packet, write the src/dst MACs */
- void update_src_dst_mac(uint8_t *raw_pkt) const;
-
/* SETTERS */
virtual int set_promiscuous(bool enabled) = 0;
virtual int add_mac(char * mac) = 0;
@@ -152,8 +229,34 @@ public:
virtual int set_led(bool on) = 0;
virtual int set_rx_filter_mode(rx_filter_mode_e mode) = 0;
- void set_src_ipv4(uint32_t addr);
+ /**
+ * configures port for L2 mode
+ *
+ */
+ void set_l2_mode(const uint8_t *dest_mac) {
+ m_layer_cfg.set_l2_mode(dest_mac);
+ }
+
+ /**
+ * configures port in L3 mode
+ * unresolved
+ */
+ void set_l3_mode(uint32_t src_ipv4, uint32_t dst_ipv4) {
+ m_layer_cfg.set_l3_mode(src_ipv4, dst_ipv4);
+ }
+ /**
+ * configure port for L3 mode
+ * resolved
+ */
+ void set_l3_mode(uint32_t src_ipv4, uint32_t dst_ipv4, const uint8_t *resolved_mac) {
+ m_layer_cfg.set_l3_mode(src_ipv4, dst_ipv4, resolved_mac);
+ }
+
+ const LayerConfig & get_layer_cfg() const {
+ return m_layer_cfg;
+ }
+
/* DUMPS */
virtual void dump_link(FILE *fd) = 0;
@@ -164,12 +267,17 @@ public:
return m_port_id;
}
+ /**
+ * event handler for link down event
+ */
+ void on_link_down();
+
protected:
uint8_t m_port_id;
rte_eth_link m_link;
uint32_t m_src_ipv4;
- DestAttr m_dest;
+ LayerConfig m_layer_cfg;
struct rte_eth_dev_info dev_info;