LantanaCom
IS-IT--Management
Alright so, I am new to C++ and have been playing with it to create a program to help me configure Network Devices Quickly. Here is something I am trying to get past before I move on to some type of menu to add multiple VLANS, ect.
Below, My "First Question" of the program is, What Switch Chassis ID do you want to program? There are up to 10 switches in a Chassis, The ID's start at 0 through 9.
I would like to either run a range command here, numbers seprated by commas or both. After the numbers have been entered they would then need to be divided into different vaules and then run a looping condition on the next Question.
Example:
Configure Chassis 1,2,3
cValue1=1,cValue2=2,cValue3=3
Configure Chassis 2
cValue1=2
Configure Chassis 1,2,5-8
cValue1=1,cValue2=2,cValue3=5,cValue4=6,cValue5=7,cValue6=8
Given that there are 10 switches in a chassis, This could potentially be broken into 10 Values.
So after the vaules have been sorted it, How many ever vaules their are is how many time the next question would be asked, but representing a different chassis number.
I would want this line to change in the question representing the chassis number.
**THIS CONFIGURATION IS FOR CHASSIS NUMBER " << chassisNum << " **" << endl;
So this question I am just asking what ports do I want to configure for the given chassis ID. I would like the same options. I would like to either run a range command here, numbers seprated by commas or both. After the numbers have been entered they would then need to be divided into different vaules and then run a looping condition on the next Question.
Example:
Configure Ports 1,2,3
pValue1=1,pValue2=2,pValue3=3
Configure Ports 2
pValue1=2
Configure Ports 1,2,5-8
pValue1=1,pValue2=2,pValue3=5,pValue4=6,pValue5=7,pValue6=8
Given that there are 48 ports on a switch, This could potentially be broken into 48 Values.
After those two questions have been seperated out into vaules. Then they need to be put int something like this.
cout << "set interface ge-" << cValue# << "/0/" << pValue#
and then multiplied out how ever many times it needs to be. Im assuming that this could be up to 10 sets of code, 1 for each chassis ID.
If I configured 10 Switches with 48 ports, I should end up with 480 lines of output just for the interface configuration part. This is all I am trying to get accomplished.
Im sure there is an easier way of doing it than what I started on the bottom. I was not even sure if I was going in the right direction with that. Like I said I am no pro at this just a newbie so any help I would epreciate.
I also am not asking for anyone to complete this for me but just provide some verable to get me started on how seperate a string into multiple values and then carry those over to a function (Not sure) and make it loop so many times to get the appropriate amount of code for all interfaces that need to be configured for each chassis.
Thanks Again
// Juniper Port Configuration
#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;
int main()
{
int option_continue;
float chassisNum;
float portNum;
string nameVLAN;
string idVLAN;
string ipAddress;
string subnetMask;
float chassisOut;
// PROGRAM INTRODUCTION, START PROGRAM
cout << endl;
cout << " ******************************************************************" << endl;
cout << endl;
cout << " You are using Juniper Networks Configuration Utility. " << endl;
cout << " For 'EX' Switches, version 1.0" << endl;
cout << endl;
cout << " Answer the questions and this program will" << endl;
cout << " print out the configuration." << endl;
cout << endl;
cout << " Type '1' and then press 'Enter' to begin." << endl;
cout << endl;
cout << " ******************************************************************" << endl;
cout << endl;
cout << " ==>";cin >> option_continue;
// FIRST QUESTION, ENTER CHASSIS NUMBER OF SWITCH
cout << endl;
cout << " ******************************************************************" << endl;
cout << endl;
cout << " Whats the 'Chassis Number' of the switch you want to configure?" << endl;
cout << endl;
cout << " There is a Max of 10 Switches in a Chassis." << endl;
cout << " You can use the following numbers: 0,1,2,3,4,5,6,7,8,9." << endl;
cout << endl;
cout << " If you want to program multiple Chassis, you can enter" << endl;
cout << " multiple numbers seperated by a comma, DO NOT USE SPACES." << endl;
cout << endl;
cout << " Example: Type '0' if the Chassis number is '0' (GE-0/0/0)" << endl;
cout << " Type '1' if the Chassis number is '1' (GE-1/0/0)" << endl;
cout << " Type '2' if the Chassis number is '2' (GE-2/0/0)" << endl;
cout << " Type '4,6,8' if you want to program Chassis numbers" << endl;
cout << " '4,6,8' (GE-4/0/0,GE-6/0/0,GE-8/0/0)" << endl;
cout << endl;
cout << " ******************************************************************" << endl;
cout << endl;
cout << " ==>";cin >> chassisNum;
// CREAT LOOP HERE TO RUN THE NEXT QUESTION FOR HOW MANY VAULES PLACES THERE ARE IN FIRST QUESTION
// IF TWO NUMBERS SEPERATED BY A COMMA ARE ENTERED IN FIRST QUESTION THEN RUN THE SECOND QUESTION TWICE
// SECOND QUESTION,WHAT PORTS DO YOU WANT TO CONFIGURE FOR THE GIVEN CHASSIS
cout << endl;
cout << " ******************************************************************" << endl;
cout << endl;
cout << " **THIS CONFIGURATION IS FOR CHASSIS NUMBER " << chassisNum << " **" << endl;
cout << endl;
cout << " What 'Ports' do you want to configure on the switch?" << endl;
cout << endl;
cout << " There is a Max of 48 Ports per." << endl;
cout << " You can use the following numbers: 0,1,2,3,4,5,6,7,8,9,10,11,12," << endl;
cout << " 13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33," << endl;
cout << " 34,35,36,37,38,39,40,41,42,43,44,45,46,47" << endl;
cout << endl;
cout << " If you want to program multiple Ports, you can enter" << endl;
cout << " multiple numbers seperated by a comma, DO NOT USE SPACES." << endl;
cout << endl;
cout << " Example: Type '0' if the Port number is 0 (GE-0/0/0)" << endl;
cout << " Type '1' if the Port number is 1 (GE-0/0/1)" << endl;
cout << " Type '2' if the Port number is 2 (GE-0/0/2)" << endl;
cout << " Type '4,6,8' if you want to program Port numbers" << endl;
cout << " '4,6,8' (GE-0/0/4,GE-0/0/6,GE-0/0/8)" << endl;
cout << endl;
cout << " ******************************************************************" << endl;
cout << endl;
cout << " ==>";cin >> portNum;
//THIRD QUESTION, TYPE THE VLAN NAME
cout << endl;
cout << " ******************************************************************" << endl;
cout << endl;
cout << " Type the VLAN Name: " << endl;
cout << endl;
cout << " The 'VLAN Name' cannot have any spaces before, after" << endl;
cout << " or in the name." << endl;
cout << endl;
cout << " Example: Type 'Default' if the 'VLAN Name' is Default" << endl;
cout << endl;
cout << " ******************************************************************" << endl;
cout << endl;
cout << " ==>";cin >> nameVLAN;
//FORTH QUESTION, TYPE THE VLAN ID
cout << endl;
cout << " ******************************************************************" << endl;
cout << endl;
cout << " Type the VLAN ID: " << endl;
cout << " This can also be reffered to as 'VLAN Number' or 'VLAN Tag'." << endl;
cout << endl;
cout << " The 'VLAN ID' cannot have any spaces before, after" << endl;
cout << " or in the ID. 'VLAN ID' can only contain numbers." << endl;
cout << " You can uses numbers 1 through 4094." << endl;
cout << endl;
cout << " Example: Type '100' if the 'VLAN ID' is 100" << endl;
cout << endl;
cout << " ******************************************************************" << endl;
cout << endl;
cout << " ==>";cin >> idVLAN;
//FITH QUESTION, TYPE THE IP ADDRESS OF VLAN
cout << endl;
cout << " ******************************************************************" << endl;
cout << endl;
cout << " Type the IP address of the VLAN: " << endl;
cout << endl;
cout << " The 'address' cannot have any spaces before, after" << endl;
cout << " or in the address. The 'address' contains 4 Octets" << endl;
cout << " seperated by 3 periods" << endl;
cout << endl;
cout << " Example: Type '172.16.100.254' if the 'address' is 172.16.100.254" << endl;
cout << endl;
cout << " ******************************************************************" << endl;
cout << endl;
cout << " ==>";cin >> ipAddress;
//SIXTH QUESTION, TYPE THE SUBNET MASK IN CIDER NOTATION
cout << endl;
cout << " ******************************************************************" << endl;
cout << endl;
cout << " Type the Subnet Mask in Cider Notation: /" << endl;
cout << endl;
cout << " --- CLASS 'C' --- --- CLASS 'B' --- --- CLASS 'A' ---" << endl;
cout << " /30 = 255.255.255.252 /23 = 255.255.254.0 /15 = 255.254.0.0" << endl;
cout << " /29 = 255.255.255.248 /22 = 255.255.252.0 /14 = 255.252.0.0" << endl;
cout << " /28 = 255.255.255.240 /21 = 255.255.248.0 /13 = 255.248.0.0" << endl;
cout << " /27 = 255.255.255.224 /20 = 255.255.240.0 /12 = 255.240.0.0" << endl;
cout << " /26 = 255.255.255.192 /19 = 255.255.224.0 /11 = 255.224.0.0" << endl;
cout << " /25 = 255.255.255.128 /18 = 255.255.192.0 /10 = 255.192.0.0" << endl;
cout << " /24 = 255.255.255.0 /17 = 255.255.128.0 /9 = 255.128.0.0" << endl;
cout << " /16 = 255.255.0.0 /8 = 255.0.0.0" << endl;
cout << endl;
cout << " Only type the number. DO NOT TYPE THE SLASH" << endl;
cout << endl;
cout << " Example: Type '24' if the 'Subnet Mask' is 255.255.255.0" << endl;
cout << endl;
cout << " ******************************************************************" << endl;
cout << endl;
cout << " ==>";cin >> subnetMask;
chassisOut = chassisNum;
cout << endl;
cout << " ******************************************************************" << endl;
cout << endl;
cout << " Copy the configuration below and past into your," << endl;
cout << " Juniper Console under 'Edit' mode. At 'Top' of 'root'. (root#)" << endl;
cout << endl;
cout << " ******************************************************************" << endl;
cout << endl;
cout << "set vlan " << nameVLAN << " l3-interface vlan." << idVLAN << endl;
cout << "set interface vlan unit " << idVLAN << " family inet address " << ipAddress << "/" << subnetMask << endl;
if (portNum == 0)
{
cout << "set interface ge-" << chassisOut << "/0/0" << " family ethernet-switching vlan members " << nameVLAN << endl;
}
if (portNum == 1)
{
cout << "set interface ge-" << chassisOut << "/0/1" << " family ethernet-switching vlan members " << nameVLAN << endl;
}
if (portNum == 2)
{
cout << "set interface ge-" << chassisOut << "/0/2" << " family ethernet-switching vlan members " << nameVLAN << endl;
}
if (portNum == 3)
{
cout << "set interface ge-" << chassisOut << "/0/3" << " family ethernet-switching vlan members " << nameVLAN << endl;
}
return 0;
}
Below, My "First Question" of the program is, What Switch Chassis ID do you want to program? There are up to 10 switches in a Chassis, The ID's start at 0 through 9.
I would like to either run a range command here, numbers seprated by commas or both. After the numbers have been entered they would then need to be divided into different vaules and then run a looping condition on the next Question.
Example:
Configure Chassis 1,2,3
cValue1=1,cValue2=2,cValue3=3
Configure Chassis 2
cValue1=2
Configure Chassis 1,2,5-8
cValue1=1,cValue2=2,cValue3=5,cValue4=6,cValue5=7,cValue6=8
Given that there are 10 switches in a chassis, This could potentially be broken into 10 Values.
So after the vaules have been sorted it, How many ever vaules their are is how many time the next question would be asked, but representing a different chassis number.
I would want this line to change in the question representing the chassis number.
**THIS CONFIGURATION IS FOR CHASSIS NUMBER " << chassisNum << " **" << endl;
So this question I am just asking what ports do I want to configure for the given chassis ID. I would like the same options. I would like to either run a range command here, numbers seprated by commas or both. After the numbers have been entered they would then need to be divided into different vaules and then run a looping condition on the next Question.
Example:
Configure Ports 1,2,3
pValue1=1,pValue2=2,pValue3=3
Configure Ports 2
pValue1=2
Configure Ports 1,2,5-8
pValue1=1,pValue2=2,pValue3=5,pValue4=6,pValue5=7,pValue6=8
Given that there are 48 ports on a switch, This could potentially be broken into 48 Values.
After those two questions have been seperated out into vaules. Then they need to be put int something like this.
cout << "set interface ge-" << cValue# << "/0/" << pValue#
and then multiplied out how ever many times it needs to be. Im assuming that this could be up to 10 sets of code, 1 for each chassis ID.
If I configured 10 Switches with 48 ports, I should end up with 480 lines of output just for the interface configuration part. This is all I am trying to get accomplished.
Im sure there is an easier way of doing it than what I started on the bottom. I was not even sure if I was going in the right direction with that. Like I said I am no pro at this just a newbie so any help I would epreciate.
I also am not asking for anyone to complete this for me but just provide some verable to get me started on how seperate a string into multiple values and then carry those over to a function (Not sure) and make it loop so many times to get the appropriate amount of code for all interfaces that need to be configured for each chassis.
Thanks Again
// Juniper Port Configuration
#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;
int main()
{
int option_continue;
float chassisNum;
float portNum;
string nameVLAN;
string idVLAN;
string ipAddress;
string subnetMask;
float chassisOut;
// PROGRAM INTRODUCTION, START PROGRAM
cout << endl;
cout << " ******************************************************************" << endl;
cout << endl;
cout << " You are using Juniper Networks Configuration Utility. " << endl;
cout << " For 'EX' Switches, version 1.0" << endl;
cout << endl;
cout << " Answer the questions and this program will" << endl;
cout << " print out the configuration." << endl;
cout << endl;
cout << " Type '1' and then press 'Enter' to begin." << endl;
cout << endl;
cout << " ******************************************************************" << endl;
cout << endl;
cout << " ==>";cin >> option_continue;
// FIRST QUESTION, ENTER CHASSIS NUMBER OF SWITCH
cout << endl;
cout << " ******************************************************************" << endl;
cout << endl;
cout << " Whats the 'Chassis Number' of the switch you want to configure?" << endl;
cout << endl;
cout << " There is a Max of 10 Switches in a Chassis." << endl;
cout << " You can use the following numbers: 0,1,2,3,4,5,6,7,8,9." << endl;
cout << endl;
cout << " If you want to program multiple Chassis, you can enter" << endl;
cout << " multiple numbers seperated by a comma, DO NOT USE SPACES." << endl;
cout << endl;
cout << " Example: Type '0' if the Chassis number is '0' (GE-0/0/0)" << endl;
cout << " Type '1' if the Chassis number is '1' (GE-1/0/0)" << endl;
cout << " Type '2' if the Chassis number is '2' (GE-2/0/0)" << endl;
cout << " Type '4,6,8' if you want to program Chassis numbers" << endl;
cout << " '4,6,8' (GE-4/0/0,GE-6/0/0,GE-8/0/0)" << endl;
cout << endl;
cout << " ******************************************************************" << endl;
cout << endl;
cout << " ==>";cin >> chassisNum;
// CREAT LOOP HERE TO RUN THE NEXT QUESTION FOR HOW MANY VAULES PLACES THERE ARE IN FIRST QUESTION
// IF TWO NUMBERS SEPERATED BY A COMMA ARE ENTERED IN FIRST QUESTION THEN RUN THE SECOND QUESTION TWICE
// SECOND QUESTION,WHAT PORTS DO YOU WANT TO CONFIGURE FOR THE GIVEN CHASSIS
cout << endl;
cout << " ******************************************************************" << endl;
cout << endl;
cout << " **THIS CONFIGURATION IS FOR CHASSIS NUMBER " << chassisNum << " **" << endl;
cout << endl;
cout << " What 'Ports' do you want to configure on the switch?" << endl;
cout << endl;
cout << " There is a Max of 48 Ports per." << endl;
cout << " You can use the following numbers: 0,1,2,3,4,5,6,7,8,9,10,11,12," << endl;
cout << " 13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33," << endl;
cout << " 34,35,36,37,38,39,40,41,42,43,44,45,46,47" << endl;
cout << endl;
cout << " If you want to program multiple Ports, you can enter" << endl;
cout << " multiple numbers seperated by a comma, DO NOT USE SPACES." << endl;
cout << endl;
cout << " Example: Type '0' if the Port number is 0 (GE-0/0/0)" << endl;
cout << " Type '1' if the Port number is 1 (GE-0/0/1)" << endl;
cout << " Type '2' if the Port number is 2 (GE-0/0/2)" << endl;
cout << " Type '4,6,8' if you want to program Port numbers" << endl;
cout << " '4,6,8' (GE-0/0/4,GE-0/0/6,GE-0/0/8)" << endl;
cout << endl;
cout << " ******************************************************************" << endl;
cout << endl;
cout << " ==>";cin >> portNum;
//THIRD QUESTION, TYPE THE VLAN NAME
cout << endl;
cout << " ******************************************************************" << endl;
cout << endl;
cout << " Type the VLAN Name: " << endl;
cout << endl;
cout << " The 'VLAN Name' cannot have any spaces before, after" << endl;
cout << " or in the name." << endl;
cout << endl;
cout << " Example: Type 'Default' if the 'VLAN Name' is Default" << endl;
cout << endl;
cout << " ******************************************************************" << endl;
cout << endl;
cout << " ==>";cin >> nameVLAN;
//FORTH QUESTION, TYPE THE VLAN ID
cout << endl;
cout << " ******************************************************************" << endl;
cout << endl;
cout << " Type the VLAN ID: " << endl;
cout << " This can also be reffered to as 'VLAN Number' or 'VLAN Tag'." << endl;
cout << endl;
cout << " The 'VLAN ID' cannot have any spaces before, after" << endl;
cout << " or in the ID. 'VLAN ID' can only contain numbers." << endl;
cout << " You can uses numbers 1 through 4094." << endl;
cout << endl;
cout << " Example: Type '100' if the 'VLAN ID' is 100" << endl;
cout << endl;
cout << " ******************************************************************" << endl;
cout << endl;
cout << " ==>";cin >> idVLAN;
//FITH QUESTION, TYPE THE IP ADDRESS OF VLAN
cout << endl;
cout << " ******************************************************************" << endl;
cout << endl;
cout << " Type the IP address of the VLAN: " << endl;
cout << endl;
cout << " The 'address' cannot have any spaces before, after" << endl;
cout << " or in the address. The 'address' contains 4 Octets" << endl;
cout << " seperated by 3 periods" << endl;
cout << endl;
cout << " Example: Type '172.16.100.254' if the 'address' is 172.16.100.254" << endl;
cout << endl;
cout << " ******************************************************************" << endl;
cout << endl;
cout << " ==>";cin >> ipAddress;
//SIXTH QUESTION, TYPE THE SUBNET MASK IN CIDER NOTATION
cout << endl;
cout << " ******************************************************************" << endl;
cout << endl;
cout << " Type the Subnet Mask in Cider Notation: /" << endl;
cout << endl;
cout << " --- CLASS 'C' --- --- CLASS 'B' --- --- CLASS 'A' ---" << endl;
cout << " /30 = 255.255.255.252 /23 = 255.255.254.0 /15 = 255.254.0.0" << endl;
cout << " /29 = 255.255.255.248 /22 = 255.255.252.0 /14 = 255.252.0.0" << endl;
cout << " /28 = 255.255.255.240 /21 = 255.255.248.0 /13 = 255.248.0.0" << endl;
cout << " /27 = 255.255.255.224 /20 = 255.255.240.0 /12 = 255.240.0.0" << endl;
cout << " /26 = 255.255.255.192 /19 = 255.255.224.0 /11 = 255.224.0.0" << endl;
cout << " /25 = 255.255.255.128 /18 = 255.255.192.0 /10 = 255.192.0.0" << endl;
cout << " /24 = 255.255.255.0 /17 = 255.255.128.0 /9 = 255.128.0.0" << endl;
cout << " /16 = 255.255.0.0 /8 = 255.0.0.0" << endl;
cout << endl;
cout << " Only type the number. DO NOT TYPE THE SLASH" << endl;
cout << endl;
cout << " Example: Type '24' if the 'Subnet Mask' is 255.255.255.0" << endl;
cout << endl;
cout << " ******************************************************************" << endl;
cout << endl;
cout << " ==>";cin >> subnetMask;
chassisOut = chassisNum;
cout << endl;
cout << " ******************************************************************" << endl;
cout << endl;
cout << " Copy the configuration below and past into your," << endl;
cout << " Juniper Console under 'Edit' mode. At 'Top' of 'root'. (root#)" << endl;
cout << endl;
cout << " ******************************************************************" << endl;
cout << endl;
cout << "set vlan " << nameVLAN << " l3-interface vlan." << idVLAN << endl;
cout << "set interface vlan unit " << idVLAN << " family inet address " << ipAddress << "/" << subnetMask << endl;
if (portNum == 0)
{
cout << "set interface ge-" << chassisOut << "/0/0" << " family ethernet-switching vlan members " << nameVLAN << endl;
}
if (portNum == 1)
{
cout << "set interface ge-" << chassisOut << "/0/1" << " family ethernet-switching vlan members " << nameVLAN << endl;
}
if (portNum == 2)
{
cout << "set interface ge-" << chassisOut << "/0/2" << " family ethernet-switching vlan members " << nameVLAN << endl;
}
if (portNum == 3)
{
cout << "set interface ge-" << chassisOut << "/0/3" << " family ethernet-switching vlan members " << nameVLAN << endl;
}
return 0;
}