-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlsGraph.h
More file actions
117 lines (103 loc) · 2.77 KB
/
lsGraph.h
File metadata and controls
117 lines (103 loc) · 2.77 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/**
* This file describes the functions used for a graph structure
*
* @author Jeffrey Bromen
* @date 4/17/17
* @info Systems and Networks II
* @info Project 3
*/
#ifndef _LSGRAPH_H
#define _LSGRAPH_H
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include "lsPacket.h"
struct Graph
{
int size;
int directed;
int updated;
char *key;
struct AdjList *array;
} Graph;
struct AdjList
{
struct AdjListNode *head;
} AdjList;
struct AdjListNode
{
int dest;
int cost;
int seqN;
struct AdjListNode *next;
} AdjListNode;
/**
* Allocates memory for a new graph structure.
*
* @param size - number of nodes in graph
* @param directed - 1 if directed graph, 0 if undirected graph
*
* @return - pointer to graph structure
*/
struct Graph *newGraph(int size, int directed);
/**
* Allocates memory for a new adjacency list node
*
* @param dest - index of destination node
* @param cost - cost of traversing the edge
* @param seqN - sequence number of last link-state packet received.
*
* @return - pointer to edge structure
*/
struct AdjListNode *newAdjListNode(int dest, int cost, int seqN);
/**
* Adds or updates an edge in a graph structure.
*
* @param graph - graph structure being modified
* @param source - node label of source
* @param dest - node label of destination
* @param cost - cost of traversing edge
* @param seqN - sequence number of link-state packet
*
* @return - 0 if successful, -1 if an error occurred
*/
int addEdge(struct Graph *graph, char source, char dest, int cost, int seqN);
/**
* Updates an existing edge if a newer sequence number is received.
*
* @param graph - graph being updated
* @param source - index of source node
* @param dest - index of destination node
* @param cost - new cost of edge
* @param seqN - sequence number of received link-state packet
*
* @return - 1 if not updated, 0 if updated
*/
int updateEdge(struct Graph *graph, int source, int dest, int cost, int seqN);
/**
* Finds the index of a router label.
* Assigns a label to an index if not found and room is availible.
*
* @param key - array of router labels
* @param size - size of array
* @param label - label being searched for
*
* @return - index of label, -1 if not found and unable to assign index
*/
int getIndex(char *key, int size, char label);
/**
* Processes a link state packet and adds/modifies the graph accordingly
*
* @param graph - graph structure of router network
* @param lsPacket - link-state packet received
*
* @return - 0 if successful, -1 if an error occurred
*/
int addEdgeFromPacket(struct Graph *graph, char *lsPacket);
/**
* Prints all of the vertices and edges of a graph. Used for debugging.
*
* @param graph - graph being printed
*/
void printGraph(struct Graph *graph);
#endif // _LSGRAPH_H