aprile 11, 2012

Programming ADO.NET: A Beginner's Tutorial for Understanding ADO.NET

Introduction

This article aims at understanding the various concepts and classes available for data access in ADO.NET. This article is meant for absolute beginners and discusses various techniques of data access using ADO.NET.

Background

ADO.NET is a set of classes that comes with the Microsoft .NET framework to facilitate data access from managed languages. ADO.NET has been in existence for a long time and it provides a comprehensive and complete set of libraries for data access. The strength of ADO.NET is firstly that it lets applications access various types of data using the same methodology. If I know how to use ADO.NET to access a SQL Server database then the same methodology can be used to access any other type of database (like Oracle or MS Access) by just using a different set of classes. Secondly, ADO.NET provides two models for data access: a connected model where I can keep the connection with the database and perform data access, and another way is to get all the data in ADO.NET objects that let us perform data access on disconnected objects.

Note: Many developers and development houses are now using ORMs to perform data access instead of using ADO.NET. ORMs provide a lot of data access functionality out of the box and relieves users from writing mundane data access code again and again. Still, I think that knowing and understanding ADO.NET is crucial as a .NET developer as it gives a better understanding of the data access methodologies. Also, there are many development houses that are still using ADO.NET.

Let us try to visualize ADO.NET data access using the following diagram:
The diagram above shows that ADO.NET can be used with any kind of application, i.e., it can be used from a Windows Forms application, an ASP.NET application, or from a WPF and/or Silverlight application. Also, the data store underneath can be any data store, SQL Server, Access, or Oracle. It is just a matter of using the right set of classes specific to that data store and the methodology will remain the same.

Using the code

Let us try to understand a few ADO.NET classes and methodologies by writing a small web application. This application uses a sample database from Microsoft (subset of the Pubs database) and we will use this database for understanding the various classes and methods of ADO.NET. We will be using ADO.NET classes specific to SQL Server but once it is understood, the basic philosophy remains the same and can be applied with any data store.

Before jumping into the code, we will have to understand some of the important objects of ADO.NET. In a typical scenario requiring data access, we need to perform four major tasks:

Connecting to the database
Passing the request to the database, i.e., a command like select, insert, or update.
Getting back the results, i.e., rows and/or the number of rows effected.
Storing the result and displaying it to the user.
This can be visualized as:


So now we need to understand how we can achieve these functionalities using ADO.NET.

The Connection

The ADO.NET Connection class is used to establish a connection to the database. The Connection class uses a ConnectionString to identify the database server location, authentication parameters, and other information to connect to the database. This ConnectionString is typically stored in the web.config.


connectionString ="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\PUBS.MDF;
Integrated Security=True;User Instance=True" />
Let us see how we can use the SqlConnection class to establish a connection with a database.


private SqlConnection con = null;
con = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString);
Now we have a connection ready with our database. Whenever we want to retrieve data, we just need to open the connection, perform the operation, and close the connection.

Storing the Result

Before we can jump to understanding how we can execute commands on a database, we first need to understand how we can store the results and these results can be displayed to the user. To get the hang of how we can store the results, we need to understand a few ADO.NET objects.

DataReader - A DataReader is an object that can be used to access the results sequentially from a database. The DataReader is used to get forward only sequential results as the query executes. This is used with the Command object (we will see the usage shortly).
Dataset - The Dataset can be thought of as an in-memory representation of a database.
A DataSet is a disconnected data access object. The result of the query can be stored in a Dataset. The DataSet contains DataTables. The DataTables contain DataRow and DataColumns.
A DataSet or a DataTable can be used with a Command and a DataAdapter object to store query results.
DataAdapter - A DataAdapter object is used to fill a DataSet/DataTable with query results. This can be thought of as the adapter between the connected and disconnected data models.
A Command object will be used to execute the query and a DataAdapter will use this Command object and fill the query results coming from the database into a DataSet/DataTable.

Note:
There are more objects that can/are used to store results but we will mainly be using these in this article.
The usage and implentation of these objects are in the next section, as understanding the Command object is required before that.
The Command

Once we have the connection ready, the next step would be to tell the database about what operation we need to perform on the database. This can be done using the Command object.
We will be using SqlCommand to tell the database about the operation we need to perform.
The typical commands on a database will be:

Select Command - This will return a set of rows to the application.
Insert Command - This will return the number of rows inserted.
Delete Command - This will return the number of rows deleted.
Update Command - This will return the number of rows updated.

Note: We are only talking about data manipulation commands in this article.

All these commands expect SQL syntax. This SQL can either be passed from the application or can be written in the form of Stored Procedures and executed using a SqlCommand.

Using a Stored Procedure with a Command

If we want to use a Stored Procedure with a Command object then we need to specify it as:


cmd = con.CreateCommand();
// This will specify that we are passing the stored procedures name
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = CommandName; // This will be the stored procedures name
If the Stored Procedure is expecting some parameters then we can pass these parameters by creating instances of SqlParameter objects as:


SqlCommand cmd = con.CreateCommand();
// This will specify that we are passing the stored procedures name
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = CommandName; // This will be the stored procedures name
SqlParameter param = new SqlParameter("@id", txtSearch.Text);
cmd.Parameters.Add(param);
Passing a SQL query from an application using a Command

If we want to pass a SQL query from our application then we can use the SqlCommand as:


SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text; //This will specify that we are passing query from application
string query = "select * from Authors";
cmd.CommandText = query;

There is one important thing to understand here and that is SqlParameters. Many a times we will need to pass parameters in our SQL query. This can be done in two ways: we can create a query using string concatenation like:


SqlCommand cmd = con.CreateCommand();
//This will specify that we are passing query from application
cmd.CommandType = CommandType.Text;
string query = "select * from Authors where authorId = '" + txtSearch.Text + "'";
cmd.CommandText = query;

This is not recommended as this approach is error prone and is vulnerable to SQL Injection attacks. So whenever we need to pass parameters to a query the preferred way is using SqlParameters. The same query can be written as:


SqlCommand cmd = con.CreateCommand();
//This will specify that we are passing query from application
cmd.CommandType = CommandType.Text;
string query = "select * from Authors where authorId = @id";
cmd.CommandText = query;

SqlParameter param = new SqlParameter("@id", txtSearch.Text);
cmd.Parameters.Add(param);

Using SqlParameters gives a cleaner, less error prone and SQL injection safe (comparative) code.

Executing the Select Command

Now let us see how we can retrieve the result of a Select command in the form of a DataTable.


