41 #define DEFAULT_UNIT 0
42 #define DEFAULT_VLAN 1
43 #define MAX_DIGITS_IN_CHOICE 5
46 "Syntax: example_packet_transmit \n\r"
48 "Paramaters: None. \n\r"
50 "Example: The following command is used to demonstrate transmit and \n\r"
52 " example_packet_transmit \n\r"
54 "Usage Guidelines: None. \n\r";
69 printf (
"\n packet dump for len = %d\n", len);
71 for (i = 0; i < len; i++)
73 if (i % line_len == 0)
75 if (i !=0) printf(
"\n");
78 printf (
"%02x ", (data[i]) & 0xff);
101 int pkt_header_len = 0;
102 uint8 pkt_header[64];
103 uint8 pkt_tagged_data[64] =
105 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
106 0x00, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E,
107 0x81, 0x00, 0x00, 0x01,
108 0x08, 0x00, 0x45, 0x10, 0x00, 0x46, 0x00, 0x00, 0x00, 0x00, 0x32, 0x06,
109 0x82, 0xab, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02,
110 0x03, 0x04, 0x00, 0x04, 0x01, 0x00, 0x56, 0xf1, 0x39, 0x00, 0x00,
111 0x11, 0x22, 0x33, 0x44, 0x55, 0x66
122 printf(
"Failed to allocate pkt memory, rv %s\n",
opennsl_errmsg(rv));
129 printf(
"Failed to get system port for unit %d port %d, rv %s\n", unit, port,
opennsl_errmsg(rv));
133 void * cookie = (
void *)1;
139 pkt_header[pkt_header_len++] = 0x50;
140 pkt_header[pkt_header_len++] = 0;
142 pkt_header[pkt_header_len++] = 0x01;
143 pkt_header[pkt_header_len++] = 0x00;
144 pkt_header[pkt_header_len++] = (sysport & 0xff);
145 pkt_header[pkt_header_len++] = 0x00;
147 pkt_len = pkt_header_len + 64;
149 pkt_tagged_data[14] = (vlan & 0xff00) >> 8;
150 pkt_tagged_data[15] = (vlan & 0x00ff);
152 memset(pkt_buf, 0, 128);
153 memcpy(pkt_buf, pkt_header, pkt_header_len);
154 memcpy(&pkt_buf[pkt_header_len], pkt_tagged_data, 64);
155 pkt_len = pkt_header_len + 64;
170 printf(
"Failed to free up packet memory, rv %s\n",
opennsl_errmsg(rv));
194 for (i = 0; i < count; i++)
200 printf(
"Error Sending Packet: %d. Error: %s\n", i + 1,
opennsl_errmsg(rv));
204 printf(
"Transmitted Packet %d\n", i + 1);
217 int main(
int argc,
char *argv[])
227 if(strcmp(argv[0],
"gdb") == 0)
232 if((argc != (index + 1)) || ((argc > (index + 1)) && (strcmp(argv[index + 1],
"--help") == 0)))
239 printf(
"Initializing the system.\r\n");
244 printf(
"\r\nFailed to initialize the system. Error %s\r\n",
253 printf(
"\r\nFailed to apply default config on ports, rc = %d (%s).\r\n",
258 printf(
"Adding ports to default vlan.\r\n");
262 printf(
"\r\nFailed to add default ports. rv: %s\r\n",
opennsl_errmsg(rv));
268 printf(
"\r\nUser menu: Select one of the following options\r\n");
269 printf(
"1. Transmit a packet\n");
270 printf(
"2. Display OpenNSL version\n");
271 #ifdef INCLUDE_DIAG_SHELL
272 printf(
"9. Launch diagnostic shell\n");
274 printf(
"0. Quit the application\n");
278 printf(
"Invalid option entered. Please re-enter.\n");
285 printf(
"\r\nEnter the port on which packet needs to be transmitted.\r\n");
288 printf(
"Invalid option entered. Please re-enter.\n");
292 printf(
"\r\nEnter VLAN ID of the packet.\r\n");
295 printf(
"Invalid option entered. Please re-enter.\n");
300 printf(
"\r\nEnter number of packets to be sent.\r\n");
303 printf(
"Invalid option entered. Please re-enter.\n");
319 #ifdef INCLUDE_DIAG_SHELL
322 opennsl_driver_shell();
329 printf(
"Exiting the application.\n");