-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlsPacket.h
More file actions
98 lines (86 loc) · 2.58 KB
/
lsPacket.h
File metadata and controls
98 lines (86 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/**
* This file describes the functions used for building and modifying link-state packets.
* Link-State Packets have the following format:
* Hop Count (1B) | Sequence Number (1B) | Source ID (1B) | Destination ID (1B) | Cost (4B)
*
* @author Jeffrey Bromen
* @date 4/16/17
* @info Systems and Networks II
* @info Project 3
*/
#ifndef _LSPACKET_H
#define _LSPACKET_H
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Number of bytes in a link-state packet
#define LS_PACKET_SIZE 8
/**
* Builds a link-state packet with the given parameters and stores it in a buffer.
*
* @param buffer - buffer where the link-state packet will be stored
* @param hopCount - number of hops for which the packet will be forwarded (0-255)
* @param seqNumber - sequence number of the link-state packet
* used to differentiate from older instances of packets (0-255)
* @param source - ID of the source router (single character)
* @param destination - ID of the destination router (single character)
* @param cost - cost to travel from the source router to destination router
*/
void buildLSPacket(char *buffer, int hopCount, int seqNumber, char source, char destination, int cost);
/**
* Gets the hop count of a link-state packet.
*
* @param lsPacket - buffer containing the link-state packet
*
* @return - the hop count
*/
int getHopCount(char *lsPacket);
/**
* Gets the sequence number of a link-state packet.
*
* @param lsPacket - buffer containing the link-state packet
*
* @return - the sequence number
*/
int getSequenceNumber(char *lsPacket);
/**
* Gets the source ID of a link-state packet.
*
* @param lsPacket - buffer containing the link-state packet
*
* @return - the source ID
*/
char getSourceID(char *lsPacket);
/**
* Gets the destination ID of a link-state packet.
*
* @param lsPacket - buffer containing the link-state packet
*
* @return - the destination ID
*/
char getDestinationID(char *lsPacket);
/**
* Gets the cost of a link-state packet.
*
* @param lsPacket - buffer containing the link-state packet
*
* @return - the cost
*/
int getCost(char *lsPacket);
/**
* Prints all of the parameters of a link-state packet. Used for debugging.
*
* @param lsPacket - buffer containing the link-state packet
*/
void printLSPacket(char *lsPacket);
/**
* Decrements the hop count of a link-state packet
*
* @param lsPacket - buffer containing the link-state packet
*
* @return - the new hop count after decrementing
*/
int decrementHopCount(char *lsPacket);
#endif // _LS_PACKET_H