public DataTable ExecuteSelectCommand(string CommandName, CommandType cmdType)
{
SqlCommand cmd = null;
DataTable table = new DataTable();

cmd = con.CreateCommand();

cmd.CommandType = cmdType;
cmd.CommandText = CommandName;

try
{
con.Open();

SqlDataAdapter da = null;
using (da = new SqlDataAdapter(cmd))
{
da.Fill(table);
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
cmd.Dispose();
cmd = null;
con.Close();
}

return table;
}

public DataTable ExecuteParamerizedSelectCommand(string CommandName,
CommandType cmdType, SqlParameter[] param)
{
SqlCommand cmd = null;
DataTable table = new DataTable();

cmd = con.CreateCommand();

cmd.CommandType = cmdType;
cmd.CommandText = CommandName;
cmd.Parameters.AddRange(param);

try
{
con.Open();

SqlDataAdapter da = null;
using (da = new SqlDataAdapter(cmd))
{
da.Fill(table);
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
cmd.Dispose();
cmd = null;
con.Close();
}

return table;
}
Executing Update, Delete, and Insert Commands

Commands like insert, update, delete are executed by calling the ExecuteNonQuery method of SqlCommand. Let us see how we can write a simple function that will execute these commands. These commands can be used by passing a query from the application or by invoking Stored Procedures (same as we saw above).


public bool ExecuteNonQuery(string CommandName, CommandType cmdType, SqlParameter[] pars)
{
SqlCommand cmd = null;
int res = 0;

cmd = con.CreateCommand();

cmd.CommandType = cmdType;
cmd.CommandText = CommandName;
cmd.Parameters.AddRange(pars);

try
{
con.Open();

res = cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
throw ex;
}
finally
{
cmd.Dispose();
cmd = null;
con.Close();
}

if (res >= 1)
{
return true;
}
return false;
}
Using the sample application

The first thing to notice in the application is that it contains a class that is responsible for all the ADO.NET logic. The class DataAccess (file: DataAccess.cs) contains all the ADO.NET classes and methods. All the pages use this class.
This class can be reused in any application with some minor application specific changes.

The class diagram for the class is:

The sample application contains four pages:

Authors.aspx
Titles.aspx
AddAuthors.aspx
AddTitles.aspx

The author pages, i.e., Authors.aspx and AddAuthors.aspx, use Stored Procedures to perform the operations whereas the title pages pass all the queries from the application to the database. We have mainly implemented Select and Insert commands but Update and Delete can be implemented on the same lines as Insert.

Some things worth mentioning about the application are:

This should in no way be treated as a design reference for the data access layer. This is only to demonstrate ADO.NET logic.

The code is written in such a way as to provide a clear understanding from a beginner's perspective, i.e., experienced programmers will find a lot of possible optimizations in the code.
No client side or server side validations have been provided as that was not the scope of this article.

There is no design (architecture wise and look wise) in this application.

Points of interest

Since ADO.NET has been in existence for so many years, many people will think that this article is very late and probably useless. But the idea behind writing this article is to target those developers who are still in the early stages of their software development.
Also, the presence of ORMs has made ADO.NET obsolete for many development houses but still knowing how ADO.NET works could be really helpful in improving data access understanding.

aprile 09, 2012

Cisco Networking: Troubleshooting Switch Stacks

Fixing Incompatible Cisco IOS Versions and Switch-Stack Protocol Versions

A new switch might not join a stack when Cisco IOS versions or stack protocol versions differ. Review these points about Cisco IOS versions and stack protocol versions:

•Switches with the same Cisco IOS version also have the same stack protocol version and are compatible in the same switch stack.

•Switches with the same Cisco IOS version as the stack master can join the stack.

•Switches with different Cisco IOS versions can have different stack protocol versions.

•Switches with the same Cisco IOS version but different major version numbers are incompatible and cannot function in the same switch stack.

The stack master reports the reason for any incompatibility.

The Cisco IOS software version running on a switch that you plan to add to a switch stack must either be the same as or compatible with on the master switch version. After you connect a new switch to a switch stack, enter the show version user EXEC command to see the version information, the switch types, and the active Cisco IOS version for each switch:

Stack# show version
Switch Ports Model SW Version SW Image
------ ----- ----- ---------- ----------
* 1 30 WS-C3750E-24PD 12.2(46)SE C3750E-UNIVERSAL-M
2 28 WS-C3750E-24PS 12.2(46)SE C3750E-UNIVERSAL-M
3 54 WS-C3750E-48TD 12.2(46)SE C3750E-UNIVERSAL-M
...
output truncated

If stack members are running incompatible Cisco IOS versions, software version incompatibilities called mismatches occur. If you have a switch that cannot join a switch stack, enter the show switch user EXEC command to see whether the state of the switch is in Version Mismatch (see Switch 3):

Stack# show switch
H/W Current
Switch# Role Mac Address Priority Version State
----------------------------------------------------------
*1 Master 0018.ba60.de00 15 1 Ready
2 Member 0018.ba60.ce00 14 1 Ready
3 Member 0016.9d0c.7500 1 2 Version Mismatch

To see which software version switch 3 is running, enter the remote 3 show version command.

If the stack master detects that the software on a new switch does not match, it upgrades (or downgrades) the new switch with the active image that is running on the switch stack by using the automatic upgrade (auto-upgrade) and the automatic advise (auto-advise) features.

Switches with the same major version number but a different minor version number are considered partially compatible. When you connect a partially compatible switch to a stack, the new switch might enter version-mismatch mode and not join the stack as a functional member. The current state in this case is also Version Mismatch, which you can see by entering the show switch user EXEC command:

Stack# show switch
H/W Current
Switch# Role Mac Address Priority Version State
----------------------------------------------------------
*1 Master 0018.ba60.de00 15 1 Ready
2 Member 0018.ba60.ce00 14 1 Ready
3 Member 0016.9d0c.7500 1 2 Version Mismatch

See the "Resolving Version Mismatches and Copying Files" section and the "Understanding Switch Hardware Priority and Stack Manager Version" section for more information.

Resolving Software License Compatibility Issues

Mismatched or incompatible software license levels might prevent a Catalyst 3750E switch from joining a stack. These license levels are also called sets, or feature sets:

•IP base (ipbase)

•IP services (ipservices)

•Advanced IP services (advanced ipservices)

Each member switch must have a compatible feature license. Otherwise, you need to upgrade the license level and then reload the switch.

To review the installed license in a member switch, enter these commands. In this example, member switches have the same license level:

Stack-1# show license all switch 1
License Store: Primary License Storage
StoreIndex: 0 Feature: advipservices
License Type: Permanent
License State: Active, In Use
Stack-1# show license all switch 2
License Store: Primary License Storage
StoreIndex: 0 Feature: advipservices
License Type: Permanent
License State: Active, In Use
A switch can have up to three installed licenses, but only one is active. Use the show version user EXEC command to see the active licenses. This example is part of the output message for one stack:

Stack-1# show version
Switch 03
---------
License Level : advipservices
License Type : Permanent
Next reboot licensing Level : advipservices
Switch 04
---------
License Level : advipservices
License Type : Permanent
Next reboot licensing Level : advipservices

Reload the switch after you upgrade the license level. See the appropriate software configuration guide for more information on license administration.


Note Activating a specific feature set on Catalyst 3750 switches requires a specific Cisco IOS version in each switch. These switches do not use licenses to activate features.
Resolving Incompatible Configurations

A switch previously used as a standalone or in a different stack might have different configuration settings. Return the switch to its default values before you connect it to a new stack.

When you add a switch to a stack, the stack master automatically changes the configuration of the new switch. The master switch revises the new member switch port numbers to conform to the current port numbering sequence in the stack. Any existing port-level configuration in the newly-added switch is automatically cleared or updated.

If you add a switch that was a member of one stack to a different stack, the switch port numbers might be inappropriate. For example, instead of the Ethernet ports being numbered with the default values of Fa1/0/1 or G1/0/1, the port numbering might start with Fa2/0/1 or G2/0/1. If the port numbers begin with G2/0/1, for example, enter the switch renumber global configuration command to return switch ports to the default numbering values as shown in this example:

Switch(config)# switch 2 renumber 1

When you reboot the switch, all port-level configurations are removed, and port numbering begins with Fa1/0/1 or G1/0/1.

To prevent incompatible configurations, follow these steps on a previously configured switch that you plan to add to the stack:

1. Delete the config.text file and vlan.dat files from flash memory.

2. Set all options such as the SDM template and port numbers to their default values.

3. Install the same Cisco IOS version that is running in the stack.

4. Power off the switch.

5. Connect the StackWise cables.

6. Power on the switch.

Fixing SDM Template Configuration Incompatibilities (Catalyst 3750G-12S Switches)

The master switch automatically corrects SDM template mismatches in Catalyst 3750 and 3750E switches when you connect one of them to a stack. A configuration mismatch might occur if the switch was a Catalyst 3750G-12S switch configured with a nondefault SDM template before you connect it to a stack.

•To display the configured SDM template on a switch, enter the show sdm prefer privileged EXEC command.

•To change a Catalyst 3750G-12S switch SDM template to the default setting before you connect it to a stack, enter the sdm prefer default global configuration command.

See the appropriate software configuration guide for additional information on SDM templates.

Resolving StackWise Connection Problems

These sections discuss how to resolve problems with StackWise connections:

•Fixing Problems with StackWise Interfaces and Cables

•Resolving Stack Partitions

When you connect a switch to a stack, make sure you properly connect both StackWise cables. It is possible for a switch to join a stack when only one StackWise cable is connected to another active stack member, in which case the stack operates at less than maximum ring bandwidth.

An open ring operates at half the available bandwidth. After you connect both StackWise cables of the new switch and it has joined the ring, full ring bandwidth is restored.

Consider these precautions when you connect StackWise cables:

•Loose connector retainer screws allow the connector to move and possibly disconnect. Always tighten the retainer screws when you test a StackWise cable. A connector or retainer screw might appear to be fully engaged, but if it is not adequately tightened, port flapping or a no-link-present state might occur.

•If you use a screwdriver to tighten the retainer screws, avoid excessive force. Tighten the screws only until the connector is fully engaged. Tighten each of the retainer screws to the same degree.

When you troubleshoot suspected cable connection problems, use the show switch user EXEC command to review the status of switches in the stack. In this example, you can see that switch #3 is in the Provisioned state, which means you need to investigate why. See the descriptions in Table 1.


Table 1 Current State Output and Descriptions

Current State
Description
Ready

The switch is fully operational.

Progressing

The stack master is communicating with the new switch joining the stack.

Provisioned

Ports are assigned in the stack running-configuration, but no switch with the port numbers Fa3/0/1, G3/0/1, and so on, is detected in the stack. If a switch that previously joined a stack is removed, the port numbers remain in the running-configuration, and the missing switch is shown as Provisioned.

The Provisioned state might be caused by a switch that is no longer connected to the stack or be the result of manually preprovisioning the related ports. See the Catalyst 3750 or the Catalyst 3750-E switch software configuration guide for more information on preprovisioning switches in a stack.


Fixing Problems with StackWise Interfaces and Cables

A defective StackWise interface might prevent a switch from joining a stack and can also cause stack port flapping. The best way to test a StackWise interface is by using a known good StackWise cable to connect the two StackWise interfaces. The switch should report a good connection when you enter the show switch detail user EXEC command.

StackWise cable connection problems are usually caused by a loose connection, not a defect in the cable or connector. If two StackWise cables are connected to another stack member, the switch should join the stack even if one of the cables is defective. If you connect only one StackWise cable to a switch and the connection is unreliable, that switch might not join the stack.

The best way to test a StackWise cable that you suspect is defective is to replace it with a known-good cable. If replacing the cable solves the problem, the replaced cable is possibly defective. However, an unreliable connection that was corrected when you replaced the cable might also have been the cause.

If you do not have replacement cable, use these steps to verify whether a cable or a stack member port is faulty:

1. Exchange the cable with another cable in the stack. If you must connect the cable to active, powered-on switches, wait 60 seconds for the stack to reconverge and stabilize after you connect the cable. Use the show switch user EXEC command to identify active stack members and stack member ports.

2. Make sure that you tighten the retainer screws when you test a StackWise cable or port. Loose retainer screws are a common source of trouble. Avoid overtightening the retainer screws, and tighten both of the retainer screws to the same degree.

You can also test a StackWise cable or interface by using only one cable and one switch. Connect the StackWise cable to both StackWise interfaces on the same switch (see Figure 1).

Figure 1 Using One Cable and Switch to Test a StackWise Cable or Interface


Boot or reboot the switch. This message appears:

SM: Detected stack cables at PORT1 PORT2

The message does not conclusively mean that there are no problems with the interfaces or cable. However, the cable and the member ports are probably good.

If a StackWise cable is connected to both StackWise ports on the switch and this message appears, either the cable is defective or StackWise port 2 is defective:

SM: Detected stack cables at PORT1

Enter the show switch detail user EXEC command to review the status of specific StackWise interfaces:


The switches in this example are active stack members, but the ring is incomplete. This example is typical of a missing cable between two switches. After you connect a known-good cable between switch 1 and switch 3, the stack ports become active and show a status of OK. This situation might be a switch hardware problem, but before you replace a switch, verify that the StackWise cables are correctly connected; that is, make sure the retainer screws are equally tightened.

This shows the results of an added StackWise cable between switch 1, port 1 and switch 3, port 2. All StackWise ports are active, and the ring is complete. Full stack bandwidth is available.


The retainer screw shown on the top of the connection shown in Figure 2 is not fully engaged, which can result in the connector working itself loose. The best practice is to finger-tighten both retainer screws to the same degree.

Figure 2 Example of Loose Retainer Screw

Resolving Stack Partitions

An improperly connected ring, a member switch failure, or a faulty StackWise cable connection can cause a stack partition. The stack separates into two independent stacks, each with a stack master. A stack partition usually changes configuration and port numbering. Each stack might also have the same IP address assigned to a switch virtual interface (SVI), which results in a duplicate IP address.

Joining a Stack: Typical Sequence States and Rules

•Using the Configuration Manager

•Using the Stack Manager

•Reviewing How the Stack Master Is Elected and Port Numbers Are Assigned

•Reviewing How the Stack Master is Rebooted or Disconnected

•Understanding Switch Hardware Priority and Stack Manager Version

This example shows a typical sequence when adding a switch to a stack:



This sequence takes several minutes. Continue to enter the show switch user EXEC command to see the current status.

These are other states that you might see when a switch is joining a stack:

•Feature Mismatch. The transition would be Progressing —> Feature Mismatch.

•Version Mismatch. The transition would be Progressing —> Version Mismatch.

After an automatic Cisco IOS upgrade corrects a detected Cisco IOS feature mismatch, the upgraded switch reloads before becoming a fully operational stack member.

Using the Configuration Manager

The configuration manager is a Cisco IOS control program that runs on the stack master. The configuration manager performs these functions:

•Maintains the running and saved configuration files and distributes them from the stack master to the member switches. The complete stack entity has one saved and one running configuration. All the switches in the stack use the stack-master running configuration.

•Keeps a copy of the startup and running configuration on all member switches. Any stack member can then become the new stack master.

•Synchronizes the running configuration to all member switches.

•When the stack master is powered off or rebooted, the newly elected stack master runs the configuration.

Using the Stack Manager

The Stack Manager is a Cisco IOS program that runs on the stack master switch and performs these tasks:

•Discovers other switches in the stack (stack members).

•Adds new switches to the stack after discovery.

•Removes a disconnected switch from the stack. The output of the show switch user EXEC command shows the switch as provisioned instead of ready.

•Elects a stack master during stack boot-up or when you disconnect the working stack master from the stack.

•Resolves switch number conflicts when a new switch joins. Assigns a switch number and port numbers to the new switch and reboots it to effect the changes.

•Communicates with other switches by using stack messages and gathers and stores information from stack messages.

•Manages a stack merge when you connect two independent stacks into a single, larger stack. Renumbers some of the switches and selects one stack master.

Reviewing How the Stack Master Is Elected and Port Numbers Are Assigned

All member switches participate in the election of a stack master if they all boot-up within the election window (20 to 60 seconds). The minimum time depends on which Cisco IOS version is running on the switches. This message appears:

Waiting for Master Election

Any switches that you connect to the stack after the election process completes are considered stragglers and do not participate in the stack master election. These are the procedural rules for electing a stack master:

•Valid switch numbers are 1 through 9. The port numbers of the member switches begin with the switch number, such as Fa9/0/1 or G2/0/1, and so forth, depending on whether the ports are FastEthernet or GigabitEthernet. For example, switch 5 has port numbers beginning with Fa5/0/1 or G5/0/1, depending on the type of switch.

•Switch numbering does not reflect the physical location of the stack members.

•Switch numbers are sticky, that is, each switch keeps the same switch number after it reboots as a stack member even if it is no longer in a stack. If necessary, you can renumber a switch using the switch current-stack-member-number renumber new-stack-member-number global configuration command. This command renumbers switch 5 to switch 1, and changes port numbers from Fa5/0/1 (or G5/0/1) to Fa1/0/1 or (G1/0/1):

Switch(config)# switch 5 renumber 1

•The stack master resolves any switch number conflicts, or the two switches involved in the conflict resolve it if a stack master is not yet elected. The renumbered switch reloads.

Member switches wait for the master to report a complete initialization, then this message appears:

Waiting for Master Ready

To identify the stack master:

•Enter the show switch user EXEC command.

•Look at the front panel Master (MSTR) LED. It is solid green only for the switch that is the stack master.

An active switch connected to a fully operational stack becomes a stack member. It receives the running configuration from the stack master. When you disconnect a stack member, the switch numbers and port numbers of the remaining stack members do not change, and the switches do not reload.

Reviewing How the Stack Master is Rebooted or Disconnected

A new stack master is elected when you:

•Power off, disconnect, or reboot the current stack master.

•Power on all switches in a new stack at the same time.

•Reboot all switches after you manually change the stack member priorities by using the CLI.

•Connect a powered-on stack to another powered-on stack merging two separate stacks merge into one.

These rules determine switch priority:

1. You can manually set the switch priority when stack master election or re-election occurs. You can set a priority of 1 to 15; 15 is the highest priority. This command sets switch 1 to priority 15, and it will be the stack master when you reload the stack if no other switches are also set to priority 15:

Stack(config)# switch 1 priority 15

You can then assign a lower priority to the remaining switches in the stack, or they can remain at default. A priority 15 switch overrides these selection decisions:

2. The switch with the highest hardware and software priority is the stack master if you do not set the priority. If all switches have the same hardware and software priority, this procedure occurs:

3. The switch that is not using the default configuration becomes the stack master. The stack manager renumbers and reboots the switches that are using a default configuration (no config.text file in flash memory).

4. The switch with the lowest MAC address.

Stack master and switch priority conflicts are resolved in this order:

1. The switch that is already master remains unchanged.

2. The switch (or stack) whose master has a higher user-configured priority.

3. The switch (or stack) that is not using the default configuration.

4. The switch (or stack) with the more recent license or image version.

5. The switch (or stack) with the higher hardware priority or hardware version.

6. The stack with the most members (if two stacks are being connected).

7. The switch with the lowest MAC addresses.

Understanding Switch Hardware Priority and Stack Manager Version

Stack hardware priority is a number associated with a specific switch model. Two different switch models can have the same hardware priority. Higher priority numbers increase the probability of a switch being elected the stack master.

The hardware priority is sent in Stack Manager messages and has a value between 15 and 0. (When you manually assign the priority, the range is 15 to 1.) For example, a Catalyst 3750-E switch typically has a default hardware priority of 5. The Catalyst 3750 switches typically have a default hardware priority of 2.

Switch hardware priority is different from the switch hardware version. The hardware version number is associated with the switch model. Different switch models can have same hardware version if they support the same system level features. (A higher version number does not always mean more capability.) This number is not used in stack master election.

This example shows the hardware priority and the hardware version:

Stack2# show switch
H/W Current
Switch# Role Mac Address Priority Version State
----------------------------------------------------------
*1 Master 0018.ba60.de00 15 1 Ready

The stack manager version is also called the image version and has major and minor version numbers as shown in this example:


Main problems related to minor version number mismatches:

•The switch cannot join stack.

•The switch joins the stack but has a feature mismatch.

To resolve these problems, install the correct Cisco IOS version in the switch with the mismatch.

In some cases, the minor version is different in member switches, which might result in a version mismatch. With a new Cisco IOS version, the minor version might increase.

This example shows the Cisco IOS version running on each switch in a stack:

Stack# show version
Switch Ports Model SW Version SW Image
------ ----- ----- ---------- ----------
* 1 30 WS-C3750E-24PD 12.2(46)SE C3750E-UNIVERSAL-M
2 30 WS-C3750E-24PD 12.2(46)SE C3750E-UNIVERSAL-M
See the "Resolving Switch Compatibility Issues" section and the "Resolving Version Mismatches and Copying Files" section for more information.

Problem: Stack Ring Is Not Operating at Full Bandwidth

To operate at full bandwidth, a stack requires a closed ring. If only one StackWise cable is connected to the first and last switches in the stack, or if the ring is incomplete, less than full bandwidth is achieved.

These issues can cause an incomplete ring, in order of probability from high to low:

•A bad connection between the StackWise cable connector and a switch chassis connector

•A defective StackWise cable

•A defective StackWise interface on a switch

•A missing StackWise cable in the installation

These issues might cause a bad connection with an otherwise good cable:

•The retainer screws on the connector are loose, which might not be obvious. Loose screws might allow the connector to move and possibly disconnect. The disconnection might appear to be either permanent or intermittent.

•The retainer screws are not evenly tightened, which might cause a constant or an intermittent disconnection.

See the "Fixing Problems with StackWise Interfaces and Cables" section and the "Resolving StackWise Connection Problems" section for more information.

See these sections:

•Resolving Bandwidth Issues (Catalyst 3750 and Catalyst 3750-E Switches)

•Using LEDs to Verify StackWise Link Connections

Resolving Bandwidth Issues (Catalyst 3750 and Catalyst 3750-E Switches)

To troubleshoot problems associated with a stack ring not operating at full bandwidth, you need to know what bandwidth you can expect.

This is the maximum theoretical ring speed (bandwidth) for a Catalyst 3750 switch:

•32 Gb/s with a full or complete StackWise ring

•16 Gb/s with an incomplete or open ring, only one StackWise cable on two switches in the ring

This is the maximum theoretical ring speed (bandwidth) for a Catalyst 3750-E switch:

•64 Gb/s with a full or complete StackWise ring of Catalyst 3750-E switches.

•32 Gb/s with a full or complete StackWise ring, and a mix of Catalyst 3750 and Catalyst 3750-E switches. A Catalyst 3750 in a Catalyst 3750-E stack results in a maximum ring speed of 32 Gb/s.

•16 Gb/s with an incomplete StackWise ring, and a mix of Catalyst 3750 and Catalyst3750-E switches.

To display the active Cisco IOS versions and switch models in a stack, enter the show version user EXEC command:

Stack# show version
Switch Ports Model SW Version SW Image
------ ----- ----- ---------- ----------
* 1 30 WS-C3750E-24PD 12.2(46)SE C3750E-UNIVERSALK9-M
2 28 WS-C3750G-24PS 12.2(46)SE C3750-IPSERVICESK9-M
3 54 WS-C3750E-48TD 12.2(46)SE C3750E-UNIVERSALK9-M
...
output truncated

To display information related to the stack member or the switch stack, enter the show switch user EXEC command:

Stack# show switch
Switch/Stack Mac Address : 0018.ba60.de00
H/W Current
Switch# Role Mac Address Priority Version State
----------------------------------------------------------
*1 Master 0018.ba60.de00 15 1 Ready
2 Member 0016.47f4.e300 14 0 Ready
3 Member 0018.ba60.c700 13 1 Ready

This example shows a mixed stack of Catalyst 3750-E and 3750G switches. All switches have joined the stack, but not all are running the same Cisco IOS version. All switches in a stack should be running the same Cisco IOS version (or equivalent Cisco IOS version in the case of mixed Catalyst 3750-E and 3750 switch stacks).

Enter the show switch stack-ring speed user EXEC command to see the StackWise bandwidth:



Use the show switch detail user EXEC command to see the status of all StackWise interfaces in the stack. The switches in this example are all active stack members, but the ring is incomplete:

A StackWise cable has been added between switch 1, port 1 and switch 3, port 2. All StackWise ports are connected and active, and the ring is complete. Full stack bandwidth is available. This is an excerpt of the output from the show switch detail user EXEC command:


Using LEDs to Verify StackWise Link Connections

You can test StackWise ring bandwidth by using the switch front-panel LEDs:

1. Press the Mode button on a stack member until the Stack mode LED is on.

2. Verify that the LEDs of the last two ports on the right of the switch front panel are green. Depending on the switch model, the last two ports on the right of the front panel are either 10/100/1000 ports or SFP module ports. If one or both LEDs are not green, the stack is not operating at full bandwidth.

Problem: StackWise Port is Flapping

These conditions might cause StackWise port flapping:

•An unreliable or intermittent (bad) connection between a StackWise cable connector and the switch stack port connector

•A defective StackWise cable

•A defective StackWise interface on a switch

When one or more StackWise ports are flapping, the source of the problem is probably an unreliable connection between a StackWise cable and a StackWise switch port.

If you suspect StackWise port flapping, first verify that the retainer screws are adequately tightened and fully seated against the connector shell. Make sure both retainer screws are tightened the same amount. In some cases you need to disconnect and reconnect the cable while you are troubleshooting, but do not test the connection unless the retainer screws are firmly holding the connector.

An unreliable StackWise connection might produce a similar error message:

#
STACKMGR-4-STACK_LINK_CHANGE: Stack Port 1 Switch 1 has changed to state UP
STACKMGR-4-STACK_LINK_CHANGE: Stack Port 1 Switch 1 has changed to state DOWN
STACKMGR-4-STACK_LINK_CHANGE: Stack Port 1 Switch 1 has changed to state UP
STACKMGR-4-STACK_LINK_CHANGE: Stack Port 1 Switch 1 has changed to state DOWN
STACKMGR-4-STACK_LINK_CHANGE: Stack Port 1 Switch 1 has changed to state UP
STACKMGR-4-STACK_LINK_CHANGE: Stack Port 1 Switch 1 has changed to state DOWN

-- or --

#
STACKMGR-4-STACK_LINK_CHANGE: Stack Port 1 Switch 4 has changed to state UP
STACKMGR-4-STACK_LINK_CHANGE: Stack Port 2 Switch 5 has changed to state UP
STACKMGR-4-STACK_LINK_CHANGE: Stack Port 1 Switch 4 has changed to state DOWN
STACKMGR-4-STACK_LINK_CHANGE: Stack Port 2 Switch 5 has changed to state DOWN
STACKMGR-4-STACK_LINK_CHANGE: Stack Port 1 Switch 4 has changed to state UP
STACKMGR-4-STACK_LINK_CHANGE: Stack Port 1 Switch 4 has changed to state DOWN
SUPQ-4-CPUHB_RECV_STARVE: Still seeing receive queue stuck after throttling
STACKMGR-4-STACK_LINK_CHANGE: Stack Port 2 Switch 5 has changed to state UP
STACKMGR-4-STACK_LINK_CHANGE: Stack Port 2 Switch 5 has changed to state DOWN

An unreliable cable connection caused both of these patterns. Neither the StackWise cable nor the StackWise port was defective. A bad connection between the StackWise cable and the stack connector on the switch caused the problem.

A problem at either end of a StackWise link might cause port flapping at the other end of the link.

See the "Fixing Problems with StackWise Interfaces and Cables" section and "Resolving StackWise Connection Problems" section.

Resolving Version Mismatches and Copying Files

The remote file system runs on the stack master. You can use it to:

•Access file systems and copy files from one switch to another in the stack.

•Use the archive download-sw privileged EXEC command to simultaneously update the Cisco IOS image in all switches.

Review these points about stack administration and Cisco IOS upgrades:

•You can access the CLI from any switch console port in the stack, but all commands are sent to the stack master. This feature is sometimes called a unified console.

•The stack master processes the CLI commands for all switches in the stack.

•All output to the console from any switch in the stack is redirected to the stack master console.

When version mismatches occur on a member switch, you can review the contents of flash memory in the mismatched switch. This command shows the contents of flash memory for switch 3 in the stack:

Switch# dir flash3:

If you previously upgraded the switch with the archive download-sw privileged EXEC command, the Cisco IOS file is in a subdirectory in flash memory. You can display the contents by using this command:

Switch# dir flash3:/c3750e-universal-mz.122-25.SE

An automatic upgrade can occur in most cases when a Cisco IOS version that is running on the stack master is not the same as the Cisco IOS version on the switch in mismatched mode. The automatic upgrade requires the Cisco IOS tar file of the current image to be available to any of the stack members. The tar file is stored in the flash memory on one of the switches in the stack, preferably the stack master.

If the tar file of the current image is not available, we recommend that you download a compatible image by using the appropriate commands and TFTP.

The automatic upgrade and auto-advise features do not work if the stack master and the switch in mismatched mode run different feature sets (IP Services and IP Base, for example). Starting with Cisco IOS Release 12.2(35)SE, automatic upgrade supports upgrades between cryptographic and noncryptographic images of the same feature set.

If automatic upgrade is not functional, you can manually copy a Cisco IOS file from one switch to another by using this command:

Stack# copy flash1:c3750e-universal-mz.122-35.SE1.bin flash3:

This example copies the Cisco IOS file from flash memory in switch 1 to the flash memory in switch 3. If the bin file is in a subdirectory, this is the appropriate command:

Stack# copy flash1:/c3750e-universal-mz.122-35.SE1/c3750e-universal-mz.122-35.SE1.bin
flash3:

After you copy the new Cisco IOS file to the switch that is in version mismatch mode, you can delete the mismatched Cisco IOS file. Use this command to delete the unneeded subdirectory from switch 3 flash memory:

Stack# remote command 3 delete /recursive /force flash:/c3750e-universal-mz.122-25.SE

Next, reboot the upgraded switch to load and run the compatible Cisco IOS version:

Stack# reload slot 3

After the switch reloads and loads the compatible Cisco IOS version, it joins the stack.

Upgrading Catalyst 3750 and Catalyst 3750-E Switch Stacks

This section includes some useful options for upgrading switch stacks. See the software configuration guide for routine software upgrade procedures for switches in a stack.

When both a Catalyst 3750-E switch and a Catalyst 3750 switch are in the same mixed stack, you can simultaneously upgrade both by using this command syntax:

stack# archive download-sw tftp://server/3750E.tar tftp://server/3750.tar

This might be a typical command string:

stack# archive download-sw tftp://192.168.1.1/3750E.tar tftp://192.168.1.1/3750.tar

You might have to specify the TFTP path if you do not copy the Cisco IOS file from the default TFTP directory on the TFTP server:

stack# archive download-sw tftp://server/path/3750E.tar tftp://server/path/3750.tar

If you do not need the HTML files, you can use the command option archive download-sw /image to install only the bin file to the flash memory in the Cisco IOS directory of each stack member. By eliminating the HTML files, the Catalyst 3750 switch uses less flash memory, and installation time is faster. Cases might occur where insufficient space is available in the flash memory to extract and install a complete tar file, Use the command option archive download-sw /image to save flash memory by installing only the IOS bin file in flash memory:

stack# archive download-sw /image tftp:// ...

This command might be useful when you upgrade from older Cisco IOS versions in a mixed stack:

stack# archive download-sw /allow-feature-upgrade tftp:// . . .

This is a typical combination:

stack# archive download-sw /image /allow tftp:// . . .

You can also copy a Cisco IOS bin file to any specific switch in the stack, and then reload that switch. This example shows upgrading switch #2 in the stack:

Switch-1# copy tftp flash2:
Address or name of remote host [ ]? ip address
Source filename [ ]? /path/filename
Switch# config t
Switch(config)# boot system switch 2 filename
Switch(config)# end
switch# reload slot 2
Proceed with reload? [confirm]

If the bin file is in a directory path in flash memory, use this command:

Switch(config)# boot system switch 2 directory/filename.bin

Always use the archive download-sw command to upgrade Cisco IOS in any switch because using that command automatically sets the correct boot variable. As an alternative when necessary, you can copy a Cisco IOS bin file to any specific switch in the stack and then reload that switch.

When you copy a bin file to flash memory, the boot variable is not set. Upgrading a switch by using the archive download-sw /image command sets the correct filename in the boot variable.

aprile 04, 2012

Cisco Networking: Configuring ISL Trunking on Catalyst 5500/5000 and 6500/6000 Family Switches

Introduction

This document illustrates how to create a switch-to-switch Inter-Switch Link (ISL) trunk. Trunk ports enable connections between switches to carry traffic from more than one VLAN. If trunking is not enabled, the link that connects the two switches only carries traffic from the VLAN that you have configured on the port. Trunking is not necessary in very simple switched networks with only one VLAN (broadcast domain). In most LANs, a small portion of traffic consists of special protocols that manage the network. (A few examples are Cisco Discovery Protocol [CDP], VLAN Trunk Protocol [VTP], Dynamic Trunking Protocol [DTP], Spanning Tree Protocol [STP], and Port Aggregation Protocol [PAgP].) You also use the management VLAN when you ping or establish a Telnet directly to or from the switch. (If you use Catalyst OS [CatOS], you define the VLAN and the IP address of the switch when you configure the sc0 interface. The Step-by-Step Instructions for CatOS section of this document explains this process.) In a multi-VLAN environment, many network administrators advocate the restriction of this management traffic to a single VLAN. The VLAN is normally VLAN 1. The administrators then configure user traffic to flow in VLANs other than this default VLAN. ISL (Cisco proprietary) is one of two possible trunking protocols for Ethernet. The other protocol is the IEEE 802.1Q standard.

This document covers the procedure to configure ISL trunking between Catalyst 5500/5000 and Catalyst 6500/6000 series switches. The CatOS configuration applies to both Catalyst 5500/5000 and 6500/6000 series switches. However, you can only apply the Cisco IOS® Software configuration to a Catalyst 6500/6000 series switch.

Prerequisites

Requirements

There are no specific prerequisites for this document.

Components Used

The information in this document is based on these software and hardware versions:

  • at least one terminal.

  • at least one console cable that is suitable for the Supervisor Engine in your switches. (Refer to the document Connecting a Terminal to the Console Port on Catalyst Switches for more information.)

  • two Catalyst 5500/5000 or Catalyst 6500/6000 switches (that run CatOS) or two Catalyst 6500/6000 switches (that run Cisco IOS Software) in a lab1 environment with cleared configurations2.

  • two Ethernet interfaces that are able to support ISL.

  • one 10BASE-T crossover cable.

1The information in this document was created from the devices in a specific lab environment. All of the devices used in this document started with a cleared (default) configuration. If your network is live, make sure that you understand the potential impact of any command.

2 For CatOS, the issue of the clear config all command ensured that there was a default configuration. For Cisco IOS Software, the write erase command cleared the configuration.

Conventions

For more information on document conventions, refer to the Cisco Technical Tips Conventions.

Creation of a Switch-to-Switch ISL Trunk

Switches A and B in this topology represent either two Catalyst 5500/5000 switches that run CatOS or two Catalyst 6500/6000 switches that run Cisco IOS Software.

2-a.gif

Switches A and B, by default, have the 2/1 ports in VLAN 1. This configuration allows traffic from other ports in VLAN 1 to flow between the switches without the need to configure trunking. References to "the management VLAN" apply to VLAN 1.

Note: VLAN 1 is the default VLAN for all types of Ethernet interfaces, as well as FDDI. VLAN 1 is also the default VLAN for the management interface (sc0).

In the example that follows, you have configured ports 2/2 on both switches in VLAN 2. Traffic from devices that you have attached to the ports in VLAN 2 do not cross over the link between the switches. Therefore, PCs A and B are not able to communicate.

2-b.gif

The solution is to enable ISL trunking on the link between switches A and B. Trunking adds a VLAN header to each frame during transmit (multiplex) onto a trunk link. This addition allows the switch at the other end of the link to demultiplex the frames; the switch then forwards the frames to the appropriate VLAN ports.

2-c.gif

Tasks

These steps guide you through this configuration:

  1. Connect a terminal to the switches.

  2. Verify ISL support on the ports.

  3. Connect the switches.

  4. Verify that the ports are operational.

  5. Assign IP addresses to the management ports.

  6. Verify that the switches are not trunking over the link.

  7. Ping from switch to switch.

  8. Create a VLAN 2 in each switch.

  9. Move the management interface (sc0) to VLAN 2 (for CatOS).

  10. Verify that you cannot ping from switch to switch.

  11. Configure the same VTP domain name in each switch.

  12. Enable trunking between the switches.

  13. Verify that the switches are trunking over the link.

  14. Ping from switch to switch.

Step-by-Step Instructions for CatOS

Follow these steps:

  1. Connect a terminal to the console ports of the switches.

    For more information, refer to this document:

  2. Make certain that the ports that you have decided to use support ISL trunking.

    There are several types of Ethernet interfaces that support ISL trunking. The 10BASE-T (common Ethernet) ports do not support trunking, while most 100BASE-T (Fast Ethernet) ports do support trunking.

    Issue the show port capabilities module_number | module_number/port_number command on both switches to determine if the ports you use support ISL.

    Note: In this example, the command specifies the port designator 2/1. This limits the response to the information that is directly applicable.

    cat5000> (enable) show port capabilities 2/1 
    Model                    WS-X5234 
    Port                     2/1 
    Type                     10/100BaseTX 
    Speed                    auto,10,100 
    Duplex                   half,full 
    Trunk encap type         802.1Q,ISL 
    Trunk mode               on,off,desirable,auto,nonegotiate 
    Channel                  2/1-2,2/1-4 
    Broadcast suppression    percentage(0-100) 
    Flow control             receive-(off,on),send-(off,on) 
    Security                 yes 
    Membership               static,dynamic 
    Fast start               yes 
    QOS scheduling           rx-(none),TX(1q4t) 
    COs rewrite              yes 
    ToS rewrite              IP-Precedence 
    Rewrite                  yes 
    UDLD                     yes 
    AuxiliaryVlan            1..1000,1025..4094,untagged,dot1p,none 
    SPAN                     source,destination
  3. Connect the two switch ports together with the Ethernet crossover cable.

    In this example, the Switch A 2/1 port connects to the Switch B 2/1 port.

  4. To verify that the ports are operational, issue the show port 2/1 command on Switch A.

    Switch-A> (enable) show port 2/1 
    Port  Name               Status     VLAN       Level  Duplex Speed Type  
    ----- ------------------ ---------- ---------- ------ ------ ----- ------------  
    2/1                      connected  1          normal a-full a-100 10/100BaseTX   
    Switch-A> (enable)
  5. Issue the set interface sc0 172.16.84.17 255.255.255.0 172.16.84.255 command on Switch A and the set interface sc0 172.16.84.18 255.255.255.0 172.16.84.255 command on Switch B.

    These commands assign IP addresses from the same subnet to the management ports on both switches. You may also need to specify in the command the VLAN for sc0 (the management VLAN). Include this VLAN if the VLAN is different than the default (VLAN 1).

    Switch-A> (enable) set interface sc0 172.16.84.17 255.255.255.0 172.16.84.255 
    Interface sc0 IP address, netmask, and broadcast set. 
    Switch-A> (enable) 

    If you have the output of a show interfaces command from your Cisco device, you can use the Output Interpreter Tool (registered customers only) to display potential issues and fixes.

  6. To verify that the link between switches A and B is not trunking, issue the show trunk 2/1 command on Switch A.

    Switch-A> (enable) show trunk 2/1 
    Port      Mode         Encapsulation  Status        Native VLAN 
    --------  -----------  -------------  ------------  ----------- 
    2/1      auto         isl            not-trunking 1  
    Port      VLANs allowed on trunk
    --------  --------------------------------------------------------------------- 
    2/1      1-1005  Port      VLANs allowed and active in management domain 
    --------  --------------------------------------------------------------------- 
    2/1      1  Port      VLANs in spanning tree forwarding state and not pruned
    --------  --------------------------------------------------------------------- 
    2/1      1 
    Switch-A> (enable)

    Note: The term Native VLAN in this output indicates the VLAN placement of this port when the port is not in trunking mode. If you have configured the port for 802.1Q trunking, the Native VLAN field also indicates the VLAN for which the frames have no tags; all others have tags. (Conversely, with ISL trunking, every data frame has the appropriate VLAN identifier.)

    The trunking status should be not-trunking because the default mode for the DTP is auto. DTP is the strategic replacement for Dynamic ISL (DISL) because DTP incorporates support for 802.1Q trunking negotiation. DTP is available in Catalyst software version 4.x and later, as well as in certain hardware modules. There are five different modes to which you can configure DTP. Cisco Technical Support recommends the configuration of desirable trunking mode on the ports of the trunk link. Step 12 discusses this information in more detail.

  7. Ping Switch B from Switch A to verify that the switches can communicate over the link.

    Switch-A> ping 172.16.84.18 172.16.84.18 is alive Switch-A>
  8. To create VLAN 2 in Switch A, issue the set vlan 2 command on Switch A.

    Switch B learns about VLAN 2 after the establishment of the VTP domain in Step 11.

    Switch-A> (enable) set vlan 2 Vlan 2 configuration successful Switch-A> (enable)
  9. Move the management interface in switches A and B to VLAN 2, which you created in Step 8.

    To change the interface, issue the set interface sc0 2 command. This output shows the issue of the command on Switch A:

    Switch-A> (enable) set interface sc0 2 Interface sc0 vlan set. Switch-A> (enable)

    Issue the show interfaces command to view the change you just made. This output shows the issue of the command on Switch A. The output shows the new association of interface sc0 and VLAN 2:

    Switch-A> (enable) show interfaces sl0: flags=51 slip 0.0.0.0 dest 0.0.0.0 sc0: flags=63 vlan 2 inet 172.16.84.17 netmask 255.255.255.0 broadcast 172.16.84.255 Switch-A> (enable) 
  10. Attempt to ping Switch B from Switch A.

    The ping should fail because the management ports are now in VLAN 2 while the link between the switches is in VLAN 1.

    Switch-A> (enable) ping 172.16.84.18 no answer from 172.16.84.18 Switch-A> (enable)
  11. Establish the same VTP domain for both switches.

    Issue the set vtp domain Cookbook command on both switches.

    Note: The name of the VTP domain is Cookbook.

    Switch-A> (enable) set vtp domain Cookbook VTP domain Cookbook modified Switch-A> (enable)

    If you have the output of a show vtp domain command from your Cisco device, you can use the Output Interpreter Tool (registered customers only) to display potential issues and fixes.

  12. Turn on trunking between the switches.

    To configure port 2/1 on Switch A for desirable mode, issue the set trunk 2/1 desirable isl command on Switch A. Switch B is in auto mode. Switch B automatically places the port 2/1 in trunking mode after completion of the DTP negotiation between the two switches.

    Note: Cisco Technical Support recommends the configuration of desirable trunking mode on the ports of the trunk link.

    Switch-A> (enable) set trunk 2/1 desirable isl Port(s) 2/1 trunk mode set to desirable. Port(s) 2/1 trunk type set to Isl. Switch-A> (enable)

    If you have the output of a show trunk command from your Cisco device, you can use the Output Interpreter Tool (registered customers only) to display potential issues and fixes.

    This list describes the five different states for which you can configure DTP:

    • auto: The port listens for DTP frames from the neighbor switch. If the neighbor switch indicates that the switch would like to be a trunk, or that the switch is a trunk, auto state creates the trunk with the neighbor switch. The auto state does not propagate any intent to become a trunk; auto state is solely dependent on the neighbor switch to make the trunking decision.

    • desirable: DTP is spoken to the neighbor switch to which you want to establish an ISL trunk. The switch with desirable configuration communicates that the switch is able to be an ISL trunk and wants the neighbor switch to also be an ISL trunk. Cisco Technical Supportrecommends the configuration of desirable trunking mode on the ports of the trunk link.

    • on: DTP is spoken to the neighbor switch. The on state automatically enables ISL trunking on the port, regardless of the state of the neighbor switch. The port remains an ISL trunk unless the port receives an ISL packet that explicitly disables the ISL trunk.

    • nonegotiate: DTP is not spoken to the neighbor switch. The nonegotiate state automatically enables ISL trunking on the port, regardless of the state of the neighbor switch.

    • off: There can be no use of ISL on this port, regardless of the configuration of DTP mode on the other switch port.

    This table shows the 15 possible, unique combinations of DTP modes. The table also shows whether the combinations result in an active bidirectional trunk. While theoretically you can trunk in one direction on a link and not in the other direction, you should not perform this kind of trunking.

    Switch A Port/Interface 2/1

    Switch B Port/Interface 2/1

    ISL Trunk Status

    DTP mode auto

    DTP mode auto

    not-trunking

    DTP mode desirable

    DTP mode auto

    trunking

    DTP mode on

    DTP mode auto

    trunking

    DTP mode nonegotiate

    DTP mode auto

    not-trunking

    DTP mode off

    DTP mode auto

    not-trunking

    DTP mode desirable (Cisco Technical Support recommended configuration)

    DTP mode desirable (Cisco Technical Support recommended configuration)

    trunking

    DTP mode on

    DTP mode desirable

    trunking

    DTP mode nonegotiate

    DTP mode desirable

    not-trunking

    DTP mode off

    DTP mode desirable

    not-trunking

    DTP mode on

    DTP mode on

    trunking

    DTP mode nonegotiate

    DTP mode on

    trunking

    DTP mode off

    DTP mode on

    not-trunking

    DTP mode nonegotiate

    DTP mode nonegotiate

    trunking

    DTP mode off

    DTP mode nonegotiate

    not-trunking

    DTP mode off

    DTP mode off

    not-trunking

    You may see other messages that relate to changes to the state of STP on the switch. These messages are not relevant to this document. Refer to the document Understanding and Configuring Spanning Tree Protocol (STP) on Catalyst Switches for more information on this protocol. Because you cleared the configurations in the switches to start, you have the defaults for the STP parameters. The default parameters of STP should provide the connectivity necessary for this document to succeed.

  13. To verify the trunk link, issue the show trunk 2/1 command at the prompt on Switch A.

    Switch-A> (enable) show trunk 2/1 Port      Mode         Encapsulation  Status        Native VLAN --------  -----------  -------------  ------------  ----------- 2/1      desirable    isl            trunking      1  Port      VLANs allowed on trunk --------  --------------------------------------------------------------------- 2/1      2,1002-1005  Port      VLANs allowed and active in management domain  --------  --------------------------------------------------------------------- 2/1      2,1002-1005  Port      VLANs in spanning tree forwarding state and not pruned --------  --------------------------------------------------------------------- 2/1      2,1002-1005 Switch-A> (enable)

    You should now see that trunking is operational.

    Note: VLANs 1–1005 are allowable on all trunk ports by default. You can clear VLAN 1 from the list of allowable VLANs. If you remove VLAN 1 from a trunk, the trunk interface continues to send and receive management traffic, for example, CDP, VTP, PAgP, and DTP in VLAN 1. You cannot remove VLANs 1002–1005. In CatOS versions earlier than 5.4(x), you cannot remove VLAN 1 from the trunk.

    To limit the VLANs on a trunk in CatOS, clear them. Issue the clear trunk 2/1 1-1001 command. To establish the allowable VLANs on the trunk, issue the set trunk 2/1 2 command on Switch A.

    Switch-A>(enable) clear trunk 2/1 1-1001 Removing Vlan(s) 1-1001 from allowed list. Port 2/1 allowed vlans modified to 4. Switch-A> (enable)  Switch-A>(enable) set trunk 2/1 2   Adding vlans 2 to allowed list. Port(s) 2/1 allowed vlans modified to 5. Switch-A>(enable)  

    In this output, notice the permission of only VLANs 1 and 2 on this trunk link now:

    Switch-A> (enable) show trunk 2/1 Port      Mode         Encapsulation  Status        Native VLAN --------  -----------  -------------  ------------  ----------- 2/1      desirable    isl            trunking     1  Port      VLANs allowed on trunk --------  --------------------------------------------------------------------- 2/1      1-1005  Port      VLANs allowed and active in management domain  --------  --------------------------------------------------------------------- 2/1      1-2  Port      VLANs in spanning tree forwarding state and not pruned --------  --------------------------------------------------------------------- 2/1      1-2 Switch-A> (enable) 
  14. Ping Switch B from Switch A to verify that the switches can communicate with each other over the trunk link.

    Switch-A> ping 172.16.84.18 172.16.84.18 is alive Switch-A>

Troubleshoot the Result

Commands to Use to Troubleshoot CatOS

  • show port capabilities mod/port —To see the physical status of a port and the port capabilities.

  • show trunk mod/port —To see the trunking information for a particular port.

  • show vtp domain—To display VTP information.

  • show vlan vlan_number —To see information on a particular VLAN.

  • show spantree vlan_number —To see the status of the spanning tree for a particular VLAN.

  • show interfaces—To display the configuration of sc0 and sl0.

  • ping—To send an Internet Control Message Protocol (ICMP) echo message to another IP host.

Note: In switches with several interfaces and VLANs, include the module/port or VLAN number with the show command to restrict the command output. Use of the ? argument with show commands displays which commands allow use of the mod/port argument. For example, the show trunk ? command indicates that show trunk mod/port is allowable.

Step-by-Step Instructions for Cisco IOS Software

Follow these steps:

  1. Connect a terminal to the console ports of the switches.

    For more information, refer to this document:

  2. Make certain that the ports that you have decided to use support ISL trunking.

    There is currently no command available to view the module or port capabilities in Cisco IOS Software. All 10/100BASE-T, 1000BASE-TX, 100BASE-FX, and 1000BASE-SX/LX/ZX-type Ethernet modules for the Catalyst 6500/6000 series switches support ISL trunking.

    Note: The 10-Gigabit Ethernet switching module (WS-X6501-10GEX4) does not support ISL encapsulation.

  3. Connect the two switch ports together with the Ethernet crossover cable.

    In this example, the Switch A 2/1 port connects to the Switch B 2/1 port.

  4. To verify that the ports are operational, issue the show interfaces fastethernet 2/1 status command.

    The command displays this information:

    Switch-A# show interfaces fastethernet 2/1 status  Port    Name               Status       VLAN       Duplex  Speed Type Fa2/1                      connected     1          a-full  a-100 10/100BaseTX Switch-A#
  5. Configure a VLAN interface on both switches A and B.

    In the global configuration mode, issue the command interface vlan 1. When you configure the IP address, issue the command ip address 172.16.84.17 255.255.255.0 on Switch A and ip address 172.16.84.17 255.255.255.0 on Switch B. To configure the switchport 2/1 as a Layer 2 (L2) interface and a member of VLAN 1, issue the commands interface fastethernet 3/1, switchport, and switchport access vlan 1. For more information on the configuration of L2 interfaces in Cisco IOS Software, refer to this document:

    Switch-A(config)# interface vlan 1 Switch-A(config-if)# ip address 172.16.84.17 255.255.255.0 Switch-A(config-if)#  Switch-A(config)# interface fastethernet 2/1 Switch-A(config-if)# switchport Switch-A(config-if)# switchport access vlan 1 Switch-A(config-if)# 
  6. To verify that the link between switches A and B is not trunking, issue the command show interfaces fastethernet 2/1 trunk.

    Switch-A# show interfaces fastethernet 2/1 trunk  Port      Mode         Encapsulation  Status        Native VLAN Fa2/1     desirable    negotiate      not-trunking  1  Port      VLANs allowed on trunk Fa2/1     none  Port      VLANs allowed and active in management domain Fa2/1     none  Port      VLANs in spanning tree forwarding state and not pruned Fa2/1     none Switch-A#  

    Note: The term Native VLAN in this output indicates the VLAN placement of this port when the port is not in trunking mode. If you have configured the port for 802.1Q trunking, the Native VLAN field also indicates the VLAN for which the frames have no tags; all others have tags. (Conversely, with ISL trunking, every data frame has the appropriate VLAN identifier.)

  7. Ping Switch B from Switch A to verify that the switches can communicate over the link.

    Switch-A> ping 66.123.210.122 Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 172.16.84.18, timeout is 2 seconds: !!!!! Success rate is 100 percent (5/5), round-trip min/avg/max = 4/21/92 ms Switch-A>
  8. To create VLAN 2 in Switch A, issue the vlan database command and the vlan 2 command on Switch A.

    Switch B learns about VLAN 2 after the establishment of the VTP domain in Step 11. For more information on the configuration of VLANs in Cisco IOS Software code, refer to this document:

    • Configuring VLANs

      Switch-A# vlan database Switch-A(vlan)# vlan 2 VLAN 2 added: Name: VLAN0002 Switch-A(vlan)#exit APPLY completed. Exiting.... Switch-A#
  9. Move the management interface on switches A and B to VLAN 2, which you created in Step 8.

    In Cisco IOS Software mode, there is no sc0 management interface. Therefore, configure the ports, which connect to host A on Switch A and host B on Switch B, to VLAN 2. Issue the commands switchport and switchport access vlan 2. Then, use the hosts to perform the ping tests. For this example, configure IP addresses 172.16.85.1/24 on host A and 172.16.85.2/24 on host B.

    Switch-A(config)# interface fastethernet 2/2 Switch-A(config-if)# switchport Switch-A(config-if)# switchport access vlan 2 

    Issue the show interfaces command to view the change you just made. This output shows the issue of the command on Switch A. The output shows the new association of interface 2/2 and VLAN 2:

    Switch-A# show interfaces fastethernet 2/2  switchport Name: Fa2/2 Switchport: Enabled Administrative Mode: dynamic desirable Operational Mode: up Administrative Trunking Encapsulation: negotiate Negotiation of Trunking: On Access Mode VLAN: 2 (VLAN0002) Switch-A# show interfaces fastethernet 2/2  switchport Name: Fa2/2 Switchport: Enabled Administrative Mode: dynamic desirable Operational Mode: up Administrative Trunking Encapsulation: negotiate Negotiation of Trunking: On Access Mode VLAN: 2 (VLAN0002)  !--- Output suppressed.  
  10. Attempt to ping the host that connects to the alternate switch.

    The ping should fail because the ports are now in VLAN 2 while the link between the switches is in VLAN 1.

    C:\> ping 172.16.85.1 Pinging 172.16.85.1 with 32 bytes of data:  Request timed out. Request timed out. Request timed out. Request timed out.  Ping statistics for 172.16.85.1: Packets: Sent = 4, Received = 0, Lost = 4 (100% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms  C:\>
  11. Establish the same VTP domain for both switches.

    Issue the vtp domain Cookbook command in global configuration mode.

    Note: The name of the VTP domain is Cookbook.

    For more information on the configuration of VTP parameters with Cisco IOS Software, refer to this document:

    • Configuring VTP

      Switch-A(config)# vtp domain Cookbook Changing VTP domain name from NULL to cookbook Switch-A(config)#  
  12. Turn on trunking between the switches.

    Configure port 2/1 on Switch A for desirable mode. To configure the encapsulation type and the mode, issue the switchport trunk encapsulation isl command and the switchport mode dynamic desirable command. Switch B is in auto mode. Switch B automatically places the port 2/1 in trunking mode after completion of the DTP negotiation between the two switches.

    Note: Cisco Technical Support recommends the configuration of desirable trunking mode on the ports of the trunk link.

    Switch-A(config)# interface fastethernet 2/1 Switch-A(config-if)# switchport trunk encapsulation isl Switch-A(config-if)# switchport mode dynamic desirable 

    This list describes the five different states for which you can configure DTP:

    • auto: The port listens for DTP frames from the neighbor switch. If the neighbor switch indicates that the switch would like to be a trunk, or that the switch is a trunk, auto state creates the trunk with the neighbor switch. The auto state does not propagate any intent to become a trunk; auto state is solely dependent on the neighbor switch to make the trunking decision.

    • desirable: DTP is spoken to the neighbor switch to which you want to establish an ISL trunk. The switch with desirable configuration communicates that the switch is able to be an ISL trunk and wants the neighbor switch to also be an ISL trunk.

    • on: DTP is spoken to the neighbor switch. The on state automatically enables ISL trunking on the port, regardless of the state of the neighbor switch. The port remains an ISL trunk unless the port receives an ISL packet that explicitly disables the ISL trunk. Cisco Technical Support recommends the configuration of desirable trunking mode on the ports.

    • nonegotiate: DTP is not spoken to the neighbor switch. The nonegotiate state automatically enables ISL trunking on the port, regardless of the state of the neighbor switch.

    • off: There can be no use of ISL on this port, regardless of the configuration of DTP mode on the other switch port.

    This table shows the 15 possible, unique combinations of DTP modes. The table also shows whether the combinations result in an active bidirectional trunk. While theoretically you can trunk in one direction on a link and not in the other direction, you should not perform this kind of trunking.

    Switch A Port/Interface 2/1

    Switch B Port/Interface 2/1

    ISL Trunk Status

    DTP mode auto

    DTP mode auto

    not-trunking

    DTP mode desirable

    DTP mode auto

    trunking

    DTP mode on

    DTP mode auto

    trunking

    DTP mode nonegotiate

    DTP mode auto

    not-trunking

    DTP mode off

    DTP mode auto

    not-trunking

    DTP mode desirable (Cisco Technical Support recommended configuration)

    DTP mode desirable (Cisco Technical Support recommended configuration)

    trunking

    DTP mode on

    DTP mode desirable

    trunking

    DTP mode nonegotiate

    DTP mode desirable

    not-trunking

    DTP mode off

    DTP mode desirable

    not-trunking

    DTP mode on

    DTP mode on

    trunking

    DTP mode nonegotiate

    DTP mode on

    trunking

    DTP mode off

    DTP mode on

    not-trunking

    DTP mode nonegotiate

    trunking

    trunking

    DTP mode off

    DTP mode nonegotiate

    not-trunking

    DTP mode off

    DTP mode off

    not-trunking

    You may see other messages that relate to changes to the state of STP on the switch. These messages are not relevant to this document. Refer to the document Understanding and Configuring Spanning Tree Protocol (STP) on Catalyst Switches for more information on this protocol. Because you cleared the configurations in the switches to start, you have the defaults for the STP parameters. The default parameters of STP should provide the connectivity necessary for this document to succeed.

  13. To verify the trunk, issue the show interfaces fastethernet 2/1 trunk command.

    Switch-A# show interfaces fastethernet 2/1 trunk   Port      Mode         Encapsulation  Status        Native VLAN Fa2/1     desirable    isl            trunking      1  Port      VLANs allowed on trunk Fa2/1     1-1005  Port      VLANs allowed and active in management domain Fa2/1     1-2,1002-1005  Port      VLANs in spanning tree forwarding state and not pruned Fa2/1     1-2,1002-1005  

    You should now see that trunking is operational.

    Note: VLANs 1–1005 are allowable on all trunk ports by default. You can clear VLAN 1 from the list of allowable VLANs. If you remove VLAN 1 from a trunk, the trunk interface continues to send and receive management traffic, for example, CDP, VTP, PAgP, and DTP in VLAN 1.

    To limit or remove VLANs on a trunk, issue the switchport trunk allowed vlan remove 1-1001 command in interface configuration mode. The command removes all removable VLANs from the trunk. Issue the switchport trunk allowed vlan add 2 command to add VLAN 2 to the list of allowable VLANs on the trunk.

    Switch-A(config-if)# switchport trunk allowed vlan remove 1-1001 Switch-A(config-if)#  Switch-A(config-if)# switchport trunk allowed vlan add 2 Switch-A(config-if)#  

    In this output, notice the permission of only VLANs 2 and 1002–1005 on the trunk:

    Switch-A# show interfaces fastethernet 2/1 trunk  Port      Mode         Encapsulation  Status        Native VLAN Fa2/1     desirable    isl            2,1002-1005      1  Port      VLANs allowed on trunk Fa2/1     2,1002-1005  Port      VLANs allowed and active in management domain Fa2/1     2,1002-1005  Port      VLANs in spanning tree forwarding state and not pruned Fa2/1     2,1002-1005
  14. To verify that the trunk link is operational, attempt to ping across the trunk link.

    Ping host A from host B to verify connectivity over VLAN 2.

    C:\> ping 172.16.85.1  Pinging 172.16.85.1 with 32 bytes of data:  Reply from 172.16.85.1: bytes=32 time<10ms TTL=255 Reply from 172.16.85.1: bytes=32 time<10ms TTL=255 Reply from 172.16.85.1: bytes=32 time<10ms TTL=255 Reply from 172.16.85.1: bytes=32 time<10ms TTL=255  Ping statistics for 172.16.85.1:     Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milliseconds:     Minimum = 0ms, Maximum =  0ms, Average =  0ms  C:\>

Troubleshoot the Result

Commands to Use to Troubleshoot Cisco IOS Software

  • show interfaces fastethernet port/mod trunk—To see the trunking information for a particular interface.

  • show vtp status—To display VTP information.

  • show vlan vlan_number —To see information on a particular VLAN.

  • show spanning-tree vlan vlan_number —To see the status of the spanning tree for a particular VLAN.

  • show interfaces fastethernet port/mod switchport —To see L2 interface information.

  • ping —To send an ICMP echo message to another IP host.