Pages

Friday, April 15, 2011

MPLS technology: Overview and Configuration guide

Understanding MPLS: MPLS Architecture:

To understand exactly how MPLS works you must understand how the control plane(tables that govern forwarding) and data plane(data or the packet) compliment each other during the forwarding process in a Label Switch Router. This process is slightly different depending if you are on a PE or P device. Below is a graphic to help illustrate those slight differences.
 



Basic Configuration of an MPLS network:

The configuration of a basic MPLS network is actually very simple and only requires a few basic
steps. The requirements of such a network are the following:
1. Enable CEF: CEF(Cisco Express Forwarding) is essentially what allows the imposition and disposition of labels in an MPLS network. You must make sure it is enabled globally, as well as on the specific interfaces
participating in the MPLS network. How to enable CEF globally and on interfaces will be shown
later. When possible enable CEF in distributed mode, which is largely platform dependent.
Unfortunately it does not to pertain to the platforms used in this lab.
2. Configure IGP routing protocol: Interior Gateway Protocols are routing protocols such as
RIP, IGRP, EIGRP, and OSPF. In this case OSPF was used on all the routers. IGP routing protocols are needed to populate the routing tables, which CEF operation takes over and label binding ensues.
3. (Optional) Define Label Distribution Protocol: LDP by default is the label distribution
protocol. The only other option is TDP, which in the real world is a overwhelming minority, if used
at all.
The command to manually do this is:
router(config)#mpls label protocol {ldp|tdp}
4. (Optional) Assign LDP Router ID: LDP uses the highest IP address on a loopback interface.
A loopback interface is a logical interface as opposed to an actual physical interface such as
interface gigabit 0/1 of a router. Loopback interfaces are often used as management IP’s for
telnet sessions, monitoring, or other forms of maintenance or management. If there is no
loopback interface defined, the highest IP address on the router becomes the LDP router ID.
To force an interface to be an LDP router interface simply type the command:
router(config)#mpls ldp router -id [interface type] [number] for example,
router(config)#mpls ldp router-id gigabit 0/1
The LDP router ID is important in setting up sessions between MPLS routers to exchange label
information.
5. Configure MPLS or Label Forwarding on the Interface: This part of the configuration tells
the specific interfaces that they are participating in MPLS or Label Forwarding. The commands to
configure this will be shown later.
 
Configuration of the MPLS Devices:

1. Enable CEF Globally on the router:
router(config)#ip cef
1B. Enable CEF on the MPLS participating interfaces:
router(config-f)#ip route-cache cef
2. Configure an IGP protocol on the Router:
router(config)#router ospf 1
router(config-router)#network 10.1.4.0 255.255.255.0 area 0
* The network statements are the networks the loopback interfaces are configured for. Directly
connected networks are automatically known, loopback interface network addresses are not.
3. Define Label Distribution Protocol:
router(config)#mpls label protocol ldp
4. Assign LDP router ID:
*Loopback interface's ip addresses are used by default, this step was not completed.*
5. Configure MPLS Label Forwarding on the interface:
router(config)#interface GigabitEthernet 0/0
router(config-if)#mpls ip
router(config)#interface GigabitEthernet 0/1
router(config-if)#mpls ip
This concludes all the necessary commands needed for basic MPLS operation.

want more details then go to the following link:
http://www.ciscopress.com/articles/article.asp?p=680824

Thursday, April 14, 2011

Travelling salesman problem implementation

/*Travelling Salesman Algorithm*/


#include<stdio.h>
#include<conio.h>

int a[10][10],visited[10],n,cost=0;



