summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorFilip Varga <fivarga@cisco.com>2020-04-06 12:52:33 +0200
committerFilip Varga <fivarga@cisco.com>2020-04-16 14:05:46 +0200
commit1a0a89770688a37e500f634b68805b1984eccac0 (patch)
treec6112c2210b3f9d6ebbe5fd5d20212440394e290 /src/plugins
parent8daeea9a5dc2c68c8e54fe7bdae98cec7072a9cd (diff)
nat: scavenging functionality removed
Type: refactor Change-Id: I9f743ba2818e1b1c5004c3575925cc7b479948d8 Signed-off-by: Filip Varga <fivarga@cisco.com>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/nat/in2out_ed.c27
-rwxr-xr-xsrc/plugins/nat/nat.c13
-rw-r--r--src/plugins/nat/nat.h13
-rw-r--r--src/plugins/nat/nat44/inlines.h170
-rw-r--r--src/plugins/nat/nat44_cli.c59
-rw-r--r--src/plugins/nat/nat_api.c25
-rw-r--r--src/plugins/nat/test/test_nat.py94
7 files changed, 9 insertions, 392 deletions
diff --git a/src/plugins/nat/in2out_ed.c b/src/plugins/nat/in2out_ed.c
index 807a716e942..a70369aae4e 100644
--- a/src/plugins/nat/in2out_ed.c
+++ b/src/plugins/nat/in2out_ed.c
@@ -309,18 +309,12 @@ slow_path_ed (snat_main_t * sm,
};
nat44_is_idle_session_ctx_t ctx;
- u32 cleared = 0;
-
if (PREDICT_FALSE (nat44_maximum_sessions_exceeded (sm, thread_index)))
{
- if (PREDICT_FALSE
- (!(cleared = nat44_users_cleanup (thread_index, now))))
- {
- b->error = node->errors[NAT_IN2OUT_ED_ERROR_MAX_SESSIONS_EXCEEDED];
- nat_ipfix_logging_max_sessions (thread_index, sm->max_translations);
- nat_elog_notice ("maximum sessions exceeded");
- return NAT_NEXT_DROP;
- }
+ b->error = node->errors[NAT_IN2OUT_ED_ERROR_MAX_SESSIONS_EXCEEDED];
+ nat_ipfix_logging_max_sessions (thread_index, sm->max_translations);
+ nat_elog_notice ("maximum sessions exceeded");
+ return NAT_NEXT_DROP;
}
key0.addr = key->l_addr;
@@ -339,16 +333,9 @@ slow_path_ed (snat_main_t * sm,
sm->port_per_thread,
tsm->snat_thread_index))
{
- if (cleared || !nat44_out_of_ports_cleanup (thread_index, now) ||
- nat_alloc_addr_and_port_ed (sm->addresses, rx_fib_index,
- thread_index, key, &key1,
- sm->port_per_thread,
- tsm->snat_thread_index))
- {
- nat_elog_notice ("addresses exhausted");
- b->error = node->errors[NAT_IN2OUT_ED_ERROR_OUT_OF_PORTS];
- return NAT_NEXT_DROP;
- }
+ nat_elog_notice ("addresses exhausted");
+ b->error = node->errors[NAT_IN2OUT_ED_ERROR_OUT_OF_PORTS];
+ return NAT_NEXT_DROP;
}
}
else
diff --git a/src/plugins/nat/nat.c b/src/plugins/nat/nat.c
index 8e20df4e64e..8ba276bc9b4 100755
--- a/src/plugins/nat/nat.c
+++ b/src/plugins/nat/nat.c
@@ -495,8 +495,6 @@ nat_user_get_or_create (snat_main_t * sm, ip4_address_t * addr, u32 fib_index,
pool_get (tsm->users, u);
clib_memset (u, 0, sizeof (*u));
- u->min_session_timeout = 0;
-
u->addr.as_u32 = addr->as_u32;
u->fib_index = fib_index;
@@ -630,9 +628,6 @@ nat_ed_session_alloc (snat_main_t * sm, snat_user_t * u, u32 thread_index,
if (PREDICT_FALSE
((u->nsessions + u->nstaticsessions) >= sm->max_translations_per_user))
{
- if (nat44_max_translations_per_user_cleanup (u, thread_index, now))
- goto alloc_new;
-
nat_elog_addr (SNAT_LOG_WARNING, "[warn] max translations per user",
clib_net_to_host_u32 (u->addr.as_u32));
snat_ipfix_logging_max_entries_per_user (thread_index,
@@ -4025,8 +4020,6 @@ snat_config (vlib_main_t * vm, unformat_input_t * input)
sm->tcp_established_timeout = tcp_established_timeout;
sm->icmp_timeout = icmp_timeout;
- sm->min_timeout = nat44_minimal_timeout (sm);
-
sm->user_buckets = user_buckets;
sm->user_memory_size = user_memory_size;
@@ -4107,12 +4100,6 @@ snat_config (vlib_main_t * vm, unformat_input_t * input)
/* *INDENT-OFF* */
vec_foreach (tsm, sm->per_thread_data)
{
- tsm->min_session_timeout = 0;
-
- tsm->cleared = 0;
- tsm->cleanup_runs = 0;
- tsm->cleanup_timeout = 0;
-
pool_alloc (tsm->sessions, sm->max_translations);
pool_alloc (tsm->list_pool, sm->max_translations);
pool_alloc (tsm->global_lru_pool, sm->max_translations);
diff --git a/src/plugins/nat/nat.h b/src/plugins/nat/nat.h
index 187e351d318..46f8b44dc11 100644
--- a/src/plugins/nat/nat.h
+++ b/src/plugins/nat/nat.h
@@ -361,8 +361,6 @@ typedef struct
u32 sessions_per_user_list_head_index;
u32 nsessions;
u32 nstaticsessions;
- /* discovered minimum session timeout time */
- u64 min_session_timeout;
} snat_user_t;
typedef struct
@@ -535,14 +533,6 @@ typedef struct
/* real thread index */
u32 thread_index;
- /* discovered minimum session timeout time */
- u64 min_session_timeout;
-
- /* session scavenging */
- u32 cleared;
- u32 cleanup_runs;
- f64 cleanup_timeout;
-
} snat_main_per_thread_data_t;
struct snat_main_s;
@@ -722,9 +712,6 @@ typedef struct snat_main_s
u32 inside_fib_index;
/* values of various timeouts */
-
- // min timeout of all proto timeouts
- u32 min_timeout;
// proto timeouts
u32 udp_timeout;
u32 tcp_transitory_timeout;
diff --git a/src/plugins/nat/nat44/inlines.h b/src/plugins/nat/nat44/inlines.h
index 631c4cd4104..541770ad102 100644
--- a/src/plugins/nat/nat44/inlines.h
+++ b/src/plugins/nat/nat44/inlines.h
@@ -31,19 +31,6 @@ nat44_maximum_sessions_exceeded (snat_main_t * sm, u32 thread_index)
return 0;
}
-static_always_inline f64
-nat44_minimal_timeout (snat_main_t * sm)
-{
- f64 min_timeout;
-
- min_timeout = clib_min (sm->udp_timeout, sm->icmp_timeout);
- min_timeout = clib_min (min_timeout, sm->icmp_timeout);
- min_timeout = clib_min (min_timeout, sm->tcp_transitory_timeout);
- min_timeout = clib_min (min_timeout, sm->tcp_established_timeout);
-
- return min_timeout;
-}
-
static_always_inline snat_session_t *
nat44_session_reuse_old (snat_main_t * sm, snat_user_t * u,
snat_session_t * s, u32 thread_index, f64 now)
@@ -66,7 +53,6 @@ nat44_session_reuse_old (snat_main_t * sm, snat_user_t * u,
return s;
}
-
static_always_inline snat_session_t *
nat44_session_alloc_new (snat_main_per_thread_data_t * tsm, snat_user_t * u,
f64 now)
@@ -122,7 +108,6 @@ nat44_user_del_sessions (snat_user_t * u, u32 thread_index)
elt = pool_elt_at_index (tsm->list_pool, elt->next);
nat44_free_session_data (sm, s, thread_index, 0);
- // TODO: needs refactoring as in nat44_user_session_cleanup
nat44_delete_session (sm, s, thread_index);
}
}
@@ -172,161 +157,6 @@ nat44_user_del (ip4_address_t * addr, u32 fib_index)
return rv;
}
-static_always_inline u32
-nat44_user_session_cleanup (snat_user_t * u, u32 thread_index, f64 now)
-{
- u32 cleared = 0;
- dlist_elt_t *elt;
- snat_session_t *s;
- u64 sess_timeout_time;
-
- snat_main_t *sm = &snat_main;
- snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
-
- if (now < u->min_session_timeout)
- goto done;
- u->min_session_timeout = now + sm->min_timeout;
-
- // get head
- elt = pool_elt_at_index (tsm->list_pool,
- u->sessions_per_user_list_head_index);
- // get first element
- elt = pool_elt_at_index (tsm->list_pool, elt->next);
-
- while (elt->value != ~0)
- {
- s = pool_elt_at_index (tsm->sessions, elt->value);
- elt = pool_elt_at_index (tsm->list_pool, elt->next);
-
- sess_timeout_time = s->last_heard +
- (f64) nat44_session_get_timeout (sm, s);
-
- if (s->tcp_close_timestamp)
- {
- sess_timeout_time =
- clib_min (sess_timeout_time, s->tcp_close_timestamp);
- }
-
- if (now < sess_timeout_time)
- continue;
-
- // do cleanup of this call (refactor for ED NAT44 only)
- nat44_free_session_data (sm, s, thread_index, 0);
-
- clib_dlist_remove (tsm->list_pool, s->per_user_index);
- pool_put_index (tsm->list_pool, s->per_user_index);
- clib_dlist_remove (tsm->global_lru_pool, s->global_lru_index);
- pool_put_index (tsm->global_lru_pool, s->global_lru_index);
- pool_put (tsm->sessions, s);
- vlib_set_simple_counter (&sm->total_sessions, thread_index, 0,
- pool_elts (tsm->sessions));
-
- if (snat_is_session_static (s))
- u->nstaticsessions--;
- else
- u->nsessions--;
-
- cleared++;
- }
-done:
- return cleared;
-}
-
-static_always_inline u32
-nat44_users_cleanup (u32 thread_index, f64 now)
-{
- snat_main_t *sm = &snat_main;
- snat_main_per_thread_data_t *tsm;
-
- u32 cleared = 0;
-
- snat_user_key_t u_key;
- clib_bihash_kv_8_8_t kv;
-
- snat_user_t *u = 0;
- u32 pool_index;
-
- tsm = vec_elt_at_index (sm->per_thread_data, thread_index);
-
- if (now < tsm->min_session_timeout)
- goto done;
- tsm->min_session_timeout = now + sm->min_timeout;
- // consider
- tsm->cleanup_timeout = tsm->min_session_timeout;
-
- pool_index = ~0;
- do
- {
- pool_index = pool_next_index (tsm->users, pool_index);
- if (pool_index == ~0)
- break;
- u = pool_elt_at_index (tsm->users, pool_index);
-
- cleared += nat44_user_session_cleanup (u, thread_index, now);
-
- if (u->nstaticsessions == 0 && u->nsessions == 0)
- {
- u_key.addr.as_u32 = u->addr.as_u32;
- u_key.fib_index = u->fib_index;
- kv.key = u_key.as_u64;
-
- // delete user
- pool_put_index (tsm->list_pool,
- u->sessions_per_user_list_head_index);
- pool_put (tsm->users, u);
- clib_bihash_add_del_8_8 (&tsm->user_hash, &kv, 0);
-
- // update total users counter
- vlib_set_simple_counter (&sm->total_users, thread_index, 0,
- pool_elts (tsm->users));
- }
- }
- while (1);
- tsm->cleared += cleared;
- tsm->cleanup_runs++;
-done:
- return cleared;
-}
-
-static_always_inline u32
-nat44_out_of_ports_cleanup (u32 thread_index, f64 now)
-{
- return nat44_users_cleanup (thread_index, now);
-}
-
-static_always_inline u32
-nat44_max_translations_per_user_cleanup (snat_user_t * u, u32 thread_index,
- f64 now)
-{
- return nat44_user_session_cleanup (u, thread_index, now);
-}
-
-static_always_inline u32
-nat44_force_users_cleanup (void)
-{
- snat_main_t *sm = &snat_main;
- snat_main_per_thread_data_t *tsm;
-
- f64 now = vlib_time_now (vlib_get_main ());
- u32 cleared = 0;
-
- if (sm->num_workers > 1)
- {
- /* *INDENT-OFF* */
- vec_foreach (tsm, sm->per_thread_data)
- {
- cleared += nat44_users_cleanup (tsm->thread_index, now);
- }
- /* *INDENT-ON* */
- }
- else
- {
- tsm = vec_elt_at_index (sm->per_thread_data, sm->num_workers);
- cleared += nat44_users_cleanup (tsm->thread_index, now);
- }
- return cleared;
-}
-
#endif /* included_nat44_inlines_h__ */
/*
diff --git a/src/plugins/nat/nat44_cli.c b/src/plugins/nat/nat44_cli.c
index 6712b8b29a7..82c0433501c 100644
--- a/src/plugins/nat/nat44_cli.c
+++ b/src/plugins/nat/nat44_cli.c
@@ -117,16 +117,6 @@ nat_show_workers_commnad_fn (vlib_main_t * vm, unformat_input_t * input,
}
static clib_error_t *
-nat44_session_cleanup_command_fn (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
-{
- clib_error_t *error = 0;
- nat44_force_users_cleanup ();
- return error;
-}
-
-static clib_error_t *
snat_set_log_level_command_fn (vlib_main_t * vm,
unformat_input_t * input,
vlib_cli_command_t * cmd)
@@ -703,10 +693,7 @@ nat44_show_summary_command_fn (vlib_main_t * vm, unformat_input_t * input,
++transitory_wait_closed;
}
}
- else
- {
- transitory++;
- }
+ transitory++;
}
else
established++;
@@ -718,18 +705,6 @@ nat44_show_summary_command_fn (vlib_main_t * vm, unformat_input_t * input,
}
}));
count += pool_elts (tsm->sessions);
-
- vlib_cli_output (vm, "tid[%u] session scavenging cleared: %u",
- tsm->thread_index, tsm->cleared);
- vlib_cli_output (vm, "tid[%u] session scavenging cleanup runs: %u",
- tsm->thread_index, tsm->cleanup_runs);
-
- if (now < tsm->cleanup_timeout)
- vlib_cli_output (vm, "tid[%u] session scavenging next run in: %f",
- tsm->thread_index, tsm->cleanup_timeout - now);
- else
- vlib_cli_output (vm, "tid[%u] session scavenging next run in: 0",
- tsm->thread_index);
}
/* *INDENT-ON* */
}
@@ -764,10 +739,7 @@ nat44_show_summary_command_fn (vlib_main_t * vm, unformat_input_t * input,
++transitory_wait_closed;
}
}
- else
- {
- transitory++;
- }
+ transitory++;
}
else
established++;
@@ -780,17 +752,6 @@ nat44_show_summary_command_fn (vlib_main_t * vm, unformat_input_t * input,
}));
/* *INDENT-ON* */
count = pool_elts (tsm->sessions);
-
- vlib_cli_output (vm, "tid[0] session scavenging cleared: %u",
- tsm->cleared);
- vlib_cli_output (vm, "tid[0] session scavenging cleanup runs: %u",
- tsm->cleanup_runs);
-
- if (now < tsm->cleanup_timeout)
- vlib_cli_output (vm, "tid[0] session scavenging next run in: %f",
- tsm->cleanup_timeout - now);
- else
- vlib_cli_output (vm, "tid[0] session scavenging next run in: 0");
}
vlib_cli_output (vm, "total timed out sessions: %u", timed_out);
@@ -1999,7 +1960,6 @@ set_timeout_command_fn (vlib_main_t * vm,
}
done:
unformat_free (line_input);
- sm->min_timeout = nat44_minimal_timeout (sm);
return error;
}
@@ -2010,8 +1970,6 @@ nat_show_timeouts_command_fn (vlib_main_t * vm,
{
snat_main_t *sm = &snat_main;
- // fix text
- vlib_cli_output (vm, "min session cleanup timeout: %dsec", sm->min_timeout);
vlib_cli_output (vm, "udp timeout: %dsec", sm->udp_timeout);
vlib_cli_output (vm, "tcp-established timeout: %dsec",
sm->tcp_established_timeout);
@@ -2234,19 +2192,6 @@ VLIB_CLI_COMMAND (nat_show_timeouts_command, static) = {
/*?
* @cliexpar
* @cliexstart{nat set logging level}
- * To force garbage collection of nat sessions
- * vpp# nat44 session cleanup
- * @cliexend
-?*/
-VLIB_CLI_COMMAND (nat44_session_cleanup_command, static) = {
- .path = "nat44 session cleanup",
- .function = nat44_session_cleanup_command_fn,
- .short_help = "nat44 session cleanup",
-};
-
-/*?
- * @cliexpar
- * @cliexstart{nat set logging level}
* To set NAT logging level use:
* Set nat logging level
* @cliexend
diff --git a/src/plugins/nat/nat_api.c b/src/plugins/nat/nat_api.c
index 5db375ca58f..863f2cbea9f 100644
--- a/src/plugins/nat/nat_api.c
+++ b/src/plugins/nat/nat_api.c
@@ -242,28 +242,6 @@ vl_api_nat_worker_dump_t_print (vl_api_nat_worker_dump_t * mp, void *handle)
}
static void
-vl_api_nat44_session_cleanup_t_handler (vl_api_nat44_session_cleanup_t * mp)
-{
- snat_main_t *sm = &snat_main;
- vl_api_nat44_session_cleanup_reply_t *rmp;
- int rv = 0;
- nat44_force_users_cleanup ();
- REPLY_MACRO (VL_API_NAT44_SESSION_CLEANUP_REPLY);
-}
-
-static void *
-vl_api_nat44_session_cleanup_t_print (vl_api_nat44_session_cleanup_t * mp,
- void *handle)
-{
- u8 *s;
-
- s = format (0, "SCRIPT: nat44_session_cleanup");
-
- FINISH;
-}
-
-
-static void
vl_api_nat_set_log_level_t_handler (vl_api_nat_set_log_level_t * mp)
{
snat_main_t *sm = &snat_main;
@@ -336,8 +314,6 @@ vl_api_nat_set_timeouts_t_handler (vl_api_nat_set_timeouts_t * mp)
sm->tcp_transitory_timeout = ntohl (mp->tcp_transitory);
sm->icmp_timeout = ntohl (mp->icmp);
- sm->min_timeout = nat44_minimal_timeout (sm);
-
rv = nat64_set_icmp_timeout (ntohl (mp->icmp));
if (rv)
goto send_reply;
@@ -3142,7 +3118,6 @@ _(NAT_SHOW_CONFIG, nat_show_config) \
_(NAT_SET_WORKERS, nat_set_workers) \
_(NAT_WORKER_DUMP, nat_worker_dump) \
_(NAT44_DEL_USER, nat44_del_user) \
-_(NAT44_SESSION_CLEANUP, nat44_session_cleanup) \
_(NAT_SET_LOG_LEVEL, nat_set_log_level) \
_(NAT_IPFIX_ENABLE_DISABLE, nat_ipfix_enable_disable) \
_(NAT_SET_TIMEOUTS, nat_set_timeouts) \
diff --git a/src/plugins/nat/test/test_nat.py b/src/plugins/nat/test/test_nat.py
index ac9c65dd0f5..e267c4ef2bc 100644
--- a/src/plugins/nat/test/test_nat.py
+++ b/src/plugins/nat/test/test_nat.py
@@ -4187,100 +4187,6 @@ class TestNAT44(MethodHolder):
self.logger.info(self.vapi.cli("show nat ha"))
-class TestNAT44EndpointDependent2(MethodHolder):
- """ Endpoint-Dependent session test cases """
-
- icmp_timeout = 2
-
- @classmethod
- def setUpConstants(cls):
- super(TestNAT44EndpointDependent2, cls).setUpConstants()
- cls.vpp_cmdline.extend(["nat", "{", "endpoint-dependent",
- "translation", "hash", "buckets", "1",
- "icmp", "timeout", str(cls.icmp_timeout), "}"])
-
- @classmethod
- def setUpClass(cls):
- super(TestNAT44EndpointDependent2, cls).setUpClass()
- translation_buckets = 1
- cls.max_translations = 10 * translation_buckets
-
- cls.create_pg_interfaces(range(2))
- cls.interfaces = list(cls.pg_interfaces[0:2])
-
- for i in cls.interfaces:
- i.admin_up()
- i.config_ip4()
- i.resolve_arp()
-
- cls.pg0.generate_remote_hosts(1)
- cls.pg0.configure_ipv4_neighbors()
-
- cls.pg1.generate_remote_hosts(1)
- cls.pg1.configure_ipv4_neighbors()
-
- @classmethod
- def tearDownClass(cls):
- super(TestNAT44EndpointDependent2, cls).tearDownClass()
-
- def create_icmp_stream(self, in_if, out_if, count):
- """
- Create ICMP packet stream for inside network
-
- :param in_if: Inside interface
- :param out_if: Outside interface
- :param count: Number of packets
- """
-
- self.assertTrue(count > 0)
- icmp_id = random.randint(0, 65535 - (count - 1))
-
- pkts = list()
- for i in range(count):
- p = (Ether(dst=in_if.local_mac, src=in_if.remote_mac) /
- IP(src=in_if.remote_ip4, dst=out_if.remote_ip4, ttl=64) /
- ICMP(id=icmp_id + i, type='echo-request'))
- pkts.append(p)
- return pkts
-
- def send_pkts(self, pkts, expected=None):
- self.pg0.add_stream(pkts)
- self.pg_enable_capture(self.pg_interfaces)
- self.pg_start()
- return self.pg1.get_capture(
- len(pkts) if expected is None else expected)
-
- def test_session_cleanup(self):
- """ NAT44 session cleanup test """
-
- self.nat44_add_address(self.pg1.local_ip4)
- flags = self.config_flags.NAT_IS_INSIDE
- self.vapi.nat44_interface_add_del_feature(
- sw_if_index=self.pg0.sw_if_index,
- flags=flags, is_add=1)
- self.vapi.nat44_interface_add_del_feature(
- sw_if_index=self.pg1.sw_if_index,
- is_add=1)
-
- nat_config = self.vapi.nat_show_config()
- self.assertEqual(1, nat_config.endpoint_dependent)
-
- pkts = self.create_icmp_stream(self.pg0, self.pg1,
- self.max_translations + 2)
- sz = len(pkts)
-
- # positive test
- self.send_pkts(pkts[0:self.max_translations])
-
- # false positive test
- self.send_pkts(pkts[self.max_translations:sz - 1], 0)
-
- sleep(self.icmp_timeout)
-
- # positive test
- self.send_pkts(pkts[self.max_translations + 1:sz])
-
-
class TestNAT44EndpointDependent(MethodHolder):
""" Endpoint-Dependent mapping and filtering test cases """
-static RPM_DEPENDS += apr-devel RPM_DEPENDS += numactl-devel RPM_DEPENDS += check check-devel RPM_DEPENDS += boost boost-devel RPM_DEPENDS += selinux-policy selinux-policy-devel RPM_DEPENDS += ninja-build RPM_DEPENDS += libuuid-devel RPM_DEPENDS += mbedtls-devel ifeq ($(OS_ID),fedora) RPM_DEPENDS += dnf-utils RPM_DEPENDS += subunit subunit-devel RPM_DEPENDS += compat-openssl10-devel RPM_DEPENDS += python3-devel # needed for python3 -m pip install psutil RPM_DEPENDS += python3-ply # for vppapigen RPM_DEPENDS += python3-virtualenv python3-jsonschema RPM_DEPENDS += cmake RPM_DEPENDS_GROUPS = 'C Development Tools and Libraries' else ifeq ($(OS_ID)-$(OS_VERSION_ID),centos-8) RPM_DEPENDS += yum-utils RPM_DEPENDS += compat-openssl10 RPM_DEPENDS += python36-devel python3-ply RPM_DEPENDS += python3-virtualenv python3-jsonschema RPM_DEPENDS += cmake RPM_DEPENDS_GROUPS = 'Development Tools' else RPM_DEPENDS += yum-utils RPM_DEPENDS += openssl-devel RPM_DEPENDS += python36-ply # for vppapigen RPM_DEPENDS += python3-devel python3-pip RPM_DEPENDS += python-virtualenv python36-jsonschema RPM_DEPENDS += devtoolset-9 RPM_DEPENDS += cmake3 RPM_DEPENDS_GROUPS = 'Development Tools' endif # +ganglia-devel if building the ganglia plugin RPM_DEPENDS += chrpath libffi-devel rpm-build # lowercase- replace spaces with dashes. SUSE_NAME= $(shell grep '^NAME=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g' | sed -e 's/ /-/' | awk '{print tolower($$0)}') SUSE_ID= $(shell grep '^VERSION_ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g' | cut -d' ' -f2) RPM_SUSE_BUILDTOOLS_DEPS = autoconf automake ccache check-devel chrpath RPM_SUSE_BUILDTOOLS_DEPS += clang cmake indent libtool make ninja python3-ply RPM_SUSE_DEVEL_DEPS = glibc-devel-static libnuma-devel RPM_SUSE_DEVEL_DEPS += libopenssl-devel openssl-devel mbedtls-devel libuuid-devel RPM_SUSE_PYTHON_DEPS = python-devel python3-devel python-pip python3-pip RPM_SUSE_PYTHON_DEPS += python-rpm-macros python3-rpm-macros RPM_SUSE_PLATFORM_DEPS = distribution-release shadow rpm-build ifeq ($(OS_ID),opensuse) ifeq ($(SUSE_NAME),tumbleweed) RPM_SUSE_DEVEL_DEPS = libboost_headers1_68_0-devel-1.68.0 libboost_thread1_68_0-devel-1.68.0 gcc RPM_SUSE_PYTHON_DEPS += python3-ply python2-virtualenv endif ifeq ($(SUSE_ID),15.0) RPM_SUSE_DEVEL_DEPS += libboost_headers-devel libboost_thread-devel gcc RPM_SUSE_PYTHON_DEPS += python3-ply python2-virtualenv else RPM_SUSE_DEVEL_DEPS += libboost_headers1_68_0-devel-1.68.0 gcc6 RPM_SUSE_PYTHON_DEPS += python-virtualenv endif endif ifeq ($(OS_ID),opensuse-leap) ifeq ($(SUSE_ID),15.0) RPM_SUSE_DEVEL_DEPS += libboost_headers-devel libboost_thread-devel gcc git curl RPM_SUSE_PYTHON_DEPS += python3-ply python2-virtualenv endif endif RPM_SUSE_DEPENDS += $(RPM_SUSE_BUILDTOOLS_DEPS) $(RPM_SUSE_DEVEL_DEPS) $(RPM_SUSE_PYTHON_DEPS) $(RPM_SUSE_PLATFORM_DEPS) ifneq ($(wildcard $(STARTUP_DIR)/startup.conf),) STARTUP_CONF ?= $(STARTUP_DIR)/startup.conf endif ifeq ($(findstring y,$(UNATTENDED)),y) CONFIRM=-y FORCE=--force-yes endif TARGETS = vpp ifneq ($(SAMPLE_PLUGIN),no) TARGETS += sample-plugin endif define banner @echo "========================================================================" @echo " $(1)" @echo "========================================================================" @echo " " endef .PHONY: help help: @echo "Make Targets:" @echo " install-dep[s] - install software dependencies" @echo " wipe - wipe all products of debug build " @echo " wipe-release - wipe all products of release build " @echo " build - build debug binaries" @echo " build-release - build release binaries" @echo " build-coverity - build coverity artifacts" @echo " rebuild - wipe and build debug binaries" @echo " rebuild-release - wipe and build release binaries" @echo " run - run debug binary" @echo " run-release - run release binary" @echo " debug - run debug binary with debugger" @echo " debug-release - run release binary with debugger" @echo " test - build and run tests" @echo " test-help - show help on test framework" @echo " run-vat - run vpp-api-test tool" @echo " pkg-deb - build DEB packages" @echo " pkg-deb-debug - build DEB debug packages" @echo " pkg-snap - build SNAP package" @echo " snap-clean - clean up snap build environment" @echo " vom-pkg-deb - build vom DEB packages" @echo " vom-pkg-deb-debug - build vom DEB debug packages" @echo " pkg-rpm - build RPM packages" @echo " install-ext-dep[s] - install external development dependencies" @echo " ctags - (re)generate ctags database" @echo " gtags - (re)generate gtags database" @echo " cscope - (re)generate cscope database" @echo " compdb - (re)generate compile_commands.json" @echo " checkstyle - check coding style" @echo " checkstyle-commit - check commit message format" @echo " checkstyle-test - check test framework coding style" @echo " checkstyle-api - check api for incompatible changes" @echo " fixstyle - fix coding style" @echo " doxygen - (re)generate documentation" @echo " bootstrap-doxygen - setup Doxygen dependencies" @echo " wipe-doxygen - wipe all generated documentation" @echo " checkfeaturelist - check FEATURE.yaml according to schema" @echo " featurelist - dump feature list in markdown" @echo " json-api-files - (re)-generate json api files" @echo " json-api-files-debug - (re)-generate json api files for debug target" @echo " docs - Build the Sphinx documentation" @echo " docs-venv - Build the virtual environment for the Sphinx docs" @echo " docs-clean - Remove the generated files from the Sphinx docs" @echo "" @echo "Make Arguments:" @echo " V=[0|1] - set build verbosity level" @echo " STARTUP_CONF=<path> - startup configuration file" @echo " (e.g. /etc/vpp/startup.conf)" @echo " STARTUP_DIR=<path> - startup directory (e.g. /etc/vpp)" @echo " It also sets STARTUP_CONF if" @echo " startup.conf file is present" @echo " GDB=<path> - gdb binary to use for debugging" @echo " PLATFORM=<name> - target platform. default is vpp" @echo " TEST=<filter> - apply filter to test set, see test-help" @echo " DPDK_CONFIG=<conf> - add specified dpdk config commands to" @echo " autogenerated startup.conf" @echo " (e.g. \"no-pci\" )" @echo " SAMPLE_PLUGIN=yes - in addition build/run/debug sample plugin" @echo " DISABLED_PLUGINS=<list> - comma separated list of plugins which" @echo " should not be loaded" @echo "" @echo "Current Argument Values:" @echo " V = $(V)" @echo " STARTUP_CONF = $(STARTUP_CONF)" @echo " STARTUP_DIR = $(STARTUP_DIR)" @echo " GDB = $(GDB)" @echo " PLATFORM = $(PLATFORM)" @echo " DPDK_VERSION = $(DPDK_VERSION)" @echo " DPDK_CONFIG = $(DPDK_CONFIG)" @echo " SAMPLE_PLUGIN = $(SAMPLE_PLUGIN)" @echo " DISABLED_PLUGINS = $(DISABLED_PLUGINS)" $(BR)/.deps.ok: ifeq ($(findstring y,$(UNATTENDED)),y) make install-dep endif ifeq ($(filter ubuntu debian,$(OS_ID)),$(OS_ID)) @MISSING=$$(apt-get install -y -qq -s $(DEB_DEPENDS) | grep "^Inst ") ; \ if [ -n "$$MISSING" ] ; then \ echo "\nPlease install missing packages: \n$$MISSING\n" ; \ echo "by executing \"make install-dep\"\n" ; \ exit 1 ; \ fi ; \ exit 0 else ifneq ("$(wildcard /etc/redhat-release)","") @for i in $(RPM_DEPENDS) ; do \ RPM=$$(basename -s .rpm "$${i##*/}" | cut -d- -f1,2,3) ; \ MISSING+=$$(rpm -q $$RPM | grep "^package") ; \ done ; \ if [ -n "$$MISSING" ] ; then \ echo "Please install missing RPMs: \n$$MISSING\n" ; \ echo "by executing \"make install-dep\"\n" ; \ exit 1 ; \ fi ; \ exit 0 endif @touch $@ .PHONY: bootstrap bootstrap: @echo "'make bootstrap' is not needed anymore" .PHONY: install-dep install-dep: ifeq ($(filter ubuntu debian,$(OS_ID)),$(OS_ID)) ifeq ($(OS_VERSION_ID),14.04) @sudo -E apt-get $(CONFIRM) $(FORCE) install software-properties-common endif ifeq ($(OS_ID)-$(OS_VERSION_ID),debian-8) @grep -q jessie-backports /etc/apt/sources.list /etc/apt/sources.list.d/* 2> /dev/null \ || ( echo "Please install jessie-backports" ; exit 1 ) endif @sudo -E apt-get update @sudo -E apt-get $(APT_ARGS) $(CONFIRM) $(FORCE) install $(DEB_DEPENDS) else ifneq ("$(wildcard /etc/redhat-release)","") ifeq ($(OS_ID),rhel) @sudo -E yum-config-manager --enable rhel-server-rhscl-7-rpms @sudo -E yum groupinstall $(CONFIRM) $(RPM_DEPENDS_GROUPS) @sudo -E yum install $(CONFIRM) $(RPM_DEPENDS) @sudo -E debuginfo-install $(CONFIRM) glibc openssl-libs mbedtls-devel zlib else ifeq ($(OS_ID)-$(OS_VERSION_ID),centos-8) @sudo -E dnf groupinstall $(CONFIRM) $(RPM_DEPENDS_GROUPS) @sudo -E dnf install $(CONFIRM) $(RPM_DEPENDS) else ifeq ($(OS_ID),centos) @sudo -E yum install $(CONFIRM) centos-release-scl-rh epel-release @sudo -E yum groupinstall $(CONFIRM) $(RPM_DEPENDS_GROUPS) @sudo -E yum install $(CONFIRM) $(RPM_DEPENDS) @sudo -E debuginfo-install $(CONFIRM) glibc openssl-libs mbedtls-devel zlib else ifeq ($(OS_ID),fedora) @sudo -E dnf groupinstall $(CONFIRM) $(RPM_DEPENDS_GROUPS) @sudo -E dnf install $(CONFIRM) $(RPM_DEPENDS) @sudo -E debuginfo-install $(CONFIRM) glibc openssl-libs mbedtls-devel zlib endif else ifeq ($(filter opensuse-tumbleweed,$(OS_ID)),$(OS_ID)) @sudo -E zypper refresh @sudo -E zypper install -y $(RPM_SUSE_DEPENDS) else ifeq ($(filter opensuse-leap,$(OS_ID)),$(OS_ID)) @sudo -E zypper refresh @sudo -E zypper install -y $(RPM_SUSE_DEPENDS) else ifeq ($(filter opensuse,$(OS_ID)),$(OS_ID)) @sudo -E zypper refresh @sudo -E zypper install -y $(RPM_SUSE_DEPENDS) else $(error "This option currently works only on Ubuntu, Debian, RHEL, CentOS or openSUSE systems") endif git config commit.template .git_commit_template.txt .PHONY: install-deps install-deps: install-dep define make @make -C $(BR) PLATFORM=$(PLATFORM) TAG=$(1) $(2) endef $(BR)/scripts/.version: ifneq ("$(wildcard /etc/redhat-release)","") $(shell $(BR)/scripts/version rpm-string > $(BR)/scripts/.version) else $(shell $(BR)/scripts/version > $(BR)/scripts/.version) endif DIST_FILE = $(BR)/vpp-$(shell src/scripts/version).tar DIST_SUBDIR = vpp-$(shell src/scripts/version|cut -f1 -d-) .PHONY: dist dist: @if git rev-parse 2> /dev/null ; then \ git archive \ --prefix=$(DIST_SUBDIR)/ \ --format=tar \ -o $(DIST_FILE) \ HEAD ; \ git describe > $(BR)/.version ; \ else \ (cd .. ; tar -cf $(DIST_FILE) $(DIST_SUBDIR) --exclude=*.tar) ; \ src/scripts/version > $(BR)/.version ; \ fi @tar --append \ --file $(DIST_FILE) \ --transform='s,.*/.version,$(DIST_SUBDIR)/src/scripts/.version,' \ $(BR)/.version @$(RM) $(BR)/.version $(DIST_FILE).xz @xz -v --threads=0 $(DIST_FILE) @$(RM) $(BR)/vpp-latest.tar.xz @ln -rs $(DIST_FILE).xz $(BR)/vpp-latest.tar.xz .PHONY: build build: $(BR)/.deps.ok $(call make,$(PLATFORM)_debug,$(addsuffix -install,$(TARGETS))) .PHONY: wipedist wipedist: @$(RM) $(BR)/*.tar.xz .PHONY: wipe wipe: wipedist test-wipe $(BR)/.deps.ok $(call make,$(PLATFORM)_debug,$(addsuffix -wipe,$(TARGETS))) @find . -type f -name "*.api.json" ! -path "./test/*" -exec rm {} \; .PHONY: rebuild rebuild: wipe build .PHONY: build-release build-release: $(BR)/.deps.ok $(call make,$(PLATFORM),$(addsuffix -install,$(TARGETS))) .PHONY: wipe-release wipe-release: test-wipe $(BR)/.deps.ok $(call make,$(PLATFORM),$(addsuffix -wipe,$(TARGETS))) .PHONY: rebuild-release rebuild-release: wipe-release build-release libexpand = $(subst $(subst ,, ),:,$(foreach lib,$(1),$(BR)/install-$(2)-native/vpp/$(lib)/$(3))) export TEST_DIR ?= $(WS_ROOT)/test export RND_SEED ?= $(shell python3 -c 'import time; print(time.time())') define test $(if $(filter-out $(3),retest),make -C $(BR) PLATFORM=$(1) TAG=$(2) vpp-install,) $(eval libs:=lib lib64) make -C test \ VPP_BUILD_DIR=$(BR)/build-$(2)-native \ VPP_BIN=$(BR)/install-$(2)-native/vpp/bin/vpp \ VPP_PLUGIN_PATH=$(call libexpand,$(libs),$(2),vpp_plugins) \ VPP_TEST_PLUGIN_PATH=$(call libexpand,$(libs),$(2),vpp_api_test_plugins) \ VPP_INSTALL_PATH=$(BR)/install-$(2)-native/ \ LD_LIBRARY_PATH=$(call libexpand,$(libs),$(2),) \ EXTENDED_TESTS=$(EXTENDED_TESTS) \ PYTHON=$(PYTHON) \ OS_ID=$(OS_ID) \ RND_SEED=$(RND_SEED) \ CACHE_OUTPUT=$(CACHE_OUTPUT) \ $(3) endef .PHONY: test test: $(call test,vpp,vpp,test) .PHONY: test-debug test-debug: $(call test,vpp,vpp_debug,test) .PHONY: test-gcov test-gcov: $(call test,vpp,vpp_gcov,test) .PHONY: test-all test-all: $(if $(filter-out $(3),retest),make -C $(BR) PLATFORM=vpp TAG=vpp vom-install,) $(eval EXTENDED_TESTS=yes) $(call test,vpp,vpp,test) .PHONY: test-all-debug test-all-debug: $(if $(filter-out $(3),retest),make -C $(BR) PLATFORM=vpp TAG=vpp_debug vom-install,) $(eval EXTENDED_TESTS=yes) $(call test,vpp,vpp_debug,test) .PHONY: papi-wipe papi-wipe: test-wipe-papi $(call banner,"This command is deprecated. Please use 'test-wipe-papi'") .PHONY: test-wipe-papi test-wipe-papi: @make -C test wipe-papi .PHONY: test-help test-help: @make -C test help .PHONY: test-wipe test-wipe: @make -C test wipe .PHONY: test-shell test-shell: $(call test,vpp,vpp,shell) .PHONY: test-shell-debug test-shell-debug: $(call test,vpp,vpp_debug,shell) .PHONY: test-shell-gcov test-shell-gcov: $(call test,vpp,vpp_gcov,shell) .PHONY: test-dep test-dep: @make -C test test-dep .PHONY: test-doc test-doc: @make -C test doc .PHONY: test-wipe-doc test-wipe-doc: @make -C test wipe-doc .PHONY: test-cov test-cov: @make -C $(BR) PLATFORM=vpp TAG=vpp_gcov vom-install $(eval EXTENDED_TESTS=yes) $(call test,vpp,vpp_gcov,cov) .PHONY: test-wipe-cov test-wipe-cov: @make -C test wipe-cov .PHONY: test-wipe-all test-wipe-all: @make -C test wipe-all .PHONY: test-checkstyle test-checkstyle: @make -C test checkstyle .PHONY: test-refresh-deps test-refresh-deps: @make -C test refresh-deps .PHONY: retest retest: $(call test,vpp,vpp,retest) .PHONY: retest-debug retest-debug: $(call test,vpp,vpp_debug,retest) .PHONY: retest-all retest-all: $(eval EXTENDED_TESTS=yes) $(call test,vpp,vpp,retest) .PHONY: retest-all-debug retest-all-debug: $(eval EXTENDED_TESTS=yes) $(call test,vpp,vpp_debug,retest) ifeq ("$(wildcard $(STARTUP_CONF))","") define run @echo "WARNING: STARTUP_CONF not defined or file doesn't exist." @echo " Running with minimal startup config: $(MINIMAL_STARTUP_CONF)\n" @cd $(STARTUP_DIR) && \ $(SUDO) $(2) $(1)/vpp/bin/vpp $(MINIMAL_STARTUP_CONF) endef else define run @cd $(STARTUP_DIR) && \ $(SUDO) $(2) $(1)/vpp/bin/vpp $(shell cat $(STARTUP_CONF) | sed -e 's/#.*//') endef endif %.files: .FORCE @find . \( -name '*\.[chyS]' -o -name '*\.java' -o -name '*\.lex' \) -and \ \( -not -path './build-root*' -o -path \ './build-root/build-vpp_debug-native/dpdk*' \) > $@ .FORCE: .PHONY: run run: $(call run, $(BR)/install-$(PLATFORM)_debug-native) .PHONY: run-release run-release: $(call run, $(BR)/install-$(PLATFORM)-native) .PHONY: debug debug: $(call run, $(BR)/install-$(PLATFORM)_debug-native,$(GDB) $(GDB_ARGS) --args) .PHONY: build-coverity build-coverity: $(call make,$(PLATFORM)_coverity,install-packages) .PHONY: debug-release debug-release: $(call run, $(BR)/install-$(PLATFORM)-native,$(GDB) $(GDB_ARGS) --args) .PHONY: build-vat build-vat: $(call make,$(PLATFORM)_debug,vpp-api-test-install) .PHONY: run-vat run-vat: @$(SUDO) $(BR)/install-$(PLATFORM)_debug-native/vpp/bin/vpp_api_test .PHONY: pkg-deb pkg-deb: $(call make,$(PLATFORM),vpp-package-deb) .PHONY: pkg-snap pkg-snap: cd extras/snap ; \ ./prep ; \ SNAPCRAFT_BUILD_ENVIRONMENT_MEMORY=8G \ SNAPCRAFT_BUILD_ENVIRONMENT_CPU=6 \ snapcraft --debug .PHONY: snap-clean snap-clean: cd extras/snap ; \ snapcraft clean ; \ rm -f *.snap *.tgz .PHONY: vom-pkg-deb vom-pkg-deb: pkg-deb $(call make,$(PLATFORM),vom-package-deb) .PHONY: pkg-deb-debug pkg-deb-debug: $(call make,$(PLATFORM)_debug,vpp-package-deb) .PHONY: vom-pkg-deb-debug vom-pkg-deb-debug: pkg-deb-debug $(call make,$(PLATFORM)_debug,vom-package-deb) .PHONY: pkg-rpm pkg-rpm: dist make -C extras/rpm .PHONY: pkg-srpm pkg-srpm: dist make -C extras/rpm srpm .PHONY: dpdk-install-dev dpdk-install-dev: $(call banner,"This command is deprecated. Please use 'make install-ext-deps'") make -C build/external install-$(PKG) .PHONY: install-ext-deps install-ext-deps: make -C build/external install-$(PKG) .PHONY: install-ext-dep install-ext-dep: install-ext-deps .PHONY: json-api-files json-api-files: $(WS_ROOT)/src/tools/vppapigen/generate_json.py .PHONY: json-api-files-debug json-api-files-debug: $(WS_ROOT)/src/tools/vppapigen/generate_json.py --debug-target .PHONY: ctags ctags: ctags.files @ctags --totals --tag-relative -L $< @rm $< .PHONY: gtags gtags: ctags @gtags --gtagslabel=ctags .PHONY: cscope cscope: cscope.files @cscope -b -q -v .PHONY: compdb compdb: @ninja -C build-root/build-vpp_debug-native/vpp -t compdb > compile_commands.json .PHONY: checkstyle checkstyle: checkfeaturelist @build-root/scripts/checkstyle.sh .PHONY: checkstyle-commit checkstyle-commit: @extras/scripts/check_commit_msg.sh .PHONY: checkstyle-test checkstyle-test: test-checkstyle .PHONY: checkstyle-all checkstyle-all: checkstyle-commit checkstyle checkstyle-test .PHONY: fixstyle fixstyle: @build-root/scripts/checkstyle.sh --fix .PHONY: checkstyle-api checkstyle-api: @extras/scripts/crcchecker.py --check-patch # necessary because Bug 1696324 - Update to python3.6 breaks PyYAML dependencies # Status: CLOSED CANTFIX # https://bugzilla.redhat.com/show_bug.cgi?id=1696324 .PHONY: centos-pyyaml centos-pyyaml: ifeq ($(OS_ID)-$(OS_VERSION_ID),centos-7) @python3 -m pip install pyyaml endif ifeq ($(OS_ID)-$(OS_VERSION_ID),centos-8) @sudo -E yum install $(CONFIRM) python3-pyyaml endif .PHONY: featurelist featurelist: centos-pyyaml @build-root/scripts/fts.py --all --markdown .PHONY: checkfeaturelist checkfeaturelist: centos-pyyaml @build-root/scripts/fts.py --validate --all # # Build the documentation # # Doxygen configuration and our utility scripts export DOXY_DIR ?= $(WS_ROOT)/doxygen define make-doxy @OS_ID="$(OS_ID)" make -C $(DOXY_DIR) $@ endef .PHONY: bootstrap-doxygen bootstrap-doxygen: $(call make-doxy) .PHONY: doxygen doxygen: bootstrap-doxygen $(call make-doxy) .PHONY: wipe-doxygen wipe-doxygen: $(call make-doxy) # Sphinx Documents export DOCS_DIR = $(WS_ROOT)/docs export VENV_DIR = $(WS_ROOT)/sphinx_venv export SPHINX_SCRIPTS_DIR = $(WS_ROOT)/docs/scripts .PHONY: docs-venv docs-venv: @($(SPHINX_SCRIPTS_DIR)/sphinx-make.sh venv) .PHONY: docs docs: $(DOCS_DIR) @($(SPHINX_SCRIPTS_DIR)/sphinx-make.sh html) .PHONY: docs-clean docs-clean: @rm -rf $(DOCS_DIR)/_build @rm -rf $(VENV_DIR) .PHONY: pkg-verify pkg-verify: install-dep $(BR)/.deps.ok install-ext-deps $(call banner,"Building for PLATFORM=vpp using gcc") @make -C build-root PLATFORM=vpp TAG=vpp wipe-all install-packages $(call banner,"Building sample-plugin") @make -C build-root PLATFORM=vpp TAG=vpp sample-plugin-install $(call banner,"Building libmemif") @make -C build-root PLATFORM=vpp TAG=vpp libmemif-install $(call banner,"Building VOM") @make -C build-root PLATFORM=vpp TAG=vpp vom-install $(call banner,"Building $(PKG) packages") @make pkg-$(PKG) ifeq ($(OS_ID),ubuntu) $(call banner,"Building VOM $(PKG) package") @make vom-pkg-deb endif MAKE_VERIFY_GATE_OS ?= ubuntu-18.04 .PHONY: verify verify: pkg-verify ifeq ($(OS_ID)-$(OS_VERSION_ID),$(MAKE_VERIFY_GATE_OS)) $(call banner,"Testing vppapigen") @src/tools/vppapigen/test_vppapigen.py $(call banner,"Running tests") @make COMPRESS_FAILED_TEST_LOGS=yes RETRIES=3 test else $(call banner,"Skipping tests. Tests under 'make verify' supported on $(MAKE_VERIFY_GATE_OS)") endif