00001
00002
00003
00004
00005
00006
00007 #ifndef _CLI_SYM
00008 #define _CLI_SYM
00009 #include <nm/nm.h>
00010 #include <nm/nm_bv.h>
00011 #include <nm/nm_rbt.h>
00012 #include <nmf/nmf.h>
00013
00014 #define CLI_SYM_MAX_HOST_NAME 31
00015 #define CLI_SYM_NAME_MAX 31
00016
00017 typedef enum cli_sym_type {
00018 CLI_SYM_SW = 1,
00019 CLI_SYM_VLAN,
00020 CLI_SYM_LAG,
00021 CLI_SYM_HOST,
00022 CLI_SYM_PCFG,
00023 CLI_SYM_ACL,
00024 CLI_SYM_POLICER,
00025 } cli_sym_type_t;
00026
00027 struct cli_sw {
00028 enum cli_sw_state {
00029 CLI_SYM_DEFINED=0,
00030 CLI_SYM_OPEN,
00031 CLI_SYM_ACTIVE,
00032 } state;
00033 char sw_host[CLI_SYM_MAX_HOST_NAME+1];
00034 nmf_client_t client_id;
00035 time_t time;
00036 int slot_count;
00037 u_int cb_events;
00038 };
00039
00040 struct cli_vlan {
00041 struct nm_rbn rbn;
00042 nmf_client_t client_id;
00043 int vlan_id;
00044 int mtu;
00045 int igmp_trapping;
00046 int routing;
00047 int reflect;
00048 };
00049 static inline void init_vlan(struct cli_vlan *dst, struct cli_vlan *src)
00050 {
00051
00052 *dst = *src;
00053
00054
00055 memset(&dst->rbn, 0, sizeof(dst->rbn));
00056 }
00057
00058 struct cli_lag {
00059 nmf_client_t client_id;
00060 int lag_id;
00061 nm_u32_t hash_flags;
00062 int port_count;
00063 nm_bv_t port_list;
00064 };
00065 static inline void init_lag(struct cli_lag *dst, struct cli_lag *src)
00066 {
00067
00068 nm_bv_free(&dst->port_list);
00069
00070
00071 *dst = *src;
00072
00073
00074 nm_bv_init(&dst->port_list);
00075 nm_bv_copy(&dst->port_list, &src->port_list);
00076 }
00077
00078 struct cli_host {
00079 struct nmf_addr_rec adrec;
00080 };
00081 static inline void init_host(struct cli_host *dst, struct cli_host *src)
00082 {
00083
00084 nm_bv_free(&dst->adrec.port_list);
00085
00086
00087 *dst = *src;
00088
00089
00090 nm_bv_init(&dst->adrec.port_list);
00091 nm_bv_copy(&dst->adrec.port_list, &src->adrec.port_list);
00092 }
00093
00094 struct cli_pcfg {
00095 nmf_client_t client_id;
00096 int mtu;
00097 int speed;
00098 enum nmf_port_state port_state;
00099 enum nmf_port_bist_mode bist_mode;
00100 enum nmf_stp_state stp_state;
00101 nm_bv_t fwd_port_list;
00102 int def_vlan;
00103 struct nmf_port_vlan_spec vlan_spec;
00104 };
00105 static inline void init_pcfg(struct cli_pcfg *dst, struct cli_pcfg *src)
00106 {
00107
00108 nm_bv_free(&dst->fwd_port_list);
00109 nm_bv_free(&dst->vlan_spec.vlan_list);
00110 nm_bv_free(&dst->vlan_spec.tag_list);
00111
00112
00113 *dst = *src;
00114
00115
00116 nm_bv_init(&dst->fwd_port_list);
00117 nm_bv_init(&dst->vlan_spec.vlan_list);
00118 nm_bv_init(&dst->vlan_spec.tag_list);
00119 nm_bv_copy(&dst->fwd_port_list, &src->fwd_port_list);
00120 nm_bv_copy(&dst->vlan_spec.vlan_list, &src->vlan_spec.vlan_list);
00121 nm_bv_copy(&dst->vlan_spec.tag_list, &src->vlan_spec.tag_list);
00122 }
00123
00124 struct cli_acl {
00125 nmf_client_t client_id;
00126 struct nmf_cond cond;
00127 struct nmf_action action;
00128 };
00129
00130 struct cli_policer {
00131 nmf_client_t client_id;
00132 int policer_id;
00133 };
00134
00135 struct cli_sym {
00136 char name[CLI_SYM_NAME_MAX+1];
00137 cli_sym_type_t type;
00138 struct nm_rbn rbn;
00139 int refcount;
00140 void (*free)(struct cli_sym *);
00141 void (*undef)(struct cli_sym *);
00142 union {
00143 struct cli_sw sw;
00144 struct cli_vlan vlan;
00145 struct cli_lag lag;
00146 struct cli_host host;
00147 struct cli_pcfg pcfg;
00148 struct cli_acl acl;
00149 struct cli_policer policer;
00150 };
00151 };
00152
00153 enum cli_stats_id {
00154 CLI_STATS_ALL,
00155 CLI_STATS_L2,
00156 CLI_STATS_L3,
00157 CLI_STATS_SIZES,
00158 CLI_STATS_ACTION,
00159 CLI_STATS_ERRORS
00160 };
00161
00162 enum cli_traffic_type {
00163 CLI_TRAFFIC_BOTH,
00164 CLI_TRAFFIC_TX,
00165 CLI_TRAFFIC_RX
00166 };
00167
00168 struct cli_sym *sym_new(char *name, cli_sym_type_t t);
00169 int sym_add(struct cli_sym *s);
00170 void sym_rem(struct cli_sym *s);
00171 struct cli_sym *sym_find(char *name);
00172 struct cli_sym *sym_find_type(char *name, cli_sym_type_t t);
00173 void sym_get(struct cli_sym *s);
00174 void sym_put(struct cli_sym *s);
00175 void sym_for_all_of_type(void (*cb)(struct cli_sym *, void *context), cli_sym_type_t type, void *context);
00176
00177 #endif