void get()
{
int i,j;

printf(“Enter No. of Cities: “);
scanf(“%d”,&n);

printf(“\nEnter Cost Matrix: \n”);
for( i=0;i<n;i++)
{
printf(“\n Enter Elements of Row # : %d\n”,i+1);
for( j=0;j<n;j++)
scanf(“%d”,&a[i][j]);
visited[i]=0;
}

printf(“\n\nThe cost list is:\n\n”);
for( i=0;i<n;i++)
{
printf(“\n\n”);
for( j=0;j<n;j++)
printf(“\t%d”,a[i][j]);
}
}



void mincost(int city)
{
int i,ncity;
visited[city]=1;
printf(“%d –>”,city+1);
ncity=least(city);

if(ncity==999)
{
ncity=0;
printf(“%d”,ncity+1);
cost+=a[city][ncity];
return;
}

mincost(ncity);
}



int least(int c)
{
int i,nc=999;
int min=999,kmin;
for(i=0;i<n;i++)
{
if((a[c][i]!=0)&&(visited[i]==0))
if(a[c][i]<min)
{
min=a[i][0]+a[c][i];
kmin=a[c][i];
nc=i;
}
}
if(min!=999)
cost+=kmin;
return nc;
}



void put()
{
printf(“\n\nMinimum cost:”);
printf(“%d”,cost);
}

void main()
{
clrscr();
get();
printf(“\n\nThe Path is:\n\n”);
mincost(0);
put();
getch();
}

Banker's algorithm implementation

/*implementation of Banker's Algorithm

#include<stdio.h>
#include<conio.h>
struct process
{
int all[6],max[6],need[6],finished,request[6];
}p[10];
int avail[6],sseq[10],ss=0,check1=0,check2=0,n,pid,work[6];
int nor,nori;

void main()
{
int safeseq(void);
int ch,i=0,j=0,k,pid,ch1;
int violationcheck=0,waitcheck=0;

do
{
clrscr();
printf(“\n\n\t 1. Input”);
printf(“\n\n\t 2. New Request”);
printf(“\n\n\t 3. Safe State or Not”);
printf(“\n\n\t 4. print”);
printf(“\n\n\t 5. Exit”);
printf(“\n\n\t Enter ur choice : “);
scanf(“%d”,&ch);
switch(ch)
{
case 1:
printf(“\n\n\t Enter number of processes : “);
scanf(“%d”,&n);
printf(“\n\n\t Enter the Number of Resources : “);
scanf(“%d”,&nor);
printf(“\n\n\t Enter the Available Resouces : “);

for(j=0;j<n;j++)
{
for(k=0;k<nor;k++)
{
if(j==0)
{
printf(“\n\n\t For Resource type %d : “,k);
scanf(“%d”,&avail[k]);
}
p[j].max[k]=0;
p[j].all[k]=0;
p[j].need[k]=0;
p[j].finished=0;
p[j].request[k]=0;
}
}
for(i=0;i<n;i++)
{
printf(“\n\n\t Enter Max and Allocated resources for P%d : “,i);       for(j=0;j<nor;j++)
{
printf(“\n\n\t Enter the Max of resource %d : “,j);
scanf(“%d”,&p[i].max[j]);
printf(“\n\n\t Allocation of resource %d    : “,j);
scanf(“%d”,&p[i].all[j]);
if(p[i].all[j]>p[i].max[j])
{
printf(“\n\n\t Allocation should be less < or == max”);
j–;
}
else
p[i].need[j]=p[i].max[j]-p[i].all[j];
avail[j]=avail[j]-p[i].all[j];
}
}
break;
case 2:
violationcheck=0;
waitcheck=0;
printf(“\n\n\t Requesting process id : “);
scanf(“%d”,&pid);
for(j=0;j<nor;j++)
{
printf(“\n\n\t Number of Request for resource %d : “,j);                scanf(“%d”,&p[pid].request[j]);
if(p[pid].request[j]>p[pid].need[j])
violationcheck=1;
if(p[pid].request[j]>avail[j])
waitcheck=1;
}
if (violationcheck==1)
printf(“\n\n\t The Process Exceeds it’s Max Need: Terminated”);
else if(waitcheck==1)
printf(“\n\n\t Lack of Resourcess : Process State – Wait”);
else
{
for(j=0;j<nor;j++)
{
avail[j]=avail[j]-p[pid].request[j];
p[pid].all[j]=p[pid].all[j]+p[pid].request[j];
p[pid].need[j]=p[pid].need[j]-p[pid].request[j];
}
ch1=safeseq();
if(ch1==0)
{
printf(“\n\n\t Granting leads to Unsafe state : “);                                                                                                                     printf(“\n\n\t Request Denied “);
for(j=0;j<nor;j++)
{
avail[j]=avail[j]+p[pid].request[j];
p[pid].all[j]=p[pid].all[j]-p[pid].request[j];
p[pid].need[j]=p[pid].need[j]+p[pid].request[j];
}
}
else if(ch1==1)
printf(“\n\n\t Request Committed “);
}
break;
case 3:
if(safeseq()==1)
printf(“\n\n\t The System is in safe state “);
else
printf(“\n\n\t The System is Not in safe state “);
break;
case 4:
printf(“\n\n\t Number of processes : %d”,n);
printf(“\n\n\t Number of Resources : %d”,nor);
printf(“\n\n\t Pid \t   Max \t   Allocated \t Need “);
for(i=0;i<n;i++)
{
printf(“\n\n\t  P%d : “,i);
for(j=0;j<nor;j++)
printf(” %d “,p[i].max[j]);
printf(“\t”);
for(j=0;j<nor;j++)
printf(” %d “,p[i].all[j]);
printf(“\t”);
for(j=0;j<nor;j++)
printf(” %d “,p[i].need[j]);
}
printf(“\n\n\t Available : “);
for(i=0;i<nor;i++)
printf(” %d “,avail[i]);
break;
case 5:
break;
}
getch();
}while(ch!=5);
}
int safeseq()
{
int i,j,k;
ss=0;
for(j=0;j<nor;j++)
work[j]=avail[j];
for(j=0;j<n;j++)
p[j].finished=0;
for(int tk=0;tk<nor;tk++)
{
for(j=0;j<n;j++)
{
if(p[j].finished==0)
{
check1=0;
for(k=0;k<nor;k++)
if(p[j].need[k]<=work[k])
check1++;
if(check1==nor)
{
for(k=0;k<nor;k++)
{
work[k]=work[k]+p[j].all[k];
p[j].finished=1;
}
sseq[ss]=j;
ss++;
}
}
}
}
check2=0;
for(i=0;i<n;i++)
if(p[i].finished==1)
check2++;
printf(“\n\n\t”);
if(check2>=n)
{
printf(“\n\n\t The system is in safe state”);
for(int tj=0;tj<n;tj++)
printf(“P%d, “,sseq[tj]);
return 1;
}
else
printf(“\n\n\t The system is Not in safe state”);
return 0;
}