41 #define DEFAULT_UNIT 0
42 #define DEFAULT_PORT 1
43 #define DEFAULT_VLAN 1
44 #define MAX_DIGITS_IN_CHOICE 5
45 #define KNET_INTF_COUNT 20
46 #define IP_ADDR_LEN 16
47 #define NETMASK_LEN 16
50 "Syntax: example_knet \n\r"
52 "Paramaters: None. \n\r"
54 "Example: The following command is used to create KNET interfaces \n\r"
55 " that can be configurable from Linux shell. \n\r"
58 "Usage Guidelines: This program request the user to enter the following\n\r"
59 " parameters interactively \n\r"
60 " port - port number \n\r"
61 " ifName - interface name \n\r"
62 " ipaddr - IP adddress to be assigned to the interface \n\r"
63 " netmask - IP netmask to be assigned to the interface \n\r"
66 " 1) Assign IP address to the interface using Create KNET \n\r"
67 " interface option. \n\r"
68 " 2) Assign IP address to the partner that is connected to \n\r"
69 " physical port in the same subnet. \n\r"
70 " 3) Verify that ping to the IP assigned in step 1 works fine. \n\r"
105 if(port == knet_if_data[i].port)
117 if(knet_if_data[i].port == 0)
127 strcpy(knet_if_data[i].name, ifName);
149 printf(
"KNET interface table is empty.\n\r");
153 printf(
"Number of KNET interfaces present: %d\n\n\r",
knet_intf_count);
156 if(knet_if_data[i].
port != 0)
158 printf(
"Port: %d Interface Name: %s netifID: %d filterID: %d\n\r",
159 knet_if_data[i].
port, knet_if_data[i].name,
160 knet_if_data[i].netIfID, knet_if_data[i].filterID);
183 unsigned char baseMac[6] = { 0x02, 0x10, 0x18, 0x00, 0x00, 0x01 };
188 strcpy(netif.
name, ifName);
194 printf(
"Created Interface ID %d for interface name \"%s\" \n",
199 printf(
"rv = %d Error creating KNET interface \"%s\" \n", rv, ifName);
224 printf(
"Created Filter ID %d for interface name \"%s\" \n",
229 printf(
"rv = %d Error creating filter for interface \"%s\" \n",
255 memset(cmd, 0,
sizeof(cmd));
257 sprintf(cmd,
"ifconfig %s %s netmask %s", ifName, ip, netmask);
260 printf(
"Failed to configure interface \"%s\" with IP: %s Netmask: %s\n",
261 ifName, ip, netmask);
265 sprintf(cmd,
"ifconfig %s up > /dev/null", ifName);
268 printf(
"Failed to bringup interface \"%s\"\n", ifName);
272 printf(
"Configured interface \"%s\" with IP: %s Netmask: %s\n",
273 ifName, ip, netmask);
295 printf(
"Maximum number of KNET interfaces are already present.\r\n");
299 printf(
"\n\rEnter port number: \n");
302 printf(
"Invalid option entered.\n");
305 printf(
"\n\rEnter knet interface name: ");
308 printf(
"\n\rInvalid KNET interface is entered.\n\r");
311 printf(
"\n\rEnter IP address in dotted decimal format: ");
314 printf(
"\n\rInvalid IP address is entered.\n\r");
317 printf(
"\n\rEnter IP netmask in dotted decimal format: ");
320 printf(
"\n\rInvalid IP netmask is entered.\n\r");
327 printf(
"Failed to create Linux interface \"%s\". rv: %d\r\n", ifName, rv);
331 printf(
"Created Linux interface \"%s\" successfully.\r\n", ifName);
353 printf(
"\n\rThere are no KNET interfaces present in the system.\n\r");
355 printf(
"\n\rEnter KNET interface name: ");
358 printf(
"\n\rInvalid KNET interface is entered.\n\r");
364 if(strcmp(ifName, knet_if_data[i].name) == 0)
370 if (i == KNET_INTF_COUNT)
372 printf(
"\n\rThe specific interface is not found.\n\r");
379 printf(
"Error destroying network interface: %s\n",
386 printf(
"Error destroying packet filter: %s\n",
404 int main(
int argc,
char *argv[])
411 if((argc != 1) || ((argc > 1) && (strcmp(argv[1],
"--help") == 0))) {
420 printf(
"\r\nFailed to initialize the system. Error %s\r\n",
439 printf(
"\r\nFailed to apply default config on ports, rc = %d (%s).\r\n",
444 printf(
"Adding ports to default VLAN %d.\r\n",
DEFAULT_VLAN);
447 printf(
"\r\nFailed to add ports to default VLAN %d. rv: %d\r\n",
455 printf(
"Failed to get port configuration. Error %s\n",
opennsl_errmsg(rv));
461 printf(
"Failed to add ports to VLAN. Error %s\n",
opennsl_errmsg(rv));
467 printf(
"\nUser Menu: Select one of the following options\n");
468 printf(
"1. Create KNET interface\n");
469 printf(
"2. Delete KNET interface\n");
470 printf(
"3. Display KNET interface database\n");
471 #ifdef INCLUDE_DIAG_SHELL
472 printf(
"9. Launch diagnostic shell\n");
474 printf(
"0. Quit the application.\n");
478 printf(
"Invalid option entered. Please re-enter.\n");
500 #ifdef INCLUDE_DIAG_SHELL
503 opennsl_driver_shell();
510 printf(
"Exiting the application.\n");