2 * gbp.h : Group Based Policy
4 * Copyright (c) 2018 Cisco and/or its affiliates.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include <plugins/gbp/gbp.h>
21 * Single contract DB instance
23 gbp_contract_db_t gbp_contract_db;
26 gbp_contract_update (epg_id_t src_epg, epg_id_t dst_epg, u32 acl_index)
28 gbp_contract_key_t key = {
33 hash_set (gbp_contract_db.gc_hash, key.as_u64, acl_index);
37 gbp_contract_delete (epg_id_t src_epg, epg_id_t dst_epg)
39 gbp_contract_key_t key = {
44 hash_unset (gbp_contract_db.gc_hash, key.as_u64);
48 gbp_contract_walk (gbp_contract_cb_t cb, void *ctx)
50 gbp_contract_key_t key;
54 hash_foreach(key.as_u64, acl_index, gbp_contract_db.gc_hash,
56 gbp_contract_t gbpc = {
58 .gc_acl_index = acl_index,
68 gbp_contract_cli (vlib_main_t * vm,
69 unformat_input_t * input, vlib_cli_command_t * cmd)
71 epg_id_t src_epg_id = EPG_INVALID, dst_epg_id = EPG_INVALID;
75 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
77 if (unformat (input, "add"))
79 else if (unformat (input, "del"))
81 else if (unformat (input, "src-epg %d", &src_epg_id))
83 else if (unformat (input, "dst-epg %d", &dst_epg_id))
85 else if (unformat (input, "acl-index %d", &acl_index))
91 if (EPG_INVALID == src_epg_id)
92 return clib_error_return (0, "Source EPG-ID must be specified");
93 if (EPG_INVALID == dst_epg_id)
94 return clib_error_return (0, "Destination EPG-ID must be specified");
98 gbp_contract_update (src_epg_id, dst_epg_id, acl_index);
102 gbp_contract_delete (src_epg_id, dst_epg_id);
109 * Configure a GBP Contract
112 * @cliexstart{set gbp contract [del] src-epg <ID> dst-epg <ID> acl-index <ACL>}
115 VLIB_CLI_COMMAND (gbp_contract_cli_node, static) =
117 .path = "gbp contract",.short_help =
118 "gbp contract [del] src-epg <ID> dst-epg <ID> acl-index <ACL>",.function
119 = gbp_contract_cli,};
122 static clib_error_t *
123 gbp_contract_show (vlib_main_t * vm,
124 unformat_input_t * input, vlib_cli_command_t * cmd)
126 gbp_contract_key_t key;
129 vlib_cli_output (vm, "Contracts:");
132 hash_foreach (key.as_u64, epg_id, gbp_contract_db.gc_hash,
134 vlib_cli_output (vm, " {%d,%d} -> %d", key.gck_src,
135 key.gck_dst, epg_id);
143 * Show Group Based Policy Contracts
146 * @cliexstart{show gbp contract}
150 VLIB_CLI_COMMAND (gbp_contract_show_node, static) = {
151 .path = "show gbp contract",
152 .short_help = "show gbp contract\n",
153 .function = gbp_contract_show,
158 * fd.io coding-style-patch-verification: ON
161 * eval: (c-set-style "gnu")