/*****************************************************************//** * \brief Main function for packet transmission * * \param argc, argv commands line arguments * * \return OPENNSL_E_XXX OpenNSL API return code ********************************************************************/ int main(int argc, char *argv[]) { opennsl_error_t rv; int count; opennsl_port_t port; int unit = DEFAULT_UNIT; int choice; int index = 0; if(strcmp(argv[0], "gdb") == 0) { index = 1; } if((argc != (index + 1)) || ((argc > (index + 1)) && (strcmp(argv[index + 1], "--help") == 0))) { printf("%s\n\r", example_usage); return OPENNSL_E_PARAM; } /* Initialize the system. */ printf("Initializing the system.\r\n"); rv = opennsl_driver_init((opennsl_init_t *) NULL); if(rv != OPENNSL_E_NONE) { printf("\r\nFailed to initialize the system. Error %s\r\n", opennsl_errmsg(rv)); return rv; } /* Add ports to default vlan. */ printf("Adding ports to default vlan.\r\n"); rv = example_switch_default_vlan_config(unit); if(rv != OPENNSL_E_NONE) { printf("\r\nFailed to add default ports. rv: %s\r\n", opennsl_errmsg(rv)); return rv; } while (1) { printf("\r\nUser menu: Select one of the following options\r\n"); printf("1. Transmit a packet\n"); printf("2. Display OpenNSL version\n"); printf("9. Launch diagnostic shell\n"); printf("0. Quit the application\n"); if(example_read_user_choice(&choice) != OPENNSL_E_NONE) { printf("Invalid option entered. Please re-enter.\n"); continue; } switch(choice){ case 1: { printf("\r\nEnter the port on which packet needs to be transmitted.\r\n"); if(example_read_user_choice(&port) != OPENNSL_E_NONE) { printf("Invalid option entered. Please re-enter.\n"); continue; } printf("\r\nEnter number of packets to be sent.\r\n"); if(example_read_user_choice(&count) != OPENNSL_E_NONE) { printf("Invalid option entered. Please re-enter.\n"); continue; } /* Transmit packet(s) on the specified port */ example_multi_pkt_send(unit, port, count); break; } /* End of case 1 */ case 2: { printf("OpenNSL version: %s\n", opennsl_version_get()); break; } case 9: { opennsl_driver_shell(); break; } case 0: { printf("Exiting the application.\n"); return OPENNSL_E_NONE; } default: break; } /* End of switch */ } /* End of while */ return OPENNSL_E_NONE; }
/**********************************************************************//** * \brief Main function for Spanning Tree Protocol (STP) sample application * * \param argc, argv commands line arguments * * \return OPENNSL_E_XXX OpenNSL API return code *****************************************************i********************/ int main(int argc, char *argv[]) { int rv = OPENNSL_E_NONE; int unit = DEFAULT_UNIT; int port1; int port2; int port; int stp_mode; int stp_state; int choice; stg_info_s info; if((argc != 3) || ((argc > 1) && (strcmp(argv[1], "--help") == 0))) { printf("%s\n\r", example_usage); return OPENNSL_E_PARAM; } /* Initialize the system */ rv = opennsl_driver_init((opennsl_init_t *) NULL); if(rv != OPENNSL_E_NONE) { printf("\r\nFailed to initialize the system.\r\n"); return rv; } /* Extract inputs parameters */ port1 = atoi(argv[1]); port2 = atoi(argv[2]); /* Call the STP action routines */ CALL_IF_ERROR_RETURN(example_stg_init(unit, &info, port1, port2)); CALL_IF_ERROR_RETURN(example_stg_create(unit, &info)); /* Display the interactive user menu */ while(1) { printf("Interactive User Menu:\n"); printf("1. Configure STP state of a port\n"); printf("2. Display the STP state of ports\n"); #ifndef CDP_EXCLUDE printf("9. Launch diagnostic shell\n"); #endif printf("0. Quit the application\n"); if(example_read_user_choice(&choice) != OPENNSL_E_NONE) { printf("Invalid option entered. Please re-enter.\n"); continue; } switch(choice) { case 1: { printf("1. Enter port number\n"); if(example_read_user_choice(&port) != OPENNSL_E_NONE) { printf("Invalid option entered. Please re-enter.\n"); continue; } printf("1. Enter STP state of the port\n"); printf(" STP state: 1 - Forward, 2 - Block\n"); if(example_read_user_choice(&stp_mode) != OPENNSL_E_NONE) { printf("Invalid option %d entered. Please re-enter.\n", stp_mode); continue; } if(stp_mode == 1) { stp_state = OPENNSL_STG_STP_FORWARD; } else if(stp_mode == 2) { stp_state = OPENNSL_STG_STP_BLOCK; } else { printf("Invalid option is entered. Please re-enter.\n"); continue; } rv = opennsl_stg_stp_set(unit, info.stg, port, stp_state); if (rv != OPENNSL_E_NONE) { printf("Failed to set STP state of port %d to " "\"%s\" in STG %d, \n", port, stp_state_str[stp_state], info.stg); return rv; } if(verbose >= 2) { printf("STP state of port %d is set to \"%s\".\n", port, stp_state_str[stp_state]); } break; } case 2: { rv = opennsl_stg_stp_get(unit, info.stg, info.port_1, &stp_state); if (rv != OPENNSL_E_NONE) { printf("Failed to get STP state of port %d in STG %d, \n", port, info.stg); return rv; } printf("STP state of port %d is \"%s\" in STG %d.\n", info.port_1, stp_state_str[stp_state], info.stg); rv = opennsl_stg_stp_get(unit, info.stg, info.port_2, &stp_state); if (rv != OPENNSL_E_NONE) { printf("Failed to get STP state of port %d in STG %d, \n", info.port_2, info.stg); return rv; } printf("STP state of port %d is \"%s\" in STG %d.\n", info.port_2, stp_state_str[stp_state], info.stg); break; } #ifndef CDP_EXCLUDE case 9: { opennsl_driver_shell(); break; } #endif case 0: { printf("User has requested to quit the application.\n"); return rv; break; } default: printf("Invalid option is entered. Please re-enter.\n"); } /* End of switch */ } /* End of while */ return rv; }