summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorIdo Barnea <ibarnea@cisco.com>2017-02-15 17:17:18 +0200
committerIdo Barnea <ibarnea@cisco.com>2017-02-16 15:38:30 +0200
commitaf52e17f717ee272577bcaa3524b272531752423 (patch)
treed6e05ad8e24629776549da98910d43801295e9f3 /src
parent76338aa3565f381df1f415b10d3d22bb5b8d71b6 (diff)
VLAN keyword in platform config file will now make all traffic be sent over vlan
Signed-off-by: Ido Barnea <ibarnea@cisco.com>
Diffstat (limited to 'src')
-rwxr-xr-xsrc/bp_gtest.cpp8
-rwxr-xr-xsrc/bp_sim.cpp46
-rwxr-xr-xsrc/bp_sim.h34
-rw-r--r--src/main_dpdk.cpp85
-rw-r--r--src/pal/common/common_mbuf.h6
-rwxr-xr-xsrc/pal/linux/mbuf.h2
6 files changed, 115 insertions, 66 deletions
diff --git a/src/bp_gtest.cpp b/src/bp_gtest.cpp
index 57cf2ffa..e1bfeeab 100755
--- a/src/bp_gtest.cpp
+++ b/src/bp_gtest.cpp
@@ -449,8 +449,8 @@ TEST_F(basic, ipv4_vlan) {
CParserOption * po =&CGlobalInfo::m_options;
po->preview.setVMode(3);
po->preview.setFileWrite(true);
- po->cfg_file ="cap2/ipv4_vlan.yaml";
- po->out_file ="exp/ipv4_vlan";
+ po->cfg_file ="cap2/ipv4_load_balance.yaml";
+ po->out_file ="exp/ipv4_load_balance";
bool res=t1.init();
EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
}
@@ -462,8 +462,8 @@ TEST_F(basic, ipv6_vlan) {
po->preview.setVMode(3);
po->preview.set_ipv6_mode_enable(true);
po->preview.setFileWrite(true);
- po->cfg_file ="cap2/ipv6_vlan.yaml";
- po->out_file ="exp/ipv6_vlan";
+ po->cfg_file ="cap2/ipv6_load_balance.yaml";
+ po->out_file ="exp/ipv6_load_balance";
bool res=t1.init();
EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
}
diff --git a/src/bp_sim.cpp b/src/bp_sim.cpp
index f540f21b..d3c8abbd 100755
--- a/src/bp_sim.cpp
+++ b/src/bp_sim.cpp
@@ -758,12 +758,23 @@ void CPreviewMode::Dump(FILE *fd){
fprintf(fd," flow-flip : %d\n", (int)getClientServerFlowFlip() );
fprintf(fd," no clean close : %d\n", (int)getNoCleanFlowClose() );
fprintf(fd," zmq_publish : %d\n", (int)get_zmq_publish_enable() );
- fprintf(fd," vlan_enable : %d\n", (int)get_vlan_mode_enable() );
+ fprintf(fd," vlan mode : %d\n", get_vlan_mode());
fprintf(fd," client_cfg : %d\n", (int)get_is_client_cfg_enable() );
fprintf(fd," mbuf_cache_disable : %d\n", (int)isMbufCacheDisabled() );
fprintf(fd," vm mode : %d\n", (int)get_vm_one_queue_enable()?1:0 );
}
+void CPreviewMode::set_vlan_mode_verify(uint8_t mode) {
+ // validate that there is no vlan both in platform config file and traffic profile
+ if ((CGlobalInfo::m_options.preview.get_vlan_mode() != CPreviewMode::VLAN_MODE_NONE) &&
+ ( CGlobalInfo::m_options.preview.get_vlan_mode() != mode ) ) {
+ fprintf(stderr, "Error: You are not allowed to specify vlan both in platform config file (--cfg) and traffic config file (-f)\n");
+ fprintf(stderr, " Please remove vlan definition from one of the files, and try again.\n");
+ exit(1);
+ }
+ set_vlan_mode(mode);
+}
+
void CFlowGenStats::clear(){
m_nat_lookup_no_flow_id=0;
m_total_bytes=0;
@@ -5060,9 +5071,14 @@ int CFlowGenList::load_from_yaml(std::string file_name,
}
/* move it to global info, better CPU D-cache usage */
- CGlobalInfo::m_options.preview.set_vlan_mode_enable(m_yaml_info.m_vlan_info.m_enable);
- CGlobalInfo::m_options.m_vlan_port[0] = m_yaml_info.m_vlan_info.m_vlan_per_port[0];
- CGlobalInfo::m_options.m_vlan_port[1] = m_yaml_info.m_vlan_info.m_vlan_per_port[1];
+ if (m_yaml_info.m_vlan_info.m_enable) {
+ CGlobalInfo::m_options.preview.set_vlan_mode_verify(CPreviewMode::VLAN_MODE_LOAD_BALANCE);
+ CGlobalInfo::m_options.m_vlan_port[0] = m_yaml_info.m_vlan_info.m_vlan_per_port[0];
+ CGlobalInfo::m_options.m_vlan_port[1] = m_yaml_info.m_vlan_info.m_vlan_per_port[1];
+ } else {
+ CGlobalInfo::m_options.m_vlan_port[0] = 0;
+ CGlobalInfo::m_options.m_vlan_port[1] = 0;
+ }
CGlobalInfo::m_options.preview.set_mac_ip_overide_enable(m_yaml_info.m_mac_replace_by_ip);
if ( m_yaml_info.m_mac_base.size() != 6 ){
@@ -5386,8 +5402,8 @@ void CParserOption::dump(FILE *fd){
fprintf(fd," tw_levels : %lu usec \n",(ulong)get_tw_levels());
- if (preview.get_vlan_mode_enable() ) {
- fprintf(fd," vlans : [%d,%d] \n",m_vlan_port[0],m_vlan_port[1]);
+ if (preview.get_vlan_mode() == CPreviewMode::VLAN_MODE_LOAD_BALANCE) {
+ fprintf(fd," vlans (for load balance) : [%d,%d] \n",m_vlan_port[0],m_vlan_port[1]);
}
int i;
@@ -5397,15 +5413,23 @@ void CParserOption::dump(FILE *fd){
dump_mac_addr(fd,lp->u.m_mac.dest);
fprintf(fd," src:");
dump_mac_addr(fd,lp->u.m_mac.src);
+ if (preview.get_vlan_mode() == CPreviewMode::VLAN_MODE_NORMAL) {
+ fprintf(fd, " vlan:%d", m_ip_cfg[i].get_vlan());
+ }
fprintf(fd,"\n");
}
+
}
void CParserOption::verify() {
/* check for mutual exclusion options */
- if (preview.get_is_client_cfg_enable()) {
- if (preview.get_vlan_mode_enable() || preview.get_mac_ip_overide_enable()) {
- throw std::runtime_error("VLAN / MAC override cannot be combined with client configuration");
+ if ( preview.get_is_client_cfg_enable() ) {
+ if ( preview.get_vlan_mode() == CPreviewMode::VLAN_MODE_LOAD_BALANCE ) {
+ throw std::runtime_error("--client_cfg_file option can not be combined with specifing VLAN in traffic profile");
+ }
+
+ if (preview.get_mac_ip_overide_enable()) {
+ throw std::runtime_error("MAC override can not be combined with --client_cfg_file option");
}
}
}
@@ -5754,9 +5778,11 @@ int CErfIF::send_node(CGenNode *node){
if (CGlobalInfo::m_options.preview.get_is_client_cfg_enable()) {
apply_client_config(node->m_client_cfg, dir);
- } else if (CGlobalInfo::m_options.preview.get_vlan_mode_enable()) {
+ // for simulation, VLAN_MODE_NORMAL is not relevant, since it uses vlan_id set in platform config file
+ } else if (CGlobalInfo::m_options.preview.get_vlan_mode() == CPreviewMode::VLAN_MODE_LOAD_BALANCE) {
uint8_t vlan_port = (node->m_src_ip & 1);
uint16_t vlan_id = CGlobalInfo::m_options.m_vlan_port[vlan_port];
+
add_vlan(vlan_id);
}
diff --git a/src/bp_sim.h b/src/bp_sim.h
index 22968b2c..bc2eaf03 100755
--- a/src/bp_sim.h
+++ b/src/bp_sim.h
@@ -386,14 +386,20 @@ public:
class CPreviewMode {
public:
+ enum {
+ VLAN_MODE_NONE = 0,
+ VLAN_MODE_NORMAL = 1,
+ VLAN_MODE_LOAD_BALANCE = 2,
+ };
+
CPreviewMode(){
clean();
}
void clean(){
m_flags = 0;
m_flags1=0;
- set_vlan_mode_enable(false);
setCores(1);
+ set_vlan_mode(VLAN_MODE_NONE);
set_zmq_publish_enable(true);
}
@@ -511,7 +517,13 @@ public:
return (btGetMaskBit32(m_flags,25,25) ? true:false);
}
- // bit 26 is free. Was deprecated option.
+ void set_pcap_mode_enable(bool enable){
+ btSetMaskBit32(m_flags,26,26,enable?1:0);
+ }
+
+ bool get_pcap_mode_enable(){
+ return (btGetMaskBit32(m_flags,26,26) ? true:false);
+ }
void set_zmq_publish_enable(bool enable){
btSetMaskBit32(m_flags,27,27,enable?1:0);
@@ -521,23 +533,15 @@ public:
return (btGetMaskBit32(m_flags,27,27) ? true:false);
}
- void set_pcap_mode_enable(bool enable){
- btSetMaskBit32(m_flags,28,28,enable?1:0);
- }
-
- bool get_pcap_mode_enable(){
- return (btGetMaskBit32(m_flags,28,28) ? true:false);
- }
-
- /* VLAN enable/disable */
- bool get_vlan_mode_enable(){
- return (btGetMaskBit32(m_flags,29,29) ? true:false);
+ uint8_t get_vlan_mode() {
+ return (btGetMaskBit32(m_flags, 29, 28));
}
- void set_vlan_mode_enable(bool enable){
- btSetMaskBit32(m_flags,29,29,enable?1:0);
+ void set_vlan_mode(uint8_t mode) {
+ btSetMaskBit32(m_flags, 29, 28, mode);
}
+ void set_vlan_mode_verify(uint8_t mode);
bool get_mac_ip_overide_enable(){
return (btGetMaskBit32(m_flags,30,30) ? true:false);
}
diff --git a/src/main_dpdk.cpp b/src/main_dpdk.cpp
index 5c9d2498..4e848f9e 100644
--- a/src/main_dpdk.cpp
+++ b/src/main_dpdk.cpp
@@ -1229,7 +1229,8 @@ static int parse_options(int argc, char *argv[], CParserOption* po, bool first_t
if ( get_is_stateless() ) {
if ( opt_vlan_was_set ) {
- po->preview.set_vlan_mode_enable(true);
+ // Only purpose of this in stateless is for configuring the 82599 rules correctly
+ po->preview.set_vlan_mode(CPreviewMode::VLAN_MODE_NORMAL);
}
if (CGlobalInfo::m_options.client_cfg_file != "") {
parse_err("Client config file is not supported with interactive (stateless) mode ");
@@ -1355,7 +1356,7 @@ public:
if (get_is_stateless()) {
m_port_conf.fdir_conf.flexbytes_offset = (14+4)/2;
/* Increment offset 4 bytes for the case where we add VLAN */
- if ( CGlobalInfo::m_options.preview.get_vlan_mode_enable() ) {
+ if ( CGlobalInfo::m_options.preview.get_vlan_mode() != CPreviewMode::VLAN_MODE_NONE) {
m_port_conf.fdir_conf.flexbytes_offset += (4/2);
}
} else {
@@ -1366,7 +1367,7 @@ public:
}
/* Increment offset 4 bytes for the case where we add VLAN */
- if ( CGlobalInfo::m_options.preview.get_vlan_mode_enable() ) {
+ if ( CGlobalInfo::m_options.preview.get_vlan_mode() != CPreviewMode::VLAN_MODE_NONE ) {
m_port_conf.fdir_conf.flexbytes_offset += (4/2);
}
}
@@ -2152,8 +2153,6 @@ protected:
rte_mbuf_t *m,
CVirtualIFPerSideStats * lp_stats);
- void add_vlan(rte_mbuf_t *m, uint16_t vlan_id);
-
protected:
uint8_t m_core_id;
uint16_t m_mbuf_cache;
@@ -2545,13 +2544,6 @@ void CCoreEthIF::apply_client_cfg(const ClientCfgBase *cfg, rte_mbuf_t *m, pkt_d
}
}
-
-void CCoreEthIF::add_vlan(rte_mbuf_t *m, uint16_t vlan_id) {
- m->ol_flags = PKT_TX_VLAN_PKT;
- m->l2_len = 14;
- m->vlan_tci = vlan_id;
-}
-
/**
* slow path features goes here (avoid multiple IFs)
*
@@ -2600,17 +2592,26 @@ int CCoreEthIF::send_node(CGenNode * node) {
single_port = node->get_is_all_flow_from_same_dir() ;
- if ( unlikely( CGlobalInfo::m_options.preview.get_vlan_mode_enable() ) ){
- /* which vlan to choose 0 or 1*/
- uint8_t vlan_port = (node->m_src_ip &1);
- uint16_t vlan_id = CGlobalInfo::m_options.m_vlan_port[vlan_port];
+ if ( unlikely(CGlobalInfo::m_options.preview.get_vlan_mode()
+ != CPreviewMode::VLAN_MODE_NONE) ) {
+ uint16_t vlan_id=0;
- if (likely( vlan_id >0 ) ) {
- dir = dir ^ vlan_port;
- }else{
- /* both from the same dir but with VLAN0 */
- vlan_id = CGlobalInfo::m_options.m_vlan_port[0];
- dir = dir ^ 0;
+ if (CGlobalInfo::m_options.preview.get_vlan_mode()
+ == CPreviewMode::VLAN_MODE_LOAD_BALANCE) {
+ /* which vlan to choose 0 or 1*/
+ uint8_t vlan_port = (node->m_src_ip & 1);
+ vlan_id = CGlobalInfo::m_options.m_vlan_port[vlan_port];
+ if (likely( vlan_id > 0 ) ) {
+ dir = dir ^ vlan_port;
+ } else {
+ /* both from the same dir but with VLAN0 */
+ vlan_id = CGlobalInfo::m_options.m_vlan_port[0];
+ }
+ } else if (CGlobalInfo::m_options.preview.get_vlan_mode()
+ == CPreviewMode::VLAN_MODE_NORMAL) {
+ CCorePerPort *lp_port = &m_ports[dir];
+ uint8_t port_id = lp_port->m_port->get_port_id();
+ vlan_id = CGlobalInfo::m_options.m_ip_cfg[port_id].get_vlan();
}
add_vlan(m, vlan_id);
@@ -2704,12 +2705,14 @@ public:
rte_mbuf_t *tx_pkts[2];
tx_pkts[0] = m;
- if ( likely( CGlobalInfo::m_options.preview.get_vlan_mode_enable() ) ){
- /* vlan mode is the default */
- /* set the vlan */
- m->ol_flags = PKT_TX_VLAN_PKT;
- m->vlan_tci =CGlobalInfo::m_options.m_vlan_port[0];
- m->l2_len =14;
+ uint8_t vlan_mode = CGlobalInfo::m_options.preview.get_vlan_mode();
+ if ( likely( vlan_mode != CPreviewMode::VLAN_MODE_NONE) ) {
+ if ( vlan_mode == CPreviewMode::VLAN_MODE_LOAD_BALANCE ) {
+ add_vlan(m, CGlobalInfo::m_options.m_vlan_port[0]);
+ } else if (vlan_mode == CPreviewMode::VLAN_MODE_NORMAL) {
+ uint8_t port_id = m_port->get_rte_port_id();
+ add_vlan(m, CGlobalInfo::m_options.m_ip_cfg[port_id].get_vlan());
+ }
}
uint16_t res=m_port->tx_burst(m_tx_queue_id,tx_pkts,1);
if ( res == 0 ) {
@@ -2799,12 +2802,15 @@ public:
private:
virtual int tx_common(rte_mbuf_t *m, bool fix_timestamp) {
- if ( likely( CGlobalInfo::m_options.preview.get_vlan_mode_enable() ) ){
- /* vlan mode is the default */
- /* set the vlan */
- m->ol_flags = PKT_TX_VLAN_PKT;
- m->vlan_tci =CGlobalInfo::m_options.m_vlan_port[0];
- m->l2_len =14;
+
+ uint8_t vlan_mode = CGlobalInfo::m_options.preview.get_vlan_mode();
+ if ( likely( vlan_mode != CPreviewMode::VLAN_MODE_NONE) ) {
+ if ( vlan_mode == CPreviewMode::VLAN_MODE_LOAD_BALANCE ) {
+ add_vlan(m, CGlobalInfo::m_options.m_vlan_port[0]);
+ } else if (vlan_mode == CPreviewMode::VLAN_MODE_NORMAL) {
+ uint8_t port_id = m_port->get_rte_port_id();
+ add_vlan(m, CGlobalInfo::m_options.m_ip_cfg[port_id].get_vlan());
+ }
}
/* allocate node */
@@ -4002,7 +4008,7 @@ bool CGlobalTRex::Create(){
}
if ( pre_yaml_info.m_vlan_info.m_enable ){
- CGlobalInfo::m_options.preview.set_vlan_mode_enable(true);
+ CGlobalInfo::m_options.preview.set_vlan_mode_verify(CPreviewMode::VLAN_MODE_LOAD_BALANCE);
}
/* End update pre flags */
@@ -5514,6 +5520,10 @@ int update_global_info_from_platform_file(){
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());
CGlobalInfo::m_options.m_ip_cfg[i].set_vlan(cg->m_mac_info[i].get_vlan());
+ // If one of the ports has vlan, work in vlan mode
+ if (cg->m_mac_info[i].get_vlan() != 0) {
+ CGlobalInfo::m_options.preview.set_vlan_mode_verify(CPreviewMode::VLAN_MODE_NORMAL);
+ }
}
}
@@ -6145,7 +6155,7 @@ int CTRexExtendedDriverBase1G::configure_rx_filter_rules_statefull(CPhyEthIF * _
_if->pci_reg_write( (E1000_FHFT(rule_id)+i) , 0);
}
- if ( CGlobalInfo::m_options.preview.get_vlan_mode_enable() ){
+ if (CGlobalInfo::m_options.preview.get_vlan_mode() != CPreviewMode::VLAN_MODE_NONE) {
len += 8;
if ( CGlobalInfo::m_options.preview.get_ipv6_mode_enable() ){
// IPv6 VLAN: NextHdr/HopLimit offset = 0x18
@@ -6544,7 +6554,8 @@ int CTRexExtendedDriverBase10G::wait_for_stable_link(){
}
CFlowStatParser *CTRexExtendedDriverBase10G::get_flow_stat_parser() {
- CFlowStatParser *parser = new C82599Parser(CGlobalInfo::m_options.preview.get_vlan_mode_enable() ? true:false);
+ CFlowStatParser *parser = new C82599Parser((CGlobalInfo::m_options.preview.get_vlan_mode()
+ != CPreviewMode::VLAN_MODE_NONE) ? true:false);
assert (parser);
return parser;
}
diff --git a/src/pal/common/common_mbuf.h b/src/pal/common/common_mbuf.h
index c52842bd..3816d203 100644
--- a/src/pal/common/common_mbuf.h
+++ b/src/pal/common/common_mbuf.h
@@ -17,6 +17,12 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
+static inline void add_vlan(rte_mbuf_t *m, uint16_t vlan_id) {
+ m->ol_flags = PKT_TX_VLAN_PKT;
+ m->l2_len = 14;
+ m->vlan_tci = vlan_id;
+}
+
static inline rte_mbuf_t * utl_rte_pktmbuf_add_after2(rte_mbuf_t *m1,rte_mbuf_t *m2){
utl_rte_pktmbuf_check(m1);
utl_rte_pktmbuf_check(m2);
diff --git a/src/pal/linux/mbuf.h b/src/pal/linux/mbuf.h
index 2996b514..17b7c7ad 100755
--- a/src/pal/linux/mbuf.h
+++ b/src/pal/linux/mbuf.h
@@ -32,6 +32,7 @@ typedef struct rte_mbuf rte_mbuf_t;
#define MAGIC2 0x11223344
#define IND_ATTACHED_MBUF (1ULL << 62) /**< Indirect attached mbuf */
+#define PKT_TX_VLAN_PKT (1ULL << 57) /**< TX packet is a 802.1q VLAN packet. */
#define RTE_MBUF_INDIRECT(mb) ((mb)->ol_flags & IND_ATTACHED_MBUF)
#define RTE_MBUF_TO_BADDR(mb) (((struct rte_mbuf *)(mb)) + 1)
#define RTE_MBUF_FROM_BADDR(ba) (((struct rte_mbuf *)(ba)) - 1)
@@ -65,6 +66,7 @@ struct rte_mbuf {
uint64_t ol_flags; /**< Offload features. */
uint16_t l2_len;
uint16_t l3_len;
+ uint16_t vlan_tci;
} ;
typedef struct rte_mempool rte_mempool_t;