|
Divya Mukundan (divi@ku.edu) Muthuvelan KP (kpm@ku.edu) Directed by Dr. Joseph B. Evans Department of Electrical Engineering and Computer Science The University of Kansas Lawrence, KS 66045 |
![]() |
Spring 2002Download code.See Real Video. See PPT slides. |
| February 23 - March 3 | Study of VRRP (see VRRP Working Group). |
| March 4 - March 31 | Design of VRRP implementation. |
| April 1 - April 30 | Implementation of VRRP. |
| May 1 - May 10 | Testing our implementation. |
| Event State | Initialize | Backup | Master |
| Start | ACTION_1 | NONE | NONE |
| Shutdown | NONE | ACTION_2 | ACTION_4 |
| Master Down Timer | NONE | ACTION_1 | NONE |
| Receive ADVERTISEMENT | NONE | ACTION_3 | ACTION_6 |
| Advertise Timer | NONE | NONE | ACTION_5 |
If Priority = 255
If the Priority Field in the ADVERTISEMENT = 0
If Priority field in the ADVERTISEMENT = 0
Else#define VRRP_MAX_EVENTS 5
#define VRRP_MAX_STATES 3#define VRRP_INIT_STATE 0
#define VRRP_BACKUP_STATE 1
#define VRRP_MASTER_STATE 2#define VRRP_ACTION_NONE 0
#define VRRP_ACTION_1 1
#define VRRP_ACTION_2 2
#define VRRP_ACTION_3 3
#define VRRP_ACTION_4 4
#define VRRP_ACTION_5 5
#define VRRP_ACTION_6 6
#define VRRP_ACTION_7 7#define VRRP_START_EVENT 0
#define VRRP_SHUTDOWN_EVENT 1
#define VRRP_MASTER_DOWN_EVENT 2
#define VRRP_RCV_ADVERTISEMENT_EVENT 3
#define VRRP_ADVERTISE_EVENT 4State Event Machine
int SEM[VRRP_MAX_EVENTS][VRRP_MAX_STATES] =
{
{ VRRP_ACTION_1, VRRP_ACTION_NONE, VRRP_ACTION_NONE },
{ VRRP_ACTION_7, VRRP_ACTION_2, VRRP_ACTION_4 },
{ VRRP_ACTION_NONE, VRRP_ACTION_1, VRRP_ACTION_NONE },
{ VRRP_ACTION_NONE, VRRP_ACTION_3, VRRP_ACTION_6 },
{ VRRP_ACTION_NONE, VRRP_ACTION_NONE, VRRP_ACTION_5 }
};Virtual Router Structure
struct VR {
uint8_t VRId; /* Virtual Router Identifier */
uint8_t N; /* Number of virtual IP addresses. */
uint32_t *VRIp; /* List of VR Ip Addresses */
char *VRMac[MAC_ADDR_SIZE]; /* 00-00-5E-00-01-<VRID> */
uint8_t Priority; /* Priority of VRRP Router */
uint8_t AdvertInt; /* Advertisement Internval */
uint8_t AuthType; /* Authuntication Type */
uint8_t AuthData[VRRP_AUTH_SIZE];
uint8_t PreemptMode; /* To Enable Preempt Mode */
uint8_t CurrentState; /* Current State of VRRP Router */
int SockFd, McastSockFd; /* To Send/Receive VRRP Messages */
struct VRIF VRIf;
};struct VRIF {
uint32_t Ip;
char Mac[MAC_ADDR_SIZE];
char *IfName;
};
The VRRP router process starts by reading the configuration file, initializes itself and transitions to INIT state. Our implementation uses signals to generate the start-up and the shutdown event. The start-up event is used to bring a VRRP router from INIT state into the BACKUP/MASTER state. The shutdown event will be used to gracefully terminate the VRRP router process regardless of the state that it is in. Once in the BACKUP/MASTER state, it can receive timer events through SIGALRM and packet reception is handled using SIGIO.main()
{
/* Fork the process and exit parent. */
/* Child process runs VRRP */
/* Disassociate from virtual terminal. */VRRP_Init();
while (1) {
/* Do nothing. Wait for signal reception. */
}
}
void VRRP_CallSEM(int Event)
{
int Action;Action = SEM[Event][VRRtr.CurrentState];
/* Block signals. */
switch(Action) {case VRRP_ACTION_1: /* START event in INIT state */
/* Create raw socket. */
/* Add to multicast group to receive VRRP advertisements. */
/* Set SIGIO */
/* Set priority to 255 if you own VR IP address. */
/* If VRRtr.Priority == 255 */
/* Send an ADVERTISEMENT. */
/* Broadcast ARP. */
/* Start AdvertTimer. */
/* If not the owner of the VR IP address, create it on the interface. */
/* CurrentState = VRRP_MASTER_STATE */
/* Else */
/* Start MasterDownTimer. */
/* CurrentState = VRRP_BACKUP_STATE */
/* Endif */
break;case VRRP_ACTION_2: /* SHUTDOWN event in BACKUP state */
/* Stop MasterDownTimer. */
/* CurrentState = VRRP_INIT_STATE */
/* De-initialize */
break;
case VRRP_ACTION_3: /* RECV ADVERTISEMENT in BACKUP state */
/* Read Advertisement from socket. */
/* If Priority in Advertisement == 0 */
/* Start MasterDownTimer with interval = SkewTime */
/* Else */
/* If PreemptMode == VRRP_PREEMPT_FALSE OR Priority in Advertisement >= VRRtr.Priority */
/* Restart MasterDownTimer with interval =
* MasterDownInterval. */
/* Else */
/* If PreemptMode == VRRP_PREEMPT_TRUE AND VRRtr.Priority > RemotePriority */
/* Become Master. */
/* Endif */
/* Endif */
/* Endif */
break;case VRRP_ACTION_4: /* SHUTDOWN event in MASTER state */
/* Stop AdvertTimer. */
/* Send an ADVERTISEMENT with Priority field set to 0. */
/* Remove VR IP address */
/* CurrentState = VRRP_INIT_STATE */
break;case VRRP_ACTION_5: /* ADVERTISE TIMER in MASTER state */
/* Send an ADVERTISEMENT. */
/* Reset AdvertTimer with interval AdvertInt. */
break;case VRRP_ACTION_6: /* RCV ADVERTISEMENT in MASTER */
/* Read Advertisement from socket. */
/* If Priority in Advertisement == 0 */
/* Same as ACTION_5 i.e. */
/* Send an ADVERTISEMENT. */
/* Reset AdvertTimer with interval AdvertInt. */
/* Else */
/* If Priority in Advertisement > VRRtr.Priority OR (Priority in Advertisement = VRRtr.Priority AND
* SrcIPAddr in Advertisement > LocPriAddr. */
/* Stop AdvertTimer. */
/* Start MasterDownTimer with interval = MasterDownInterval. */
/* CurrentState = VRRP_BACKUP_STATE */
/* Remove VR IP address */
/* Endif */
/* Endif */
break;case VRRP_ACTION_7:
exit() after cleaning all allocated resources.
break;case VRRP_ACTION_NONE:
/* Invalid event in this state. */
break;
}/* Unblock signals. */
}VRRP_Init()
{
/* Set defaults to VR structure. */
/* Read config file, check parameter values and copy to VR structure. */
/* Exit if MUST configs are not set in the confile file. */
/* Check if the virtual router IP address is the same as the real IP
* addresses of the machine's interfaces. i.e. other than the configured
* interface. */
/* Create pidfile vrrp.<vrid> for VRRP. */
/* Set state to VRRP_INIT_STATE. */
/* Set signal for SIGUSR2. */
/* SIGUSR2 - This signal will be used to shutdown VRRP gracefully. */
/* Set signal for SIGUSR1. */
/* SIGUSR1 - This signal will be used to generate the start-up event for
* VRRP. */
}VRRP_DeInit() /* To be called in backup and master states to shutdown VRRP */
{
/* Remove from multicast address. */
/* Close VRRP socket. */
/* Release all allocated memory in the VR structure. */
/* Remove pid file. */
}Catch_SIGUSR1() /* Start-Up Event */
{
/* Stop signal handling for SIGUSR1. */
VRRP_CallSEM(VRRP_START_EVENT);
}Catch_SIGUSR2() /* Shutdown-Event */
{
/* Stop signal handling for SIGUSR2. */
VRRP_CallSEM(VRRP_SHUTDOWN_EVENT);
VRRP_DeInit();
exit();
}Catch_SIGALRM() /* Timer Event */
{
/* If CurrentState == VRRP_MASTER_STATE */
VRRP_CallSEM(VRRP_ADVERTISE_EVENT);
/* Elseif CurrentState == VRRP_BACKUP_STATE */
VRRP_CallSEM(VRRP_MASTER_DOWN_EVENT);
/* Else*/
/* Invalid */
/* Endif */
}Catch_SIGIO() /* Packet Reception Event */
{
VRRP_CallSEM(VRRP_RCV_ADVERTISEMENT_EVENT);
}
Many kernel interface functions that were added are listed below. The following functions makes use of ioctl calls, setsockopt, getsockopt and other systems calls.
IsRealIPAddress(VRIp, IfName, Option); /* To check for ip address on the Interface */Function to send Gratuitous ARP is defined using the SOCK_PACKET interface provided by the Linux kernel.SetVirtualMACAddress( VRId, Mac); /* Set The Virtual MAC Address */
GetHwAddress(IfName,Mac); /* Get The MAC Address on a Interface */
SetHwAddress(IfName, Mac); /* Get The MAC Address on a Interface */
GetPrimaryIPAddress(IfName, IPAddr); /* Get IP Address of an Interface */
AddToMulticast(SockFd, IpAddr, MCastAddr); /* Add socket to Multicast Address */
RemoveFromMulticast(SockFd, IpAddr, MCastAddr); /* Remove socket from Multicast Address */
AddAliasInterface(AliasIp, IfName, AliasNo); /* Add Alias to a Interface */
RemoveAliasInterface(IfName, AliasNo); /* Remove Alias from a Interface */
CalculateIPChecksum(Buffer); /* Calculate IP Checksum */
VerifyChecksum(Buffer, Size); /* Verify the Checksum Field */
CreateAsyncRawSocket(SockFd, IpAddr); /* Asynchronous Socket for Receiving */
![]()
The various various test cases and the corresponding results are discussed below.
- Unequal Priority Without Preemption
|
VRRP Router 1
|
VRRP Router 2 |
| Configuration File | Configuration File |
| vrrp.log | vrrp.log |
Results:Router 1 is configured with lower priority than Router 2. Router 2 is started first and it becomes the MASTER of the configured VR. Router 2 is started later and since both routers are configured with n-preemption the Router 1 continues to be the MASTER, ven when a higher priroty router is available. This is mainly used to prevent unnecessary service distruptions.2. Unequal Priority With Preemption
|
VRRP Router 1
|
VRRP Router 2 |
| Configuration File | Configuration File |
| vrrp.log | vrrp.log |
Results:3. Equal Priority Without PreemptionRouter 1 is configured with lower priority than router 2. Router 2 is started first and it becomes the MASTER of the configured VR. Router 2 is started later. Since its configured with preemption it would be sending the VRRP Advertisement packet and becomes the MASTER. It is used to have preference over particular path when available.
|
VRRP Router 1
|
VRRP Router 2 |
| Configuration File | Configuration File |
| vrrp.log | vrrp.log |
Results:4. Equal Priority With PreemptionRouter 1 and Router 2 are configured with equal priority. Since Router 1 is started first and is configured with no-preemption is remains the MASTER, even after Router 2 comes up.
|
VRRP Router 1
|
VRRP Router 2 |
| Configuration File | Configuration File |
| vrrp.log | vrrp.log |
Results:5. Unequal Priority Without Preemption, One of the VRRP Routers is IP Address Owner.Router 1 and Router 2 are configured with equal priority. Since Router 1 is started first is becomes the MASTER. When 2 routers have equal priority the one with the highest primary IP Address wins the election. In the above case, VRRP Router 1 has a IP address of 192.168.1.2 while VRRP Router 2 has a IP address of 192.168.1.1. Hence, Router 1 continues to be the master.
|
VRRP Router 1
|
VRRP Router 2 |
| Configuration File | Configuration File |
| vrrp.log | vrrp.log |
Results:6. Unequal Priority With Simple Authentication.Router 1 is configured with lower priority than Router 2. Router 2 is configured with priority of 255. Router 2 is started first and it becomes the MASTER of the configured VR. Router 2 is started later since Router 1 is configured with no preemption, Router 1 continues to be the master.
|
VRRP Router 1
|
VRRP Router 2 |
| Configuration File | Configuration File |
| vrrp.log | vrrp.log |
Results:Interface configuration of a VRRP Router before and after it becomes the Master of Virtual router.Router 1 is configured with lower priority than Router 2. Router 2 is started first and it becomes the MASTER of the configured VR. Router 2 is started later. Both routers are configured with simple authentication.
We would like to thank each other :) as we were able to complete our work with ease, only by sharing project responsibilities.
Finally, we would like to thank people all over the Internet and man
page writers for providing excellent documentation and the needed resources.
These were helpful to understand system calls and kernel interfaces needed
to manipulate network devices.