blob: 779f1252d90a1f52191d71d1f103a119b0b7363b [file] [log] [blame]
Shad Ansari2f7f9be2017-06-07 13:34:53 -07001/******************************************************************************
2 *
3 * <:copyright-BRCM:2016:DUAL/GPL:standard
4 *
5 * Copyright (c) 2016 Broadcom
6 * All Rights Reserved
7 *
8 * Unless you and Broadcom execute a separate written software license
9 * agreement governing use of this software, this software is licensed
10 * to you under the terms of the GNU General Public License version 2
11 * (the "GPL"), available at http://www.broadcom.com/licenses/GPLv2.php,
12 * with the following added to such license:
13 *
14 * As a special exception, the copyright holders of this software give
15 * you permission to link this software with independent modules, and
16 * to copy and distribute the resulting executable under terms of your
17 * choice, provided that you also meet, for each linked independent
18 * module, the terms and conditions of the license of that module.
19 * An independent module is a module which is not derived from this
20 * software. The special exception does not apply to any modifications
21 * of the software.
22 *
23 * Not withstanding the above, under no circumstances may you combine
24 * this software in any way with any other Broadcom software provided
25 * under a license other than the GPL, without Broadcom's express prior
26 * written consent.
27 *
28 * :>
29 *
30 *****************************************************************************/
31
32/**
33 * @file bal_switch_cli.c
34 * @brief Sample CLI for switch integration module
35 *
36 */
37
38/*@{*/
39
40#include <bal_common.h>
41#include <bcm_dev_log.h>
42#include <bal_msg.h>
43#include "bal_switch_util.h"
44#include <bcmcli.h>
45
46/* Below local functions are used for real logic only */
47#ifndef TEST_SW_UTIL_LOOPBACK
48
49#include "bal_switch_acc_term.h"
50#include <bcm/types.h>
51#include <bcm/port.h>
52#include <appl/diag/shell.h>
53
54static bcmcli_entry *switch_cli_dir;
55
56/* Function declarations */
57
58/*
59 * CLI backend helper functions
60 */
61
62static bcmos_errno bal_switch_device(bcmcli_session *sess, const bcmcli_cmd_parm parm[], uint16_t nParms)
63{
64 bal_bcm_dft_dev_set(parm[0].value.number);
65 return BCM_ERR_OK;
66}
67
68static bcmos_errno bal_switch_l2_age_time(bcmcli_session *sess, const bcmcli_cmd_parm parm[], uint16_t nParms)
69{
70 bal_bcm_l2_age_time_set(parm[0].value.number);
71 return BCM_ERR_OK;
72}
73
74static bcmos_errno bal_switch_rpc_mode(bcmcli_session *sess, const bcmcli_cmd_parm parm[], uint16_t nParms)
75{
76 bal_bcm_use_rpc_set(parm[0].value.number);
77 return BCM_ERR_OK;
78}
79
80static bcmos_errno bal_switch_intf_map(bcmcli_session *sess, const bcmcli_cmd_parm parm[], uint16_t nParms)
81{
82 bal_bcm_intf_maptable_set(parm[0].value.number);
83 return BCM_ERR_OK;
84}
85
86static bcmos_errno bal_switch_trap_udp_port(bcmcli_session *sess, const bcmcli_cmd_parm parm[], uint16_t nParms)
87{
88 bal_bcm_trap_rcv_port_set(parm[0].value.number);
89 return BCM_ERR_OK;
90}
91
92static bcmos_errno bal_switch_shell(bcmcli_session *sess, const bcmcli_cmd_parm parm[], uint16_t nParms)
93{
94 sh_process(-1, "BCM", TRUE);
95 return BCM_ERR_OK;
96}
97/* allow CLI to send a testing packet out of NNI interface, input is interface_number */
98static bcmos_errno bal_switch_pkt_out(bcmcli_session *sess, const bcmcli_cmd_parm parm[], uint16_t nParms)
99{
100 int out_port = parm[0].value.number;
101 unsigned char pkt_tagged_data[64] = {
102 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, /* DA */
103 0x00, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, /* SA */
104 0x81, 0x00, 0x00, 0x01, /* TPID + VID */
105 0x08, 0x00, 0x45, 0x10, 0x00, 0x46, 0x00, 0x00, 0x00, 0x00, 0x32, 0x06,
106 0x82, 0xab, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02,
107 0x03, 0x04, 0x00, 0x04, 0x01, 0x00, 0x56, 0xf1, 0x39, 0x00, 0x00,
108 0x11, 0x22, 0x33, 0x44, 0x55, 0x66};
109
110 sw_util_pkt_send(out_port, REASON_SEND_TO_NNI, pkt_tagged_data, 64, 0);
111 return BCM_ERR_OK;
112}
113
114/* allow CLI to send a testing packet out of PON interface, inputs are interface_number and tunnel_id */
115static bcmos_errno bal_switch_pon_out(bcmcli_session *sess, const bcmcli_cmd_parm parm[], uint16_t nParms)
116{
117 int out_port = parm[0].value.number;
118 int tunnel_id = parm[1].value.number;
119 unsigned char pkt_tagged_data[64] = {
120 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, /* DA */
121 0x00, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, /* SA */
122 0x81, 0x00, 0x00, 0x01, /* TPID + VID */
123 0x08, 0x00, 0x45, 0x10, 0x00, 0x46, 0x00, 0x00, 0x00, 0x00, 0x32, 0x06,
124 0x82, 0xab, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02,
125 0x03, 0x04, 0x00, 0x04, 0x01, 0x00, 0x56, 0xf1, 0x39, 0x00, 0x00,
126 0x11, 0x22, 0x33, 0x44, 0x55, 0x66};
127
128 sw_util_pkt_send(out_port, REASON_SEND_TO_PON, pkt_tagged_data, 64, tunnel_id);
129 return BCM_ERR_OK;
130}
131
132#endif
133
134/* Create CLI directory */
135bcmos_errno sw_util_cli_init(bcmcli_entry *top_dir)
136{
137#ifndef TEST_SW_UTIL_LOOPBACK
138 if (switch_cli_dir)
139 {
140 return BCM_ERR_ALREADY;
141 }
142 switch_cli_dir = bcmcli_dir_add(top_dir, "switch", "Switch CLI commands", BCMCLI_ACCESS_GUEST, NULL);
143 BCMOS_CHECK_RETURN_ERROR(!switch_cli_dir, BCM_ERR_INTERNAL);
144
145 BCMCLI_MAKE_CMD(switch_cli_dir, "device", "Set default device", bal_switch_device,
146 BCMCLI_MAKE_PARM("index", "Device index", BCMCLI_PARM_NUMBER, BCMCLI_PARM_FLAG_NONE));
147
148 BCMCLI_MAKE_CMD(switch_cli_dir, "l2_agetime", "Set L2 table aging time", bal_switch_l2_age_time,
149 BCMCLI_MAKE_PARM("time", "L2 Aging Time", BCMCLI_PARM_NUMBER, BCMCLI_PARM_FLAG_NONE));
150
151 BCMCLI_MAKE_CMD(switch_cli_dir, "rpc_mode", "Set RPC mode", bal_switch_rpc_mode,
152 BCMCLI_MAKE_PARM_ENUM("enable", "Enable RPC mode", bcmcli_enum_bool_table, BCMCLI_PARM_FLAG_NONE));
153
154 BCMCLI_MAKE_CMD(switch_cli_dir, "intf_map_table", "Select interface mapping table", bal_switch_intf_map,
155 BCMCLI_MAKE_PARM("table", "Interface Mapping Table Number", BCMCLI_PARM_NUMBER, BCMCLI_PARM_FLAG_NONE));
156
157 BCMCLI_MAKE_CMD(switch_cli_dir, "trap_udp_port", "Set trap packet receiving udp port", bal_switch_trap_udp_port,
158 BCMCLI_MAKE_PARM("port", "Receiving Port number", BCMCLI_PARM_NUMBER, BCMCLI_PARM_FLAG_NONE));
159
160 BCMCLI_MAKE_CMD(switch_cli_dir, "nni_packet_out", "Send example packet vid=1 to switch nni port", bal_switch_pkt_out,
161 BCMCLI_MAKE_PARM("port", "Sending Port number", BCMCLI_PARM_NUMBER, BCMCLI_PARM_FLAG_NONE));
162
163 BCMCLI_MAKE_CMD(switch_cli_dir, "pon_packet_out", "Send example packet vid=1 to switch pon port", bal_switch_pon_out,
164 BCMCLI_MAKE_PARM("port", "Sending Port number", BCMCLI_PARM_NUMBER, BCMCLI_PARM_FLAG_NONE),
165 BCMCLI_MAKE_PARM("tunnel", "Sending Tunnel Id", BCMCLI_PARM_NUMBER, BCMCLI_PARM_FLAG_NONE));
166
167 BCMCLI_MAKE_CMD_NOPARM(switch_cli_dir, "shell", "Switch SDK shell", bal_switch_shell);
168#endif
169 return BCM_ERR_OK;
170}
171
172/*@}*/