Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c...

80
Examensarbete Routing of traffic in an IP-network using combined routing patterns Andreas Lindblad LiTH-MAT-EX–2015/06–SE

Transcript of Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c...

Page 1: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

Examensarbete

Routing of traffic in an IP-network usingcombined routing patterns

Andreas Lindblad

LiTH-MAT-EX–2015/06–SE

Page 2: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks
Page 3: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

Routing of traffic in an IP-network usingcombined routing patterns

Division of Optimization, Department of Mathematics, Linkoping University

Andreas Lindblad

LiTH-MAT-EX–2015/06–SE

Examensarbete: 30 hp

Level: D

Supervisor: Kaj Holmberg,Division of Optimization, Department of Mathematics, Linkoping University

Examiner: Kaj Holmberg,Division of Optimization, Department of Mathematics, Linkoping University

Linkoping: June 2015

Page 4: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks
Page 5: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

Matematiska Institutionen581 83 LINKOPINGSWEDEN

June 2015

x x

http://urn.kb.se/resolve?urn=urn:nbn:se:liu:diva-

119973

LiTH-MAT-EX–2015/06–SE

Routing of traffic in an IP-network using combined routing patterns

Andreas Lindblad

In IP networks using the OPSF-principle together with the ECMP-principle, thetraffic is routed in all shortest paths. Weights on links are set by an administrator,not knowing how the resulting routing pattern will become. In this final thesis, I givea heuristic solution to the problem of changing a set of desired routing patterns inan ordered way to make them compatible with each other. An implementation of thealgorithm has been made and some testing with provided data for performance is alsopresented.

IP-Network, Routing pattern, Valid cycles, Heuristic methodNyckelord

Keyword

Sammanfattning

Abstract

Forfattare

Author

Titel

Title

URL for elektronisk version

Serietitel och serienummer

Title of series, numbering

ISSN

ISRN

ISBNSprak

Language

Svenska/Swedish

Engelska/English

Rapporttyp

Report category

Licentiatavhandling

Examensarbete

C-uppsats

D-uppsats

Ovrig rapport

Avdelning, InstitutionDivision, Department

DatumDate

Page 6: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

vi

Page 7: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

Abstract

In IP networks using the OPSF-principle together with the ECMP-principle,the traffic is routed in all shortest paths. Weights on links are set by an ad-ministrator, not knowing how the resulting routing pattern will become. Inthis final thesis, I give a heuristic solution to the problem of changing a set ofdesired routing patterns in an ordered way to make them compatible with eachother. An implementation of the algorithm has been made and some testingwith provided data for performance is also presented.

vii

Page 8: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

viii

Page 9: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

Acknowledgements

This is my master thesis for a degree in Master of Sience in Applied Mathe-matics. It has been carried out at the Division of Optimization, Departmentof Mathematics at Linkoping University. I would like to thank my supervisorand examiner Kaj Holmberg for support with limitations to this thesis and for-mulating the problem. I would also like to thank my opponent Sofia LarssonCahlin for the feedback and criticism on the work. My wife Johanna and childJon also deserves a special thank you for the love and support which I verymuch needed writing this thesis. My father in law also deserves a special thankyou for helping out with daycare in the last months.

Andreas Lindblad, Linkoping June 2015

ix

Page 10: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

x

Page 11: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

Notation

Abbrevations

OSPF IP-network protocol. States that all shortest paths should be used(Open Shortest Path First)

ECMP IP-network protocol. States that each node should split the trafficequal on each outgoing link included in the shortest path (Equal CostMulti Path)

RP Set of arcs to be used for routing the trafic (Routing Pattern)

SPG, SP-Graph Graph describing routing patterns (Shortest Path Graph)

WFP Name for the problem of finding weights given desired routing patterns(Weight Finding Problem)

Nomenclature

G = (N, A) Directed graph containing the nodes N and arcs A(ai, aj) ∈ A One specific arc between node i and j in NSPGi ∈ A SP-Graph i, i ≤ count(N)C = F ∪B Cycle consisting of arcs from graphs F and B

xi

Page 12: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

xii

Page 13: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

Contents

1 Introduction 11.1 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2 Problem description . . . . . . . . . . . . . . . . . . . . . . . . . 11.3 Goals and limitations . . . . . . . . . . . . . . . . . . . . . . . . . 21.4 Reader’s guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

2 Theory 32.1 An introduction to valid cycles . . . . . . . . . . . . . . . . . . . 52.2 Method for finding valid cycles . . . . . . . . . . . . . . . . . . . 62.3 Breaking valid cycles . . . . . . . . . . . . . . . . . . . . . . . . . 92.4 Updating SP-graphs . . . . . . . . . . . . . . . . . . . . . . . . . 9

3 The heuristics design 113.1 Graph selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113.2 Update method . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123.3 Replacing arcs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143.4 Analysis of valid cycles . . . . . . . . . . . . . . . . . . . . . . . . 16

3.4.1 Eligible arcs . . . . . . . . . . . . . . . . . . . . . . . . . . 163.4.2 C1 cycles . . . . . . . . . . . . . . . . . . . . . . . . . . . 163.4.3 C2 cycles . . . . . . . . . . . . . . . . . . . . . . . . . . . 163.4.4 C3 cycles . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

3.5 Randomization . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173.6 Full specification . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

4 Heuristics performance 234.1 Full example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234.2 Performance measures . . . . . . . . . . . . . . . . . . . . . . . . 24

5 Summary and conclusions 27

6 Future work 29

Bibliography 31

Appendix A Source code 33

xiii

Page 14: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

Chapter 1

Introduction

This is the master thesis of Andreas Lindblad at Linkoping University writtendiscontinuously from 2010 to 2015.

This first chapter is an introduction giving the problem background (sec-tion 1.1), a problem description (section 1.2), the goals and limitations for thisthesis (section 1.3) and a small readers guide (section 1.4).

1.1 Background

In IP-networks the routing protocol OSPF (Open Shortest Path First) is widelyused and it dictates that the traffic is routed on the shortest path(s) from eachrouter to each destination. The routers are calculating the shortest path tothe destination using the weights associated with each link. If multiple equallyshort paths exist the traffic is split using the ECMP (Equally Cost Multi-pathsPrinciple) so that all shortest paths are used. The weights are manually set bya network administrator and the routing patterns will follow from the abovementioned principles. If, however, one has a set of routing patterns, would itbe possible to find weights that give the desired routing of the traffic in theIP-network given the two principles? In [3] a study has been conducted totell whether such weights may exist or not. If they exist, nothing needs to bedone. But if, however, no compatible weights exist that give the desired routingpattern, how should the SP-graphs be changed for compatible weights to exist?

1.2 Problem description

Suppose that the administrator has a number of SP-graphs telling how thetraffic should be routed from node Ai to all other nodes in the network. Is itnow possible to find compatible weights for all of those routing patterns to beused simultaneously? If not, how should the routing pattern(s) be changed ina systematic way to be able to find compatible weights? This thesis aims tocreate a heuristic suggesting a solution to that problem.

1

Page 15: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

1.3. GOALS AND LIMITATIONS

1.3 Goals and limitations

The goal of this thesis is to investigate a different approach to the design ofIP-networks using desired SP-graphs and create a heuristic that systematicallymodifies those SP-graphs to eliminate all pairwise valid cycles. The resultingheuristic will be implemented in object oriented c++ using an external programcalled spgb written in c for finding valid cycles (code written by Kaj Holmbergand it uses the VC method specified in [3] with small modifications from myselffor removing all display output). In the development of such a heuristic thefollowing limitations are assumed:

1. Only eliminations of Valid Cycles are considered. If all cycles arebroken, the graphs are considered to be compatible (see section 2.1for why this is not the whole truth).

1.4 Reader’s guide

chapter 1 Introduction to the thesis paired with background and goal.chapter 2 General theory and problem formulation for the areas in-

cluded.chapter 3 Description of the heuristic algorithm. Design, develop-

ment and flowcharts.chapter 4 Performance measures of the heuristics and analysis of the

results.chapter 5 Summary and conclusions from this work.chapter 6 Future work and continuation from this thesis.A Main source code.

2

Page 16: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

Chapter 2

Theory

Consider a directed graph G = (N,A) where N is the set of nodes and A is the setof arcs, or more formally A = {ai,j : ∀i,∀j ∈ N, i 6= j}. Assume that a numberof routing patterns, RPi ⊂ A for i = 1, . . . ,m ≤ count(N), is given and thosegraphs describe the desired routing patterns (if having “small” routing patternsthey can be combined into larger ones, see [?] for a thesis concerning combiningrouting patterns). All routing patterns may contain multiple paths between agiven node pair and the traffic should then be split using the ECMP-principle.

In the Weight Finding Problem (WFP) as described in [1] the problem wasformulated as to try and find weights given the desired routing patterns and,if no such weights exist, try to identify which parts of the graphs that arein conflict. To be able to continue that work and resolve the conflicts using aheuristic algorithm, some definitions and reasoning from the same paper is used.

For the WFP the OSPF-principle is assumed, that is integral weights wi,j ≥1 are associated with each arc ai,j ∈ A. Let pk,l denote a path between thenodes k and l and let W (pk,l) =

∑(i,j)∈p

wi,j be the total cost for that path. If

W (pk,l) ≤ W (qk,l) the path pkl is called a minimal weight path and if W (pk,l)is strictly smaller than W (qk,l) the same path is called a unique minimal weightpath. This is extended for sets as P = {p : W (p) < W (q),∀q ∈ A \P )} is calleda unique minimal weight path set. If the set of routing patterns are such sets ofpaths, weights exist for the arcs that give the routing patterns in question.

The following formulation can be found in [1]: “Lemma 1. If a desiredpath contains a directed cycle, no compatible weights exist.” This meansthat one prerequisite is that none of RPi may contain a directed cycle. Thiscan be realized quite easily. Consider a graph G = (N,A) with the nodesn1, n2, n3 and n4 and the links a1,2, a1,3, a2,3, a3,4 and a4,2 as shown in Fig-ure 2.1a. Now assume one routing pattern exists with a directed cycle and let itbe RPcyclic = a1,2, a2,3, a3,4, a4,2 (illustrated in Figure 2.1b). Assume that theweights that give this routing pattern are w1,2, w2,3, w3,4 and w4,2. Since thepath p = 1− 2− 3− 4 should be equally short as q = 1− 2− 3− 4− 2− 3− 4this would mean that W (p) and W (q) must be equal. However

∑q wi,j =∑

p wi,j + w4,2 + w2,3 + w2,4 which means that the tail sum must be equal tozero. But the weights must be strictly positive and this is a contradiction whichmeans that the routing pattern cannot contain any directed cycles if compatibleweights should exist.

3

Page 17: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

1

2

3

4

(a) Full network

1

2

3

4

(b) Cyclic routing pattern RPcyclic

1

2

3

4

(c) RP1,4

1

2

3

4

(d) RP1,2

Figure 2.1: Example of a directed cycle and subpath inconsistency

A subpath is defined in [1] as “Definition 1. If p and q are two paths andif q ⊂ p, then q is called a subpath of p” . When studying two routing patternsthis can be used to check if they are compatible in the following way. Considertwo routing patterns RPi and RPj in the graph G = (N,A). Now, assumethat the nodes nk and nl are connected in both of the routing patterns but inRPi it is connected through the node nm but not in RPj . This means thatpk,l = qk,m + qm,l where qk,m, qm,l ∈ RPi. Since p is not connected throughthe node nm in RPj this means that qk,m /∈ RPj and/or qm,l /∈ RPj and therouting patterns are not subpath consistent. So for two routing patterns tobe subpath consistent all node-pairs must be connected in the same way inboth graphs. No subpath may differ. One can quite easily also realize that ifhaving two routing patterns, they cannot be subpath inconsistent if compatibleweights should exist. Let RPi and RPj be two routing patterns with both pathsbetween the nodes nk and nl. Assume that there exists one path pk,l ∈ RPj

but pk,l /∈ RPi. The path pk,l must be shortest according to RPj and weightscan be obtained to achieve this. However according to RPi the path pk,l shouldnot be shortest so the two routing patterns cannot co-exist if they are subpathinconsistent. This is illustrated in Figure 2.1 with the graphs RP1,4 and RP1,2

where the first routing pattern dictates that from node 1 to node 3 the path1-2-3 should be used while the other routing pattern tells that the path 1-3should be used and thus, the routing patterns are not subpath consistent. Thisleads to the following definition that is a nessecary but not sufficient conditionfor compatibility of routing patterns.

Definition 1. Two routing patterns RPi and RPj must be subpath consistentif compatible weights may exist.

4

Page 18: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

2.1. AN INTRODUCTION TO VALID CYCLES

Definition 2. Subpath consistent routing patterns are called SP-graphs, or SPG(Shortest path graph).

2.1 An introduction to valid cycles

In [3], one source of incompatibility for SP-graphs was found. When studyingtwo SP-graphs to see if they can co-exist (are compatible), the method was tofind cycles that do not stem from subpath inconsistency. The method is aboutstudying flow of traffic when the two graphs are active together.

From [3] the following definitions are used when defining the valid cycles(with other enumeration for the definitions and other notations).

Definition 3. The cycle C = F ∪B is called a feasible cycle for graphs SPGi

and SPGj if B ⊆ SPGi and F ⊆ SPGj.

From the above definition it is noted that a feasible cycle C is formed byarcs in both SP-graphs.

Definition 4. For the cycle C = F ∪ B and the graphs SPGi and SPGj thearc (k, l) is called eligible if (k, l) ∈ (F\ SPGi ) ∪ (B\ SPGj ).

This means that an eligible arc is included in only one of the two graphs,either SPGi or SPGj but not both.

Definition 5. The cycle C = F ∪B is called an improving cycle if it containsat least one eligible arc.

And lastly the definition for valid cycles:

Definition 6. A cycle C is called valid if it is feasible and improving.

The reason for searching for such structures is given by the following theoremfrom [3].

Theorem 1. If there exists a valid cycle, then there exists no compatible set ofweights.

From the above definitions it is clear that a valid cycle is feasible and im-proving (Definition 6) which means that it contains at least one eligible arcand is formed by a subset from the given SP-graphs (Definition 5 and Defini-tion 3). Together with Definition 4 it is clear that given two SP-graphs, SPGi

and SPGj , all cycles that are formed by a subset from each graph with at leastone arc that is only included in one of the graphs, is also valid. And givenTheorem 1 it is clear that the SP-graphs aren’t compatible if any such cycleexist.

This criteria is necessary but not sufficient and lacking of valid cycles isa stronger necessary condition than the previously known condition based onsuboptimality. In [3], the authors conclude that there are three cases whenstudying SP-graphs and their compatibility: compatible weights exist, validcycles exist and neither compatible weights nor valid cycles exist. The lastgroup is also concluded to be “small” in some sense which means that justeliminating the presence of valid cycles isn’t enough to ensure the compatibilityof the routing patterns but the chanses are relatively good that they are. As

5

Page 19: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

2.2. METHOD FOR FINDING VALID CYCLES

stated in section 1.3, one limitation for this thesis is that only the first two casesare beeing considered. If all valid cycles are eliminated, it is assumed that theSP-graphs are compatible.

This means that given a set of SPGi, i = 1, . . . ,m ≤ count(N) for a completenetwork G = (N,A) where SPGi ⊆ A,∀i. Instead of trying to use weights onthe links for testing if the graphs are compatible it is possible to search forvalid cycles for each pair Sij = ( SPGi, SPGj) and if a valid cycle exists, nocompatible weights exist which is formally defined as

Definition 7. For a set of SP-graphs to be compatible, all SP-graphs must bepairwise compatible.

This definition is nesessary and sufficient for making the graphs compatible,given the limitations mentioned above.

From [3] the following lemma is noted.

Lemma 1. A valid cycle must contain at least three nodes.

2.2 Method for finding valid cycles

In [3] a method for finding valid cycles is proposed. The steps are listed inTable 2.1.

As a clarification for point 4 in the reduction phase: This step ensures thatpotential cycles are not eliminated in the search algorithm. For instance: As-sume that for node ni there is a set of arcs leaving the node and only one arcis entering (given the heuristic). Let the arc enabeling flow entering the nodebe labeled both F and B (it is not eligible, see Definition 4). Then the labelallowing the flow to go through the node is kept, and the other one is discarded.In this case the label F is kept so that the flow will be entering the node sincethe other arcs are leaving the node.

Example 1. Let G = (N,A)with N = {ni : i = 1 . . . 6} be given together withthe sp-graphs SPG1 = {a1,2, a1,3, a2,5, a3,4, a4,6, a5,6} andSPG2 = {a1,3, a2,1, a2,4, a2,5, a3,5, a4,6, a6,5}. Could the graphs be combined inthe sense that the routing patterns exist simultainously? Illustrations availablein Figure 2.2.

In the example above SPG1 and SPG2 are subpath inconsistent. The firstgraph dictates that from node 2 to node 5 only one path should be used (namelythe arc a2,5) but in the second graph the path p = a2,4, a4,6, a6,5 should be equalyshort as q = a2,5. So the first graph has one shortest path from node 2 to node 5and the second one has two paths from node 2 to node 5. This means that SPG1

and SPG2 are not subpath consistent and there is no need to check for cyclesif only wanting to test if they are compatible. However, it is still possible tosearch for valid cycles for two subpath inconsistent graphs, as illustrated in thesame example. Note that in Figure 2.2c eligible arcs are marked and especiallya1,2 is labeled Fe and a2,1 is labeled Be. This is also the case for the arcs a5,6and a6,5. In Figure 2.2d those have been replaced by a single arc for readability,but there are two arcs (each eligible) but the flow will go in the same directionhence the simplification. In Figure 2.2e the cycle 2-4-3-5-2-. . . is highlighted.The algorithm for finding valid cycles might find this cycle or another. Another

6

Page 20: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

2.2. METHOD FOR FINDING VALID CYCLES

1. Choose two SP-graphs: SPGi and SPGj

2. Labeling phase: Label each arc in SPGi with B and each arcin SPGj with F. Arcs with one label are marked eligible.

3. Reduction phase: Repeat the reductions until no more changesoccur. (See Table 2.2)

4. Elimination check: If the number of arcs or nodes is less thanthree (see Lemma 1), go to 11

5. Find eligible arc: Let (i, j) be an eligible arc. If no eligible arcexist, go to 11.

6. Heuristic cycle search: Start with arc (i, j) and find a cycle(in the proper direction) by the heuristic.

7. Evaluation of cycle: If the cycle contains an eligible arc, go to13. If the cycle has total in-degree or out-degree equal to zero, goto 10.

8. Shortest path cycle search: Set the arc cost zero for eligiblearcs and one for the other arcs. Find shortest path from node j tonode i (or the other way around). If a path exists, add arc (i, j)to form a cycle and go to 13.

9. No path: Remove arc (i, j). If the reachable subgraph containssome eligible arc, go to 3.

10. Isolated cycle/subgraph found: Eliminate all nodes in theisolated cycle/subgraph and all adjacent arcs. Go to 3.

11. Graph eliminated: No valid cycle found. If SP-graphs remainto compare, go to 1.

12. No valid cycle exists: Terminate the method.13. Valid cycle found: Terminate the method. No compatible

weights exist.

Table 2.1: The VC method

1. Discard all arcs with no label.2. Where nodes only have one adjacent arc: Discard the node and

arc.3. If there are no arcs leaving (entering) a node: Discard the node

and all adjacent arcs.4. If there is only one arc entering (leaving) a node, and this arc is

labeled with both F and B: Keep the label that enable entering(leaving) the node, and remove the other label.

Table 2.2: Reduction phase for the VC method. Note that points 3 and 4 arereally two steps each, one for checking entering arcs and one for leaving arcs.

7

Page 21: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

2.2. METHOD FOR FINDING VALID CYCLES

1

2

3

4

5

6

(a) SPG1

1

2

3

4

5

6

(b) SPG2

1

2

3

4

5

6

Fe

F,B

Be

Be

Be

F,B

Fe

Be

Fe

F,B

(c) SPG1 (F) and SPG2 (B)

1

2

3

4

5

6

B

Be

FFe

Be

B

(d) Graph after reduction phase

1

2

3

4

5

6

B

Be

FFe

Be

B

(e) Reduced graph with one valid cyclehighlighted

Figure 2.2: Example of directed cycles and subpath inconsistency

8

Page 22: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

2.3. BREAKING VALID CYCLES

valid cycle that can be identified is 2-5-6-7-2-. . . and this is a cycle that stemsfrom the subpath inconsistancy between the graphs. So, the VC algorithm isalso identifying subpath inconsistency in this way.

2.3 Breaking valid cycles

In order to “break” (or invalidate) a valid cycle C = F ∪ B, one of the actionsin Table 2.3 can be taken, as stated in [3].

1. Remove one eligible arc2. Add all eligible arcs in B to F and vice versa3. Exchange one eligible arc in the cycle contained in either SPGi

or SPGj

Table 2.3: Ways of invalidating valid cycles

The first way will render the cycle in-feasible and thus non-valid and thesecond method will make the cycle non-improving and this will also result inthe cycle to become non-valid (Definition 5 and Definition 6). The third methodcan be used to make the cycle infeasible and/or non-improving. Which methodto use when is depending on the SPG used in the problem and also what typeof results that are acceptable. There is no solution that is generally better thananother. If arcs are added however, more paths may be introduced and thusmore splitting of traffic according to the ECMP-principle. If arcs are removed,some action should be taken to make sure the origin and the nodes for thatSPG are still reachable.

2.4 Updating SP-graphs

Assume that a set of SP-graphs is given and denote it as SPG0 = { SPG0i

⊆ A, i = 1, . . . ,m}. In some way these graphs need to be updated where validcycles exist in order to eliminate the incompatible components. Let SPGn

= { SPGni ⊆ A, i = 1, . . . ,m}, n = 1, 2, 3, . . . denote the SP-graphs at the

n-th iterative update and let SPGnj and SPGn

k denote two SP-graphs in thatiteration. Now we can make the following definitions.

Definition 8. The total amount of feasible cycles for the two SP-graphs SPGnj

and SPGnk is Cn

jk = {C = F ∪B,F ⊆ SPGnj , B ⊆ SPGn

k}.

Let V njk be Cn

jk where the cycle is also improving (that is, contains at leastone eligible arc). This is the set of valid cycles that exists for the two graphs.Given the definitions for two graphs it can be generalized for the complete setas follows.

Definition 9. Define Cn as the set of all cycles formed by the SP-graphs givenby SPGn, that is Cn = {Cn

jk,∀SPGnj ,∀SPGn

k ∈ SPGn , j 6= k}.

Definition 10. Let Vn = {V njk,∀ SPGj

n ∀ SPGkn , j 6= k} ⊆ Cn be the set of

valid cycles for SPGn.

9

Page 23: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

2.4. UPDATING SP-GRAPHS

Vn can be used as an indicator for how compatible the SP-graphs givenby SPGn are. If Vn = ∅ all graphs given by the SPGn are compatible andweights that give the routing patterns exist (again, the “small” set where novalid cycle exists and compatible weights do not exist is not considered here,see [3]). Given a set of SP-Graphs, SPG0, if Vn 6= ∅, how should the graphs beupdated in some minimal way to eventually find a SPGq that yields Vn = ∅?In order to formulate this, the minimal way of changing from the original SP-graphs must be defined. One definition could be to define it as the amountof arcs that differ from the original graphs. This allows us to formulate anobjective function as min f( SPG0 − SPGn ) where f =

∑gab and gab = 1 (a, b) ∈ SPGn, (a, b) /∈ SPG0

1 (a, b) /∈ SPGn, (a, b) ∈ SPG0

0 otherwiseNow the problem can be formulated as to find one SPGn where Vn = ∅ and

f( SPG0 - SPGn ) is minimal.Given Vn how should the SPGn be updated to give SPGn+1? Let ||Vn||

denote the amount of valid cycles for the given set SPGn. The update shouldyield ||Vn+1|| ≤ ||Vn|| and SPGn+1

i must still connect all nodes as in SPGni for

all i in SPGn+1 and the amount of SP-graphs must be the same in SPGn+1 asin SPGn. Now, which SPGi

n should be updated in the iteration? One methodcould be to update the SPGi

n that is part of the most valid cycles. This wouldrender a “biggest step“ in the minimizing operation for finding a optimum.There is one problem with this method: Vn is very expensive to calculate andit needs to be recalculated in each iteration. This is why a heuristic method isneeded.

10

Page 24: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

Chapter 3

The heuristics design

According to Definition 7 the problem of making a set of SPG compatible canbe reduced to a series of subproblems of making each pair of SPGi and SPGj

∀i, j compatible. In order to do this in an ordered way some reasoning canbe applied for creating an order in which the SPG should be processed. Ingeneral terms, the algorithm is comparing each graph-pair in a systematic way(see section 3.1) and tries to do as few (or small) modifications to the graphs aspossible in each step. To not get stuck for ever a time limitation is used thataborts the search when reached.

3.1 Graph selection

Assume a set of SPG = { SPGi ∈ A, i = 1, . . . , n} is given together with thecomplete network G = (N,A) where SPGi ∈ A,∀i. If processing a pair ofgraphs SPGi and SPGj and succeeding in making them compatible and whenlater on processing SPGi and SPGn, how can it be assured that the previouswork of making SPGi and SPGj compatible isn’t destroyed in the currentupdate? The easiest way of assuring this is to process the graphs and to onlymodify one graph in the comparision. This means in each pairwise comparisionthere is one fix graph and one change graph where the fix graph is fixed (as thename indicates) and all modifications are made in the change graph.

So when iterating over all given SPGi the method is to let the fix index gofrom 1 to n−1 and then, in order (as illustrated in Figure 3.1), form Sfix,change =( SPGfix , SPGchange ) for all index change ∈ {fix + 1, . . . , n} and trying toresolve the conflicts for the pairs in order. When Sfix,change is made compatiblethe SPGchange is used to form Si,change∀i ∈ fix− 1, . . . , 1. If any cycle isfound for any Si,change the current change graph is not compatible against atleast one of the previously used fix graphs and the change graph needs to beupdated again, or, as in this heuristic, fail the algorithm. The reason for failingthe heuristic search in this step is to simplify it. Otherwise it will become toocomplex and it would be very possible that previously searched steps will berepeated. In this way the complexity of the comparasion would be O(n2). Thismeans when the change index has reached n and all pairs for the current fixgraph is compatible, the fix index is updated and the search continues. Whenthe fix index has reached n, all graphs are compatible. This means that the

11

Page 25: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

3.2. UPDATE METHOD

SPG1 SPG2

Fix Change

(a) First step in graph selection process

SPG1 SPGj

Fix Change

(b) j-th step in graph selection process

SPG1 SPGn

Fix Change

(c) Last step before fix index update

SPGi SPGj

Fix Change

(d) General update step

Figure 3.1: Example of how the index is selected when attempting to makegraphs compatible.

order in which the graphs are processed is of importance since the first graphin the process list will never be changed, and hence a randomization must beused (see section 3.5).

3.2 Update method

How should SPGi and SPGj be made compatible? Since there exists only amethod for finding a valid cycle and abort if one exists, this step must be builtupon that method. This means that an approach based on all valid cycles willnot be possible (and it would also be costful, see section 2.4), but only focuson rendering one valid cycle non-valid at a time and continue to search for newcycles (or previously existing ones). In Table 2.3 three ways of invalidating avalid cycle are presented and which one could be used in the heuristics? Sincethe selection of graphs and which one should be updated is already decided,only a smaller subset of actions are left to use. In order to choose method, adeeper analysis of the cycle itself is needed. When invalidating a valid cycle, thestructural features of the SPG should be kept in some sense. What this means isthat if the nodes ni and nj are connected in SPGa the connection is meaningfulbut how meaningful is determined by the in-degree for the origin node and theout-degree for the destination node for the given arc. The arcs can be classifiedinto four different types using the in-degree and out-degree for the origin anddestination node, given an arc. In order to simplify the text the in-degree (andincomming arcs) for the origin of a given arc will be called the in-degree (andincomming arcs) for the arc. The same is for the out-degree and outgoing arcs.This means that when talking about an arc, instead of writing “the incomminglinks from the origin of the arc” this is shortened as “the incomming links forthe arc” to increase readability. So, each arc is classified as one of the followingtypes:

This is illustrated in Figure 3.2.

12

Page 26: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

3.2. UPDATE METHOD

Type In-degree Out-degree

e1 0 0e2 > 0 0e3 0 > 0e4 > 0 > 0

Table 3.1: Table with descriptions of the arc types

i j

(a) Type e1. Arc considered to be re-quired for the graph.

i j

(b) Type e2. Important to keepconnection from ingoing nodes to ni

against node nj .

i j

(c) Type e2. Important to keep connec-tion between node ni and nodes con-neted by nj .

i j

(d) Type e4. The combination of thee2 and e3 type connections are to bekept.

Figure 3.2: Illustrations of the different types of arcs within a sp-graph. Theeligible arc for the examples is ai,j .

13

Page 27: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

3.3. REPLACING ARCS

3.3 Replacing arcs

When replacing an arc, the first thing is to categorize it into the correct category.This means when replacing arc ai,j ∈ SPGchange, how the replacement is doneshould be decided by the type of arc it is (see Table 3.1). For e1 types noreplacement is possible since it is considered to be required for the graph. Whenreplacing a type e2 arc, some more complicated methods must be used. Letthe arc ai,j ∈ SPGa be given where ai,j ∈ e2. Now define the origin nodesas O = {nk, ak,i ∈ SPGa ∀k}. Replacements for the arc ai,j should keepthe connections between all nodes in O and nj . Now, let rca,b be a requestto connect the nodes na and nb using some, for now, undefined path. Usingthe set O with origins a new set is formed with all requested connections asRC = {rck,j : nk ∈ O}. Each pair should now be processed, one at a time,and a search in the full network for paths pk,j connecting the current node-pairwithout the use of arc ai,j is conducted. Each path is then ranked accordingto how much the SPGa (at its current state) must be modified in order tointroduce it and this information is used for creating a set of ranked replacementpaths where each rank may contain multiple paths. For the ranked replacementpaths each rank is searched in increasing order and if a path is found, the nextrequested connection is processed, in the same way as described above. If novalid replacement path is found for the current requested pair, the path usedin the previous requested pair is discarded and next possible path is evaluated(either within the same rank or a new one). This is a form of DFS algorithmwhere each requested pair is having multiple choises of paths to introduce andthe cheapest one is always evaluated first. If the path is not leading to a solutionfor all requests the algorithm traverse backwards in the tree and keep searchingwhere available paths still exist. See Figure 3.3 for a illustration of this process.The reason for processing one request at a time is that if one path is added,parts of it may be used in the processing of the next request which is leading todiversing the paths in the graph, in some sense.

As illustrated in Figure 3.3 each request is processed in order and a binarysearch tree is created for each step. If a step does not lead to an existing pathfor a request, the node is removed and its parent is revisited for the next lowestranked path to test. If all requests have been processed and a path (in the tree)has been found, that path gives the the modifications to be performed in orderto replace the arc that is processed (note that a path in the tree is representing aset of paths to the graph). The arcs of type e3 are replaced in the same manneras in e2 but using the outgoing arcs from the arc to replace and all requestswill be formed by those instead. In order to replace a type e4 arc, the easiestway is to use the same type of reasoning and tree search as for type e2 and e3.In other words, to replace an arc of type e4 all incomming arcs’ origins shouldbe reconnected to the destination of the arc in question and the origin of thearc to replace should be reconnected to the destinations in all outgoing arcs.Then the tree search is performed in the same manner as for a single type e2and e3 replacement. See chapter 6 for comments on how this may be furtherinvestigated.

14

Page 28: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

3.3. REPLACING ARCS

SPG

rc11 rci1. . .

(a) First requested connection in thebinary search tree. Each leaf is repre-senting a path in the request rc1.

SPG

rc11

rc12 rcj2

rci1. . .

. . .

(b) Second requested connection in thebinary search tree where rc11 is beingevaluated.

SPG

rcm1

rc12 rcj2

rci1. . . . . .

. . . . . .

(c) General step in rc1 where alreadysearched paths in previous ranks havebeen discarded.

SPG

rcm1

rc12 rcn2

rc13 rck3

rcj2

rci1. . .

. . . . . . . . .

(d) Last step when processing the bi-nary tree search for three requests.

Figure 3.3: Illustration of the processing of requested connections. In the nodecurrently tested, each path is sorted according to rank, the lowest rank to theleft and highest to the right.

15

Page 29: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

3.4. ANALYSIS OF VALID CYCLES

3.4 Analysis of valid cycles

When conducting a deeper analysis of a valid cycle, some key differences for thecycles are noted. Let C = F ∪ B and let the set of eligible arcs be Ce = {ai,j :ai,j ∈ C, ai,j ∈ F, ai,j /∈ B or ai,j ∈ B, ai,j /∈ F}. The cycles may be classifiedinto different categories using information in which graph(s) the eligible arc(s)exist(s). Three classes are now identified: In the first class of cycles (C1) alleligible arcs are contained within the first graph (fix graph). The second class(C2) is defined as cycles where all eligible arcs are contained within the secondgraph (change graph) and the third class (C3) is a combination of the first two.The reason to perform classification using eligible arcs is because some differentapproaches are needed when invalidating the cycle for the different classes.

3.4.1 Eligible arcs

When studying eligible arcs in a valid cycle one thing can be noted. If the arcai,j ∈ SPGfix and aj,i ∈ SPGchange and a cycle is found where the nodes ni

and nj are detected as part of the cycle, both arcs will be considered to beeligible but in two different cycles. Why this may be worth noting it because ofthe following. Assume such a cycle (C1) is found using the VC method. Thecycle is invalidated using the eligible arc ai,j ( ∈ SPGfix, /∈ SPGchange). Whenchecking if the cycle has been invalidated the algorithm is returning the stronglyconnected components which is only the nodes included in the cycle (not theactual arcs). The same nodes are found and this seems to render the cycle hasnot been invalidated and the heuristics fails. However, the cycle C1 may verywell have been invalidated and the cycle C2 is now identified which includessame nodes as for cycle C1 but the arc aj,i is used instead of ai,j . So, it is ofgreat importance to make this distinction between the cycles using the arcs andnot the strongly connected components (the reson for this remark is that in theexternal file spgb.c the strongly connected component forming the valid cycleis returned. In the implementation of the heuristics this result is read and thearcs used in the cycle are determined).

3.4.2 C1 cycles

In order to invalidate a C1 cycle the only option is to add all eligible arcs in thecycle to the change graph. This will make all arcs non-eligible and the cycle willbecome non-improving which means it is broken. If the resulting change graphwill become cyclic (contains a directed cycle) when adding the eligible arcs, thegraph will not be valid (since a shortest path cannot contain a directed cycle)and it will not be possible to go further in the comparison and thus, the heuristichas failed. If just using a smaller set of the eligible arcs and adding them tothe change graph, the cycle will still contain eligible arcs and will still be valid.Hence all arcs must be added in order to invalidate the cycle.

3.4.3 C2 cycles

A cycle in this category has all eligible arcs within the change graph and inorder to invalidate such a cycle one of two actions can be taken. Either aneligible arc is removed or an arc is exchanged for another path. If the arc is

16

Page 30: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

3.5. RANDOMIZATION

removed a test must be done to see if the nodes still are connected. If it is thecase, the cycle is invalidated and if not, the arc must be exchanged. How thearc should be exchanged depends on what type of arc it is within the SP-graph,see Figure 3.2.

This means that when processing these cycles, one candidate at the time, thecandidate can either be removed or exchanged. If another path exists betweenthe nodes it can safely be removed and the cycle is invalidated (render somecompression of the structure of the graph). If another path does not exist, itmay be possible to exchange it for another path from the full network connectingthe nodes. Consider the arc ai,j to be part of a cycle within this class. Thearc is classified as one of the four types illustrated in Figure 3.2. If it is of typeone it cannot be used to invalidate the cycle (since no arcs are entering to nodeni and no arcs are leaving the node nj). But if it is of type two to four it canbe further processed. A type e2, e3 or e4 arc is invalidated using a DFS searchalgorithm for finding all paths between the nodes connected to node ni and thenode nj (see Figure 3.3) and when proper replacements have been found, thegraph is updated and the cycle will be invalidated. It is sufficient to invalidatethe cycle successfully by removing or replacing only one eligible arc since it willrender the cycle infeasible.

3.4.4 C3 cycles

This is the last classification of the valid cycles and in order to invalidate thoseonly the eligible arcs in the SPGchange will be considered. To realize why thisis nesessary concider the following. Let a cycle C ∈ C3 be given as well asthe set of eligible arcs in SPGfix, SPGe

fix, and the eligible arcs in SPGchange,SPGe

change. The cycle is formed by the arcs SPGefix, SPGe

change and possiblymore arcs (not eligible ones). If adding the set of arcs SPGe

fix to SPGchange,the cycle will be formed by the arcs SPGe

change and (at least) the arcs justadded to the SPGchange. This would mean that the cycle is still improving andfeasible, which means that it is still valid. So, the only option will be to usethe same methods as for the C2 cycles (since the SPGfix is not allowed to bemodified at this stage).

3.5 Randomization

Since looping over a set of SPG with the above given properties and conditionswould give different results if reading the graphs in a different order, a random-ization flag is added to the heuristics. This will tell whether the graphs shouldhave the same index as the order they are input in or if some randomizationshould be applied before starting the heuristics. A randomization is also intro-duced in the ordering of the candidates list. The reason for this it that for agiven cycle C the candidates list Cchange will be processed in the same orderwhen having the same SPGfix and SPGchange and if that order does not leadto a solution the heuristic search will never converge to compatible SP-grahps.The same logic is applied to the DFS algorithm when searching for replace-ments that yields the same cost and hence, a randomization is introduced whenchoosing the minimum cost replacement for a requested connection.

17

Page 31: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

3.6. FULL SPECIFICATION

3.6 Full specification

Using the graph selection presented in section 3.1 together with the cycle clas-sification (section 3.4) and the update methods (section 3.2) a full heuristicspecification can be specified as Figure 3.4 and Figure 3.5 illustrates.

In the step named start in Figure 3.4 all graphs are read and the network touse together with a timelimit for stoping the search when timeout. Note thatthe compatible test in Figure 3.4 is to test the current change graph against allprevious fix graphs.

18

Page 32: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

3.6. FULL SPECIFICATION

Start

FI=0, CI=1,timer=0

FI++

FI == N?

CI++

CI==N+1?

Make graphscompatible

Compatible?

All graphscompatible

Heuristics failed

no

yes

no

yes

no

yes

Figure 3.4: Flowchart over the heuristics design. The flowchart and descriptionof the block named “make graphs compatible” is described in Figure 3.5. FIand CI is the fix- and change index used and N is the amount of SP-graphs.

19

Page 33: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

3.6. FULL SPECIFICATION

VC?

Timelimit?

Read cycle

Classify cycle

ResolveC2 and C3

Resolve C1

VC broken?

Heuristic fail

return

yes

no

C1 C2, C3

no

yes

yes

no

Figure 3.5: Flowchart for making a pair of graphs compatible. The C1 resolvemethod is described in Figure 3.6 and the C2 and C3 methods are described inFigure 3.7.

20

Page 34: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

3.6. FULL SPECIFICATION

Add?

Set fail

no

yes

Figure 3.6: Flow illustrating how a C1 cycle is invalidated.

21

Page 35: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

3.6. FULL SPECIFICATION

Read eligible arcsfrom SPGchange

to candidates list

Empty?

Select one candidate

Classify arc

Make dfssearch for

replacements

Replacement?Graphs notcompatible.

Return

no

e1

other

yes

no

yes

Figure 3.7: Flow illustrating how a C2 cycle is invalidated. Note that the stepof making search for replacements is described in section 3.3 and will not beincluded here.

22

Page 36: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

Chapter 4

Heuristics performance

The heuristic has undergone some performance measures in order to be able totell something about the convergence of the same. The networks used have beenprovided by Kaj Holmberg.

4.1 Full example

In this first example, a full presentation of the updates in each step can befound, but the search for ranked replacement paths are excluded from the ex-ample. Consider the two SP-graphs SPG1 = {(0, 1), (0, 2), (0, 5), (1, 3), (2, 4)}and SPG2 = {(0, 5), (1, 4), (2, 3), (3, 5), (4, 5)} which are illustrated in Figure 4.1.The underlying network for the SP-graphs is a complete network with 5 nodes.

0

1

2

3

4

5

(a) SPG1

0

1

2

3

4

5

(b) SPG2

Figure 4.1: Two SP-graphs to make compatible.

In the first step, one of the graphs is considered to be fix and the othersubject for modification. In this example the SPG1 is considered fix and SPG2

the graph where modifications are to be performed. The cycle found is consistingof the links {(1, 4), (1, 3), (2, 4), (2, 3)} and is classified to as type C3. The eligiblearcs are {(1, 4), (2, 3)} and the first candidate to be processed is (1, 4). In thisstep the only path to find an alternetive route for is p = {(1, 4), (4, 5)} whichmeans that the heuristic search will try to connect the nodes 1 and 5 in a waynot using (1, 4). The request for connections will be {(1, 5)} (since there existsno other path between the nodes in the SPG2, it cannot be simply removed).This request is processed within the complete network and all paths are rankedaccording to the cost to introduce them in the SPG2. The path selected by theheuristic is {(1, 5)}. When this arc is introduced the current cycle is broken and

23

Page 37: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

4.2. PERFORMANCE MEASURES

a new test for valid cycles is performed. Since no other cycles exist, the graphsare now compatible. The compatible graphs can be seen in Figure 4.2.

0

1

2

3

4

5

(a) SPG1

0

1

2

3

4

5

(b) SPG2 after modifications

Figure 4.2: The two graphs when compatible.

As seen in this example, the structure for SPG2 is kept as the nodes 1 and5 are still connected in the change graph after the modifications as well as theconnection between nodes 4 and 5.

4.2 Performance measures

In Table 4.1 some performance measures of the algorithm are provided for anumber of test runs. All graphs have been processed 10 times and the fullnetwork for each example is a complete network. That is, all nodes are connectedto each other. It is worth noting that each setup of SP-graphs are successfullymade compatible. The main reason for this is that the search is exhaustiveand there is only 5 SP-graphs in each setup, leading to many possibilities forconvergence. If there would be more graphs in the tests, the convergence rate isexpected to go down a bit, depending on the structure of the graphs of course.

It is worth noting that there are some examples with networks containing100 and more nodes (not included in Table 4.1) but they are crashing sincethe DFS algorithm implemented for finding alternative paths between nodesare taking too long. Also, some sp-graphs with 50 nodes are leading to a crashbut not all (as seen in the table). This is depending on the size of the sp-graphs in the files (the arc-count of each graph). When running the algorithmthe convergence times are relatively short. It spans from about 1-3 secondsto approximately 35-45 seconds, depending on the sp-graphs used. So it is arelatively fast convergence on the heuristic itself.

24

Page 38: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

4.2. PERFORMANCE MEASURES

File N pass fail avg changesnexa01.spg 10 10 0 47nexa02.spg 10 10 0 48nexa03.spg 10 10 0 44nexa04.spg 10 10 0 43nexa05.spg 10 10 0 56nexa06.spg 10 10 0 52nexa07.spg 10 10 0 71nexa08.spg 10 10 0 54nexa09.spg 10 10 0 50nexa10.spg 10 10 0 56nexa11.spg 10 10 0 55nexa12.spg 10 10 0 68nexa13.spg 10 10 0 56nexa14.spg 10 10 0 54nexa15.spg 10 10 0 51nexa16.spg 10 10 0 58nexa17.spg 10 10 0 49nexa18.spg 10 10 0 59nexa19.spg 10 10 0 58nexa20.spg 10 10 0 47nexb01.spg 30 10 0 360nexb02.spg 30 10 0 371nexb03.spg 30 10 0 354nexb04.spg 30 10 0 348nexb05.spg 30 10 0 385nexb06.spg 30 10 0 353nexb07.spg 30 10 0 360nexb08.spg 30 10 0 380nexb09.spg 30 10 0 341nexb10.spg 30 10 0 377nexc01.spg 50 10 0 798nexc02.spg 50 10 0 810nexc03.spg 50 10 0 728nexc04.spg 50 10 0 768nexc05.spg 50 10 0 798nexc06.spg 50 10 0 819nexc07.spg 50 10 0 793nexc08.spg 50 10 0 782nexc09.spg 50 10 0 774nexc10.spg 50 10 0 817

Table 4.1: Table over algorithm performance. N is the amount of nodes and inall files, only 5 SPG exists.

25

Page 39: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

4.2. PERFORMANCE MEASURES

26

Page 40: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

Chapter 5

Summary and conclusions

When designing IP-networks using the current approach, the network admin-istrator will not be able to tell how the traffic will be routed in the networkaccording to the ECMP- and OSPF-principles until the shortest paths are cal-culated. This will make it hard to determine where possible bottlenecks willappear and where reinforcements must be done in the network structure.

The findings in this thesis show that it would be possible to design thenetwork using desired routing patterns and combining them using a heuristicapproach to design a network. The approach used in this thesis to keep thestructure of the SP-graphs (in some sense) and invalidating valid cycles oneat a time to make the SP-graphs compatible, seems to work well for smallernetworks. Up to about 30 nodes seem to work very good and in every test allSP-graphs are made compatible within the given timelimit. The test cases arenot representative for use cases but generated for containing valid cycles, sosome more investigation and further studies need to be conducted before it ispossible to tell whether this approach can be useful.

27

Page 41: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

28

Page 42: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

Chapter 6

Future work

To be able to design a better heuristic for invalidating valid cycles and mak-ing SP-graphs compatible a deeper and more thourough analysis of the cyclesand how to invalidate them could be conducted. The reason it has not beenincluded in this thesis is because of the time limitation for this work and alsothat the analysis here is based upon the graph selection pattern, as described insection 3.1. If the graph selection is changed, the possibility of another analysisof the structure of the cycle may be conducted and more interesting findingsmay come up. Another solution method would be to explore the possibility toperform modifications in both graphs where a valid cycle exist and not make theresult depending on the order in which the graphs are processed. It would alsobe good to be able to define a function measuring how compatible the completeset of SP-graphs are without having to calculate the valid cycles.

When updating the SPGchange a DFS search is performed in the completenetwork for finding all paths in order to reconnect a node-pair. The resultingpaths are ranked and then searched in increasing rank for finding a suitablematch within a lowest possible rank. This means however that for each node-pair to reconnect, a new DFS search will be conducted and processed to keepthe changes in some minimal way. This could be updated to use an algorithmthat searches for possible paths and when one is found it is returned and tested.If the path should not be ok when further processing the tested (and discarded)paths should be excluded in the new search for a path connecting the node-pair.I believe that this is the main reason why the heuristics is failing at the currentstate where there is about 50 nodes or more in the network. There are too manypaths to keep track of all at that magnitude.

In this thesis, when replacing an arc of type e4, the requested connectionsare made up of the origins for the incomming arcs and the destination of thearc to replace together with the origin of the arc to replace together with thedestinations of the outgoing arcs. It would be interesting to see how the resultswill change if the requested connections instead would be made up of all sourcesfor the incomming arcs against all destinations in the outgoing arcs. How thiswould affect the performance is not determined yet.

29

Page 43: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

30

Page 44: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

Bibliography

[1] Brostrom, P. and Holmberg, K., “Compatible Weights and Valid Cycles inNon-spanning OSPF Routing Patterns”. In Brostrom’s PhD dissertation:Optimization Models and Methods for Telecommunication Networks usingOSPF 2006. Linkoping Studies in Science and Technology. DissertationsNo. 1032

[2] Brostrom P and Holmberg K. Compatible Weights andValid Cycles in Non-spanning OSPF Routing Patterns, Al-gorithmic Operations Research volume 4 (2009): 19-35,https://journals.lib.unb.ca/index.php/AOR/article/view/4175 (fetched2015-06-17)

[3] Brostrom, P. and Holmberg, K., “Valid Cycles: A Source of Infeasibility inOSPF Routing”. In Brostrom’s PhD dissertation: Optimization Models andMethods for Telecommunication Networks using OSPF 2006. LinkopingStudies in Science and Technology. Dissertations No. 1032

[4] Brostrom P and Holmberg K. Valid Cycles: A Source of Infeasi-bility in OSPF Routing, Networks volume 52 (2008): 206-215, doi:10.1002/net.20232

Note: The sources [3] and [1] have been used but for readers to find thesources easier the source [4] and [2] has been added

31

Page 45: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

BIBLIOGRAPHY

32

Page 46: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

Appendix A

Source code

All implementations has been made in c++ using emacs and building hasbeen made using cmake. The unit testing framework used is UnitTest++ (seehttps://github.com/unittest-cpp, 2015-06-04). The files listed here are the mainsource files, containing the most important runtime routines. A complete set ofsource files is far too large to include.

33

Page 47: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

#include <s t r i ng>#include <c l i m i t s >#include <fstream>#include <sys / s t a t . h>

#include ”MakeSpgCompatibleCommandLineApplication . hpp”#include ”LogModule . hpp”#include ”CommandLineOptionDefaultValue . hpp”#include ”CommandLineOptions . hpp”#include ”MakeSpgCompatible . hpp”#include ” NetworkFi leParser . hpp”#include ”Graph . hpp”#include ”Link . hpp”#include ”CommonDef . hpp”

MakeSpgCompatibleCommandLineApplication : : MakeSpgCompatibleCommandLineApplication ( ): CommandLineApplication ( ”Make SPG Compatible” , 1 , 0 , fa l se )

{fu l lNetworkFi l eOpt ion = new CommandLineOptionDefaultValue<s t r i ng >({ ”−− f u l l −network− f i l e ” , ”−f ” } ,”Path to f i l e d e s c r i b i n g f u l l network” ,”” ) ;

spgNetworkFileOption = new CommandLineOptionDefaultValue<s t r i ng >({ ”−−spg− f i l e ” , ”−spg” } ,”Path to f i l e d e s c r i b i n g the SP graphs ” ,”” ) ;

maxCalculationTimeOption = new CommandLineOptionDefaultValue<int>({ ”−−max−c a l c u l a t i o n−time ” , ”−t ” } ,” Timel imit in seconds ” ,INT MAX) ;

generateFul lNetworkOption = new CommandLineOptionFlag ({ ”−−generate−f u l l −network” , ”−g” } ,” Generate f u l l network” ) ;

randomizeOrderOption = new CommandLineOptionFlag ({ ”−−randomize ” , ”−r ” } ,”Use the randomizat ion f l a g f o r graphs , cand idate s and v a l i d replacement paths ” ) ;

logLeve lOpt ion = new CommandLineOptionDefaultValue<s t r i ng >({ ”−−log−l e v e l ” , ”− l e v e l ” } ,” Leve l o f l ogg ing : One o f ’Debug ’ , ’ I n f o ’ , ’ Warning ’ , ’ Error ’ ” ,” In f o ” ) ;

r e s u l t F i l e O p t i o n = new CommandLineOptionDefaultValue<s t r i ng >({ ”−−r e s u l t− f i l e ” } ,”Name o f the r e s u l t f i l e ” ,” a lgor i thm per formance . r e s ” ) ;

i t e r a t i o n s O p t i o n = new CommandLineOptionDefaultValue<int>({ ”−− i t e r a t i o n s ” } ,”The amount o f i t e r a t i o n s to use f o r performance measurement” ,1 ) ;

dumpEachStepOption = new CommandLineOptionFlag ({”−−dump−each−s tep ” } ,

34

Page 48: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

”Output each compatible s tep o f the proce s s to an output f i l e ” ) ;outputPathOption = new CommandLineOptionDefaultValue<s t r i ng >({”−−output−path” } ,”Path to where a l l output should be placed ” , ” . ” ) ;

this−>opt ions . push back ( fu l lNetworkFi l eOpt ion ) ;this−>opt ions . push back ( spgNetworkFileOption ) ;this−>opt ions . push back ( maxCalculationTimeOption ) ;this−>opt ions . push back ( generateFul lNetworkOption ) ;this−>opt ions . push back ( randomizeOrderOption ) ;this−>opt ions . push back ( logLeve lOpt ion ) ;this−>opt ions . push back ( r e s u l t F i l e O p t i o n ) ;this−>opt ions . push back ( i t e r a t i o n s O p t i o n ) ;this−>opt ions . push back ( dumpEachStepOption ) ;this−>opt ions . push back ( outputPathOption ) ;

}

MakeSpgCompatibleCommandLineApplication : : ˜ MakeSpgCompatibleCommandLineApplication ( ){

delete fu l lNetworkFi l eOpt ion ;delete spgNetworkFileOption ;delete maxCalculationTimeOption ;delete generateFul lNetworkOption ;delete randomizeOrderOption ;delete logLeve lOpt ion ;delete r e s u l t F i l e O p t i o n ;delete i t e r a t i o n s O p t i o n ;delete dumpEachStepOption ;delete outputPathOption ;

}

s t r i n g MakeSpgCompatibleCommandLineApplication : : GetDescr ipt ion ( ){

return std : : s t r i n g ( ”The program i s us ing an h e u r i s t i c f o r t ry ing to make a s e t o f SP−graphs ” ) +” compatible with each other search f o r a s t r u c t u r e c a l l e d a ’ v a l i d c y c l e ’ ” +”and i f one e x i s t s , t r y ing to modify the graphs in a s m a l l e s t p o s s i b l e way ” +” to make them compatible ( in the sense that compatible weights MIGHT e x i s t . ” +” This i s an implementation c reated by Andreas Lindblad f o r h i s master t h e s i s ” +

” at MAI, LinkA¶ping Un ive r s i ty . ” ;}

void MakeSpgCompatibleCommandLineApplication : :Process ( std : : vector<std : : pa ir<ICommandLineOption ∗ , s td : : s t r i ng>> optionValues ,

s td : : vector<std : : s t r i ng> UNUSED( args ) ){

i f ( opt ionValues . s i z e ( ) == 0) {l o gge r−>In f o ( ”Use −−help f o r usage ” ) ;

35

Page 49: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

return ;}

s t r i n g fu l lNe tworkF i l e = fu l lNetworkFi l eOpt ion−>GetValue ( opt ionValues ) ;s t r i n g spgF i l e = spgNetworkFileOption−>GetValue ( opt ionValues ) ;int maxCalculationTime = maxCalculationTimeOption−>GetValue ( opt ionValues ) ;bool generateFul lNetwork = generateFullNetworkOption−>GetValue ( opt ionValues ) ;bool randomize = randomizeOrderOption−>GetValue ( opt ionValues ) ;s t r i n g l ogLeve l = logLevelOption−>GetValue ( opt ionValues ) ;

s t r i n g r e s u l t F i l e = re su l tF i l eOpt i on−>GetValue ( opt ionValues ) ;int i t e r a t i o n s = i t e ra t i on sOpt i on−>GetValue ( opt ionValues ) ;

bool dumpEachStep = dumpEachStepOption−>GetValue ( opt ionValues ) ;s t r i n g outputPath = outputPathOption−>GetValue ( opt ionValues ) ;

i f ( spgF i l e . compare ( ”” ) == 0) {l o gge r−>Error ( ”No spg f i l e used as input . Use −−help f o r usage ! ” ) ;

return ;} else i f ( ! NetworkFi leParser : : F i l e E x i s t ( spgF i l e ) ) {

l o gge r−>Error ( ”Could not l o c a t e spg f i l e ” + spgF i l e + ” ! ” ) ;return ;

}

i f ( f u l lNe tworkF i l e . compare ( ”” ) != 0) {i f ( ! NetworkFi leParser : : F i l e E x i s t ( f u l lNe tworkF i l e ) ) {

l o gge r−>Error ( ”Could not l o c a t e f u l l network f i l e ” + fu l lNe tworkF i l e + ” ! ” ) ;return ;

}}

i f ( outputPath . subs t r ( outputPath . s i z e ( ) − 1 ) . compare ( ”/” ) != 0) {outputPath += ”/” ;

}

mode t process mask = umask ( 0 ) ;mkdir ( outputPath . c s t r ( ) , S IRWXU | S IRWXG | S IRWXO) ;umask ( process mask ) ;

LogLevel l e v e l =logLeve l . compare ( ”Debug” ) == 0 ? LogLevel : : Debug :l ogLeve l . compare ( ” In f o ” ) == 0 ? LogLevel : : I n f o :l ogLeve l . compare ( ”Warning” ) == 0 ? LogLevel : : Warning :l ogLeve l . compare ( ” Error ” ) == 0 ? LogLevel : : Error :LogLevel : : I n f o ;

l ogge r−>SetLeve l ( l e v e l ) ;

MakeSpgCompatible∗ a lgor i thm =new MakeSpgCompatible ( maxCalculationTime ,

36

Page 50: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

randomize ,generateFul lNetwork ,l ogge r ,

outputPath ) ;int pass = 0 ;int f a i l = 0 ;int timeLimitReached = 0 ;int changes = 0 ;

for ( int i = 0 ; i < i t e r a t i o n s ; ++i ) {l o gge r−>In f o ( ” I t e r a t i o n ” + t o s t r i n g ( i + 1) + ” o f ” + t o s t r i n g ( i t e r a t i o n s ) ) ;l o gge r−>In f o ( ”−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−” ) ;

i f ( f u l lNe tworkF i l e . compare ( ”” ) == 0) {algor ithm−>I n i t i a l i z e F r o m S p g F i l e ( spgF i l e ) ;

}else {

algor ithm−>I n i t i a l i z e F r o m F i l e s ( fu l lNetworkF i l e , spgF i l e ) ;}Algor ithmStatus s t a t u s = algor ithm−>RunAlgorithm ( dumpEachStep ) ;

i f ( s t a t u s == Algor ithmStatus : : Compatible ) {pass++;changes += algorithm−>GetTota lModi f i cat ions ( ) ;

}else i f ( s t a t u s == Algor ithmStatus : : TimeLimitReached ) {

timeLimitReached++;}else {

f a i l ++;}

}

delete a lgor i thm ;

s t r i n g r e s F i l e = outputPath + r e s u l t F i l e ;i f ( r e s F i l e . compare ( ”” ) != 0) {

i f ( ! NetworkFi leParser : : F i l e E x i s t ( r e s F i l e ) ) {ofstream o ;o . open ( r e s F i l e ) ;o << ” F i l e & i t e r a t i o n s & time l i m i t & pass & f a i l & max time reached & avg changes \\” << endl ;o << ”\\ h l i n e ” << endl ;o . c l o s e ( ) ;

}ofstream output ;output . open ( r e s F i l e , s td : : o f s tream : : app ) ;output <<

spgF i l e + ” & ” +t o s t r i n g ( i t e r a t i o n s ) + ” & ” +t o s t r i n g ( maxCalculationTime ) + ” & ” +t o s t r i n g ( pass ) + ” & ” +

37

Page 51: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

t o s t r i n g ( f a i l ) + ” & ” +t o s t r i n g ( changes / pass ) << endl ;

output . c l o s e ( ) ;}

}

38

Page 52: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

#include <fstream>#include <sys / s t a t . h>

#include ”MakeSpgCompatible . hpp”#include ”MakeCompatible . hpp”#include ”Graph . hpp”#include ”Link . hpp”#include ”Node . hpp”#include ”Timer . hpp”#include ”VectorMethods . hpp”#include ”MakeCompatible . hpp”#include ”AlgorithmType . hpp”#include ” Algor ithmStatus . hpp”#include ”MainIndexLoop . hpp”#include ”SpgbCommunication . hpp”#include ”MakeSpgCompatibleException . hpp”#include ” NetworkFi leParser . hpp”#include ”LogModule . hpp”

using std : : f o r e a c h ;

s t r i n g MakeSpgCompatible : : GraphToString ( const Graph∗ g ) {return MakeSpgCompatible : : LinksToStr ing (g−>GetLinks ( ) ) ;

}

s t r i n g MakeSpgCompatible : : LinksToStr ing ( const vector<Link∗> &l i n k s ) {vector<s t r i ng> s t r l i n k s ;s t r l i n k s . r e s i z e ( l i n k s . s i z e ( ) ) ;t rans form ( l i n k s . begin ( ) ,

l i n k s . end ( ) ,s t r l i n k s . begin ( ) ,[&] ( Link∗ l ) { return l−>ToString ( ) ; } ) ;

return MakeSpgCompatible : : Aggregate ( s t r l i n k s ) ;}

s t r i n g MakeSpgCompatible : : LinksSpecToStr ing ( const vector<pair<int , int>> &l i n k s ) {vector<s t r i ng> s t r l i n k s ;s t r l i n k s . r e s i z e ( l i n k s . s i z e ( ) ) ;t rans form ( l i n k s . begin ( ) ,

l i n k s . end ( ) ,s t r l i n k s . begin ( ) ,[&] ( pair<int , int> l ){

return t o s t r i n g ( l . f i r s t ) + ”−>” + t o s t r i n g ( l . second ) ;} ) ;

return MakeSpgCompatible : : Aggregate ( s t r l i n k s ) ;}

s t r i n g MakeSpgCompatible : : NodesToString ( const vector<Node∗> &nodes ) {

39

Page 53: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

vector<s t r i ng> s t rnodes ;s t rnodes . r e s i z e ( nodes . s i z e ( ) ) ;t rans form ( nodes . begin ( ) ,

nodes . end ( ) ,s t rnodes . begin ( ) ,[&] (Node∗ n) { return t o s t r i n g (n−>GetIndex ( ) ) ; } ) ;

return MakeSpgCompatible : : Aggregate ( s t rnodes ) ;}

s t r i n g MakeSpgCompatible : : Aggregate ( const vector<s t r i ng> &v ) {return VectorMethods<s t r i ng > : : Aggregate (v ,

[&] ( s t r i n g s1 , s t r i n g s2 ) {return s1 + ” , ” + s2 ;

} ) ;}

MakeSpgCompatible : : MakeSpgCompatible ( int maxCalculationTime ,bool randomize ,bool generateFul lNetwork ,LogModule∗ l ogger ,s t r i n g outputPath ) {

this−>t imer = new Timer ( maxCalculationTime ) ;this−>randomize = randomize ;this−>compat ib leSpgFi le = ” compat ib le spg . net ” ;this−>l o g g e r = l o g g e r ;this−>l e v e l = l e v e l ;this−>generateFul lNetwork = generateFul lNetwork ;this−>outputPath = outputPath ;

}

MakeSpgCompatible : : ˜ MakeSpgCompatible ( ) {delete t imer ;delete fu l lNetwork ;f o r e a c h ( spGraphs . begin ( ) ,

spGraphs . end ( ) ,[ ] ( Graph∗ spg ){

delete spg ;} ) ;

spGraphs . c l e a r ( ) ;}

void MakeSpgCompatible : : I n i t i a l i z e F r o m S p g F i l e ( s t r i n g spgF i l e ) {vector<vector<pair<int , int>>> spgLinks =

NetworkFi leParser : : ReadSpgFile ( spgF i l e ) ;

this−>fu l lNetwork = new Graph ( generateFul lNetwork ) ;i f ( generateFul lNetwork ) {

40

Page 54: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

this−>fu l lNetwork−>GenerateFromNodes ( SpgSpec i f i cat ionToNodes ( spgLinks ) ) ;}else {

this−>fu l lNetwork−>AddLink ( SpgSpec i f i c a t i onToFu l l ( spgLinks ) ) ;}this−>spGraphs = ParseSpgLinks ( spgLinks ) ;

}

void MakeSpgCompatible : : I n i t i a l i z e F r o m F i l e s ( s t r i n g fu l lNetworkF i l e ,s t r i n g spgF i l e ) {

vector<vector<pair<int , int>>> spgLinks =NetworkFi leParser : : ReadSpgFile ( spgF i l e ) ;

this−>spGraphs = ParseSpgLinks ( spgLinks ) ;

this−>fu l lNetwork = new Graph ( generateFul lNetwork ) ;vector<pair<int , int> > fu l lNetworkLinks =

NetworkFi leParser : : ReadFullNetworkFile ( f u l lNe tworkF i l e ) ;this−>fu l lNetwork−>AddLink ( fu l lNetworkLinks ) ;

}

Algor ithmStatus MakeSpgCompatible : : RunAlgorithm ( bool dumpEachStep ) {t o t a l M o d i f i c a t i o n s = 0 ;

currentPath = NetworkFi leParser : : AppendCurrentTime ( outputPath ) ;NetworkFi leParser : : CreateDir ( currentPath ) ;

Algor ithmStatus s t a t u s = Algor ithmStatus : : Compatible ;MakeCompatible∗ comp =

new MakeCompatible ( this−>fu l lNetwork ,timer ,this−>l ogger ,this−>randomize ,AlgorithmType : : Random ) ;

comp−>SetOutputPath ( currentPath ) ;MainIndexLoop∗ loop = new MainIndexLoop ( spGraphs . s i z e ( ) ) ;timer−>Star t ( ) ;int s tep = −1;while ( loop−>Update ( ) && s t a t u s == Algor ithmStatus : : Compatible ) {

comp−>SetGraphs ( spGraphs . at ( loop−>GetFixIndex ( ) ) ,spGraphs . at ( loop−>GetChangeIndex ( ) ) ) ;

l ogger−>Debug( ”Graph index : ” + t o s t r i n g ( loop−>GetFixIndex ( ) ) +” and ” + t o s t r i n g ( loop−>GetChangeIndex ( ) ) ) ;

s t a t u s = comp−>RunAlgorithm(++step , dumpEachStep ) ;

i f ( s t a t u s == Algor ithmStatus : : Compatible ) {l ogger−>Debug( ”Fix graph : ” +

GraphToString ( spGraphs . at ( loop−>GetFixIndex ( ) ) ) ) ;l ogger−>Debug( ”Compatible change graph : ” +

GraphToString ( spGraphs . at ( loop−>GetChangeIndex ( ) ) ) ) ;

41

Page 55: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

l ogger−>In f o ( s t r i n g ( ”Graphs compatible . ” ) +” Test ing change graphs aga in s t prev ious f i x graphs ” ) ;

SpgbCommunication∗ spgb = comp−>GetSpgb ( ) ;spgb−>SetChangeGraph ( spGraphs . at ( loop−>GetChangeIndex ( ) ) ) ;for ( int i = loop−>GetFixIndex ( ) −1; i > 0 ; −− i ) {

spgb−>SetFixGraph ( spGraphs . at ( i ) ) ;i f ( spgb−>Val idCyc leExi s t ( ) ) {

l ogger−>Debug( ”Chage graph not compatible aga in s t ” +GraphToString ( spGraphs . at ( i ) ) ) ;

const vector<Link∗> c y c l e = spgb−>GetCycle ( ) ;l ogger−>Debug( ” Val id c y c l e : ” + LinksToStr ing ( c y c l e ) ) ;s t a t u s = AlgorithmStatus : : NotCompatible ;

}}

i f ( s t a t u s == Algor ithmStatus : : Compatible ) {l ogger−>In f o ( ”Change graph m o d i f i c a t i o n s : ” + t o s t r i n g (comp−>GetModi f i cat ions ( ) ) ) ;t o t a l M o d i f i c a t i o n s += comp−>GetModi f i cat ions ( ) ;

}}

}timer−>Stop ( ) ;

i f ( s t a t u s == Algor ithmStatus : : Compatible ) {l ogger−>In f o ( ” Al l graphs compatible . Writing r e s u l t to f i l e . ” ) ;l ogger−>In f o ( ” Total amount o f m o d i f i c a t i o n s made : ” + t o s t r i n g ( t o t a l M o d i f i c a t i o n s ) ) ;WriteGraphsToFile ( ) ;

}else {

l ogger−>In f o ( ” H e u r i s t i c search f a i l ” ) ;}

delete loop ;delete comp ;

return s t a t u s ;}

int MakeSpgCompatible : : GetTota lModi f i cat ions ( ) {return t o t a l M o d i f i c a t i o n s ;

}

vector<Graph∗> MakeSpgCompatible : : ParseSpgLinks ( vector<vector<pair<int , int>>> spgLinks ) {vector<Graph∗> spg ;f o r e a c h ( spgLinks . begin ( ) ,

spgLinks . end ( ) ,[&] ( vector<pair<int , int>> l i n k s ){

Graph∗ g = new Graph ( fa l se ) ;

42

Page 56: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

g−>AddLink ( l i n k s ) ;spg . push back ( g ) ;

} ) ;

return this−>randomize ? VectorMethods<Graph∗> : : Randomize ( spg ) : spg ;}

vector<pair<int , int>>MakeSpgCompatible : : SpgSpec i f i c a t i onToFu l l ( vector<vector<pair<int , int>>> spgLinks ) {

vector<pair<int , int>> a l l L i n k s ;f o r e a c h ( spgLinks . begin ( ) ,

spgLinks . end ( ) ,[&] ( vector<pair<int , int>> spg ){

f o r e a c h ( spg . begin ( ) ,spg . end ( ) ,[&] ( pair<int , int> l i n k ){

i f ( ! VectorMethods<pair<int , int >>::Contains ( a l lL ink s ,

l ink ,[&] ( pair<int , int> l1 , pair<int , int> l 2 ){

return l 1 . f i r s t == l 2 . f i r s t && l 1 . second == l 2 . second ;} ) ) {

a l l L i n k s . push back ( l i n k ) ;}

} ) ;} ) ;

return a l l L i n k s ;}

vector<int> MakeSpgCompatible : : SpgSpec i f i cat ionToNodes ( vector<vector<pair<int , int>>> spgLinks ) {vector<int> nodes ;f o r e a c h ( spgLinks . begin ( ) ,

spgLinks . end ( ) ,[&] ( vector<pair<int , int>> spg ){

f o r e a c h ( spg . begin ( ) ,spg . end ( ) ,[&] ( pair<int , int> l i n k ){

i f ( ! VectorMethods<int > : : Contains ( nodes , l i n k . f i r s t ) ) {nodes . push back ( l i n k . f i r s t ) ;

}i f ( ! VectorMethods<int > : : Contains ( nodes , l i n k . second ) ) {

nodes . push back ( l i n k . second ) ;}

43

Page 57: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

} ) ;} ) ;

vector<s t r i ng> s t rn ;f o r e a c h ( nodes . begin ( ) ,

nodes . end ( ) ,[&] ( int i ){

s t rn . push back ( t o s t r i n g ( i ) ) ;} ) ;

l ogger−>Debug( ”Node numbers : ” +VectorMethods<s t r i ng > : : Aggregate ( strn ,

[&] ( s t r i n g s1 , s t r i n g s2 ){

return s1 + ” , ” + s2 ;} ) ) ;

return nodes ;}

void MakeSpgCompatible : : WriteGraphsToFile ( ) {s t r i n g outputF i l e = currentPath + compat ib leSpgFi l e ;o f s tream graphFi l e ;g raphFi l e . open ( outputF i l e ) ;g raphFi l e << spGraphs . s i z e ( ) << endl ;for (auto i t = spGraphs . begin ( ) ; i t != spGraphs . end ( ) ; ++i t ) {

NetworkFi leParser : : WriteGraphToFile ( graphFi le , ∗ i t ) ;}graphFi l e . c l o s e ( ) ;

}

44

Page 58: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

#include <ctime>#include <fstream>#include ”MakeCompatible . hpp”#include ”MakeSpgCompatible . hpp”#include ”SpgbCommunication . hpp”#include ”MakeSpgCompatibleException . hpp”#include ”Timer . hpp”#include ”Graph . hpp”#include ”Link . hpp”#include ”Node . hpp”#include ”VectorMethods . hpp”#include ” Di jks t rasAlgor i thm . hpp”#include ” TarjansAlgorithm . hpp”#include ” NetworkSearchAlgorithms . hpp”#include ” NetworkFi leParser . hpp”#include ”LogModule . hpp”#include ” Logging . hpp”

using std : : t rans form ;using std : : f o r e a c h ;using std : : o f s tream ;

/∗============================================================================∗∗ c t o r and dtor∗∗============================================================================∗/

MakeCompatible : : MakeCompatible ( Graph∗ fu l lNetwork ,Timer∗ timer ,bool randomize ,AlgorithmType type ,LogLevel l e v e l ) :

MakeCompatible ( fu l lNetwork , timer , Logging : : DisplayLogger ( ) , randomize , type ){

this−>l ogger−>SetLeve l ( l e v e l ) ;}

MakeCompatible : : MakeCompatible ( Graph∗ fu l lNetwork ,Timer∗ timer ,LogModule∗ l ogger ,bool randomize ,AlgorithmType type ) {

this−>t imer = timer ;this−>fu l lNetwork = fu l lNetwork ;this−>l o g g e r = l o g g e r ;this−>spgb = new SpgbCommunication ( fu l lNetwork , l o g g e r ) ;this−>randomize = randomize ;this−>a lgor i thm = type ;

45

Page 59: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

nodeIndexOf fset = 0 ;auto nodes = ful lNetwork−>GetNodes ( ) ;vector<int> nodeIndex ( nodes . s i z e ( ) ) ;f o r e a c h ( nodes . begin ( ) , nodes . end ( ) ,

[&] (Node∗ n){

i f (n−>GetIndex ( ) == 0) {nodeIndexOf fset = 1 ;

}} ) ;

}

MakeCompatible : : ˜ MakeCompatible ( ) {delete spgb ;

}

/∗============================================================================∗∗ P u b l i c methods∗∗============================================================================∗/

Algor ithmStatus MakeCompatible : : RunAlgorithm ( int step , bool dumpOutput ) {int i = −1;while ( spgb−>Val idCyc leExi s t ( ) ) {

i ++;logger−>In f o ( ”Fix graph : ” + MakeSpgCompatible : : GraphToString ( f ixGraph ) ) ;l ogger−>In f o ( ”Change graph : ” + MakeSpgCompatible : : GraphToString ( changeGraph ) ) ;auto c y c l e = spgb−>GetCycle ( ) ;l ogger−>In f o ( ” Val id c y c l e : ” + MakeSpgCompatible : : LinksToStr ing ( c y c l e ) ) ;i f ( timer−>IsTimeOut ( ) ) {

l ogger−>In f o ( ”Time l i m i t reached ! ” ) ;return Algor ithmStatus : : TimeLimitReached ;

}

vector<Link∗> e l ig ib leInChangeGraph , e l i g i b l e InF ixGraph ;ReadEl ig ib l eArcs ( cyc l e , e l ig ib leInChangeGraph , e l i g i b l e InF ixGraph ) ;

logger−>Debug( ” E l i g i b l e a r c s in change graph : ” +MakeSpgCompatible : : LinksToStr ing ( e l ig ib le InChangeGraph ) ) ;

l ogger−>Debug( ” E l i g i b l e a r c s in f i x graph : ” +MakeSpgCompatible : : LinksToStr ing ( e l i g i b l e InF ixGraph ) ) ;

i f (dumpOutput ) {WriteGraphs ( step , i ) ;WriteCycle ( step , i , cyc l e , e l i g ib l e InF ixGraph , e l ig ib le InChangeGraph ) ;

}

i f ( e l ig ib le InChangeGraph . s i z e ( ) == 0) {i f ( e l i g i b l e InF ixGraph . s i z e ( ) == 0) {

46

Page 60: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

l ogger−>Error ( ”No e l i g i b l e arc in the c y c l e ! ” ) ;return Algor ithmStatus : : NotCompatible ;

}i f ( ! Reso lveCyc leUs ingEl ig ib leArcsInFixGraph ( e l i g i b l e InF ixGraph ) ) {

return Algor ithmStatus : : NotCompatible ;}

i f (dumpOutput ) {WriteAddAction ( step , i , e l i g i b l e InF ixGraph ) ;

}}else {

l ogger−>Debug( ” Candidates : ” + MakeSpgCompatible : : LinksToStr ing ( e l ig ib le InChangeGraph ) ) ;

bool cycleBroken = fa l se ;while ( e l ig ib le InChangeGraph . s i z e ( ) > 0 && ! cycleBroken ) {

Link∗ candidate = GetCandidate ( e l ig ib le InChangeGraph ) ;logger−>Debug( ” Candidate : ” + candidate−>ToString ( ) ) ;l ogger−>Debug( ” Candidates l e f t : ” +

MakeSpgCompatible : : LinksToStr ing ( e l ig ib le InChangeGraph ) ) ;

AlgorithmType method = GetAlgorithm ( ) ;

vector<Link∗> l i n k s B e f o r e = changeGraph−>GetLinks ( ) ;

i f ( RemoveLink ( candidate ) ) {i f (dumpOutput ) {

WriteRemoveAction ( step , i , candidate ) ;}cycleBroken = true ;

}else i f ( ExchangeLink ( candidate ) ) {

i f (dumpOutput ) {vector<Link∗> l i n k s A f t e r = changeGraph−>GetLinks ( ) ;WriteReplaceAction ( step , i , candidate , l i nk sBe fo r e , l i n k s A f t e r ) ;

}cycleBroken = true ;

}/∗cyc leBroken =

RemoveLink ( candida te ) ? t r u e :ExchangeLink ( candida te ) ;

∗/l ogger−>Debug( s t r i n g ( ” Current c y c l e i s ” ) +

( cycleBroken ? ”” : ” not ” ) +” broken ! ” ) ;

}

i f ( ! cyc leBroken ) {l ogger−>In f o ( ”Unable to make graphs compatible ! ” ) ;

47

Page 61: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

return Algor ithmStatus : : NotCompatible ;}

}}

i f (dumpOutput ) {WriteGraphs ( step , 0 , ”Compatible” ) ;

}

l ogger−>In f o ( ”Graphs compatible ! ” ) ;return Algor ithmStatus : : Compatible ;

}

bool MakeCompatible : : RemoveLink ( Link∗ l ) {l ogger−>Debug( ”Removing l i n k ” + l−>ToString ( ) ) ;changeGraph−>RemoveLink ( l ) ;l ogger−>Debug( ” After removal : ” + MakeSpgCompatible : : GraphToString ( changeGraph ) ) ;l ogger−>Debug( ”Running D i j k s t r a s a lgor i thm to f i n d another path between nodes ” ) ;Di jks t rasAlgor i thm ∗ d i j k s t r a = new Di jks t rasAlgor i thm ( changeGraph ) ;Graph∗ r e s = d i j k s t r a−>Run( l−>GetFrom ( ) ) ;bool pathExis t s = res−>ContainsNodeIndex ( l−>GetTo()−>GetIndex ( ) ) ;delete r e s ;delete d i j k s t r a ;i f ( pathExis t s ) {

l ogger−>Debug( ”Another path found ! ” ) ;m o d i f i c a t i o n s += 1 ;return true ;

}else {

l ogger−>Debug( ”No other path e x i s t . Adding l i n k again . ” ) ;changeGraph−>AddLink ( l ) ;l ogger−>Debug( ”Link ” + l−>ToString ( ) + ” added” ) ;return fa l se ;

}}

bool MakeCompatible : : ExchangeLink ( Link∗ changeGraphLink ) {l ogger−>Debug( ”Changing l i n k ” + changeGraphLink−>ToString ( ) ) ;

const vector<Link∗> incomming = changeGraphLink−>GetFrom()−>GetIncomming ( ) ;const vector<Link∗> outgoing = changeGraphLink−>GetTo()−>GetOutgoing ( ) ;bool incommingPossible = incomming . s i z e ( ) != 0 ;bool outgo ingPos s ib l e = outgoing . s i z e ( ) != 0 ;

logger−>Debug( ”Incomming l i n k s : ” + MakeSpgCompatible : : LinksToStr ing ( incomming ) ) ;l ogger−>Debug( ”Outgoing l i n k s : ” + MakeSpgCompatible : : LinksToStr ing ( outgoing ) ) ;

48

Page 62: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

vector<Link∗> l inksToReplace ;vector<Node∗> nodes ;i f ( incommingPossible && outgo ingPos s ib l e ) {

return ReplaceUsingBothLinks ( changeGraphLink , incomming , outgoing ) ;}else i f ( incommingPossible ) {

return ReplaceUsingIncommingLinks ( changeGraphLink , incomming ) ;}else i f ( ou tgo ingPos s ib l e ) {

return ReplaceUsingOutgoingLinks ( changeGraphLink , outgoing ) ;}

l ogger−>In f o ( ”No incomming nor outgoing l i n k s from the l i n k ” + changeGraphLink−>ToString ( ) +” . Link i s r equ i r ed f o r the change graph and w i l l not be r ep laced ! ” ) ;

return fa l se ;}

AlgorithmType MakeCompatible : : GetAlgorithm ( ) {return

this−>a lgor i thm == AlgorithmType : : Random ?static cast<AlgorithmType>(rand ( ) % ( ( int ) AlgorithmType : : Random) ) :this−>a lgor i thm ;

}

Link∗ MakeCompatible : : GetCandidate ( std : : vector<Link∗>& cand idates ) {i f ( randomize ) {

return VectorMethods<Link ∗> : :RemoveRandom( cand idate s ) ;}else {

Link∗ l = cand idate s . f r o n t ( ) ;cand idate s . e r a s e ( cand idate s . begin ( ) ) ;return l ;

}}

std : : vector<Link∗> MakeCompatible : : GetPath ( vector<vector<Link∗>>& paths ) {i f ( randomize ) {

return VectorMethods<vector<Link∗>>::RemoveRandom( paths ) ;}else {

std : : vector<Link∗> l = paths . f r o n t ( ) ;paths . e r a s e ( paths . begin ( ) ) ;return l ;

}}

map<int , vector<vector<Link∗>>> MakeCompatible : : GetRankedPaths ( Link∗ changeGraphLink ) {

49

Page 63: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

l ogger−>Debug( ”MakeCompatible : Trying to exchange arc ” + changeGraphLink−>ToString ( ) ) ;Link∗ toExchange =

ful lNetwork−>GetLink ( changeGraphLink−>GetFrom()−>GetIndex ( ) ,changeGraphLink−>GetTo()−>GetIndex ( ) ) ;

vector<Link∗> l i n k s = this−>fu l lNetwork−>GetLinks ( [& ] ( Link∗ l ) { return l != toExchange ; } ) ;

vector<vector<Link∗>> paths =NetworkSearchAlgorithms : : AsPath ( l i nk s ,

toExchange−>GetFrom ( ) ,toExchange−>GetTo ( ) ) ;

vector<Link∗> changeGraphLinks = changeGraph−>GetLinks ( ) ;vector<Link∗> fu l lNetworkLinks ( changeGraphLinks . s i z e ( ) ) ;t rans form ( changeGraphLinks . begin ( ) ,

changeGraphLinks . end ( ) ,fu l lNetworkLinks . begin ( ) ,[&] ( Link∗ l ){

return fu l lNetwork−>GetLink ( l−>GetFrom()−>GetIndex ( ) , l−>GetTo()−>GetIndex ( ) ) ;} ) ;

map<int , vector<std : : vector<Link∗>>> rankedPaths ;f o r e a c h ( paths . begin ( ) ,

paths . end ( ) ,[&] ( vector<Link∗> path ){

vector<Link∗> d i f f = VectorMethods<Link ∗> : : GetDi f f ( path , fu l lNetworkLinks ) ;rankedPaths [ d i f f . s i z e ( ) ] . push back ( d i f f ) ;

} ) ;return rankedPaths ;

}

map<int , vector<vector<Link∗>>> MakeCompatible : : GetRankedReplacements (Node∗ from ,Node∗ to ,vector<Link∗> toReplace ) {

l ogger−>Debug( ”Get ranked replacements . From : ” + t o s t r i n g ( from −>GetIndex ( ) ) +” to : ” + t o s t r i n g ( to−>GetIndex ( ) ) ) ;

vector<Link∗> r e p l a c e ;f o r e a c h ( toReplace . begin ( ) ,

toReplace . end ( ) ,[&] ( Link∗ l ){

r e p l a c e . push back ( fu l lNetwork−>GetLink ( l−>GetFrom()−>GetIndex ( ) ,l−>GetTo()−>GetIndex ( ) ) ) ;

} ) ;

vector<Link∗> a l l L i n k s =ful lNetwork−>GetLinks ( [& ] ( Link∗ l )

50

Page 64: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

{return ! VectorMethods<Link ∗> : : Contains ( r ep lace , l ) ;

} ) ;l ogger−>Debug( ”Using DFS to search a l l paths between nodes ” ) ;vector<vector<Link∗>> paths =

NetworkSearchAlgorithms : : AsPath ( a l lL ink s ,fu l lNetwork−>GetNode ( from−>GetIndex ( ) ) ,fu l lNetwork−>GetNode ( to−>GetIndex ( ) ) ) ;

l ogger−>Debug( ”Number o f paths : ” + t o s t r i n g ( paths . s i z e ( ) ) ) ;

vector<Link∗> changeGraphLinks = changeGraph−>GetLinks ( ) ;vector<Link∗> fu l lNetworkLinks ( changeGraphLinks . s i z e ( ) ) ;t rans form ( changeGraphLinks . begin ( ) ,

changeGraphLinks . end ( ) ,fu l lNetworkLinks . begin ( ) ,[&] ( Link∗ l ){

return fu l lNetwork−>GetLink ( l−>GetFrom()−>GetIndex ( ) , l−>GetTo()−>GetIndex ( ) ) ;} ) ;

map<int , vector<std : : vector<Link∗>>> rankedPaths ;f o r e a c h ( paths . begin ( ) ,

paths . end ( ) ,[&] ( vector<Link∗> path ){

vector<Link∗> d i f f = VectorMethods<Link ∗> : : GetDi f f ( path , fu l lNetworkLinks ) ;rankedPaths [ d i f f . s i z e ( ) ] . push back ( d i f f ) ;

} ) ;l ogger−>Debug( ”Number o f ranks : ” + t o s t r i n g ( rankedPaths . s i z e ( ) ) ) ;return rankedPaths ;

}

map<int , vector<vector<Link∗>>> MakeCompatible : :GetRankedReplacements (Node∗ from , Node∗ to , Link∗ toReplace ) {return GetRankedReplacements ( from , to , vector<Link∗> { toReplace } ) ;

}

bool MakeCompatible : :FindValidReplacement ( vector<Link∗> o r i g i n a l ,

map<int , vector<vector<Link∗>>> &replacements ) {

map<int , vector<vector<Link∗>>>:: i t e r a t o r i t ;for ( i t = replacements . begin ( ) ; i t != rep lacements . end ( ) ; ++i t ) {

l ogger−>Debug( ” Search ing rank ” + t o s t r i n g ( (∗ i t ) . f i r s t ) ) ;vector<vector<Link∗>> paths = (∗ i t ) . second ;while ( paths . s i z e ( ) > 0) {

vector<Link∗> newPath = GetPath ( paths ) ;l ogger−>Debug( ” Test ing replacement : ” + MakeSpgCompatible : : LinksToStr ing ( o r i g i n a l ) +

” with ” + MakeSpgCompatible : : LinksToStr ing ( newPath ) ) ;i f ( IsVal idReplacement ( o r i g i n a l , newPath ) && spgb−>Val idCycleIsBroken ( ) ) {

51

Page 65: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

l ogger−>Debug( ”Replacement : ” + MakeSpgCompatible : : LinksToStr ing ( o r i g i n a l ) +” with ” + MakeSpgCompatible : : LinksToStr ing ( newPath ) +” i s v a l i d and the c y c l e i s broken ! ” ) ;

l ogger−>In f o ( ”Change graph updated to ” + MakeSpgCompatible : : GraphToString ( changeGraph ) +” by the co s t o f ” + t o s t r i n g ( (∗ i t ) . f i r s t ) ) ;

return true ;}

}}return fa l se ;

}

bool MakeCompatible : : IsVal idReplacement ( vector<Link∗> o r i g i n a l , vector<Link∗> replacement ) {f o r e a c h ( o r i g i n a l . begin ( ) ,

o r i g i n a l . end ( ) ,[&] ( Link∗ l ){

changeGraph−>RemoveLink ( l ) ;} ) ;

f o r e a c h ( replacement . begin ( ) ,replacement . end ( ) ,[&] ( Link∗ l ){

changeGraph−>AddLink ( l−>GetFrom()−>GetIndex ( ) ,l−>GetTo()−>GetIndex ( ) ) ;

} ) ;

bool i s C y c l i c = I s C y c l i c ( ) ;l ogger−>Debug( ”Change graph : ” + MakeSpgCompatible : : GraphToString ( changeGraph ) +

” i s ” + ( i s C y c l i c ? ” ” : ” not ” ) + ” c y c l i c ! ” ) ;i f ( i s C y c l i c ) {

f o r e a c h ( o r i g i n a l . begin ( ) ,o r i g i n a l . end ( ) ,[&] ( Link∗ l ){

changeGraph−>AddLink ( l ) ;} ) ;

f o r e a c h ( replacement . begin ( ) ,replacement . end ( ) ,[&] ( Link∗ l ){

changeGraph−>RemoveLink ( l−>GetFrom()−>GetIndex ( ) ,l−>GetTo()−>GetIndex ( ) ) ;

} ) ;}return ! i s C y c l i c ;

52

Page 66: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

}

bool MakeCompatible : : CanBeAdded( vector<Link∗> l i n k s ) {f o r e a c h ( l i n k s . begin ( ) ,

l i n k s . end ( ) ,[&] ( Link∗ l ){

changeGraph−>AddLink ( l−>GetFrom()−>GetIndex ( ) ,l−>GetTo()−>GetIndex ( ) ) ;

} ) ;bool i s C y c l i c = I s C y c l i c ( ) ;l ogger−>Debug( ”Change graph : ” + MakeSpgCompatible : : GraphToString ( changeGraph ) +

” i s ” + ( i s C y c l i c ? ” ” : ” not ” ) + ” c y c l i c ! ” ) ;i f ( i s C y c l i c ) {

f o r e a c h ( l i n k s . begin ( ) ,l i n k s . end ( ) ,[&] ( Link∗ l ){

changeGraph−>RemoveLink ( l−>GetFrom()−>GetIndex ( ) ,l−>GetTo()−>GetIndex ( ) ) ;

} ) ;}else {

m o d i f i c a t i o n s += l i n k s . s i z e ( ) ;}

return ! i s C y c l i c ;}

bool MakeCompatible : : I s C y c l i c ( ) {TarjansAlgorithm ∗ a lgo = new TarjansAlgorithm ( changeGraph ) ;vector<vector<Node∗>> s cc = algo−>Run ( ) ;bool c y c l e E x i s t = scc . s i z e ( ) != changeGraph−>GetNodes ( ) . s i z e ( ) ;delete a lgo ;return c y c l e E x i s t ;

}

void MakeCompatible : : ReadEl ig ib l eArcs ( vector<Link∗> &cyc le ,vector<Link∗> &eChangeGraph ,vector<Link∗> &eFixGraph ) {

f o r e a c h ( c y c l e . begin ( ) ,c y c l e . end ( ) ,[&] ( Link∗ l ){

i f ( changeGraph−>Ex i s t s ( l ) && ! fixGraph−>Ex i s t s ( l ) ) {eChangeGraph . push back ( l ) ;

}else i f ( fixGraph−>Ex i s t s ( l ) && ! changeGraph−>Ex i s t s ( l ) ) {

eFixGraph . push back ( l ) ;

53

Page 67: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

}} ) ;

}

bool MakeCompatible : : Reso lveCyc leUs ingEl ig ib leArcs InFixGraph ( vector<Link∗> e l i g i b l e InF ixGraph ) {i f ( ! ( CanBeAdded( e l i g i b l e InF ixGraph ) ) ) {

l ogger−>In f o ( ”Not p o s s i b l e to add e l i g i b l e a r c s from f i x graph to change graph ! ” ) ;return fa l se ;

}

i f ( spgb−>Val idCycleIsBroken ( ) ) {

return true ;}else {

throw MakeSpgCompatibleException ( s t r i n g ( ” Al l e l i g i b l e a r c s from f i x graph added ” ) +” to change graph and no e l i g i b l e a r c s e x i s t in ” +”change graph but the cur rent c y c l e i s not broken ! ! ! ” ) ;

}}

bool MakeCompatible : : ReplaceUsingIncommingLinks ( Link∗ changeGraphLink , vector<Link∗> incomming ) {vector<Node∗> nodes ( incomming . s i z e ( ) ) ;t rans form ( incomming . begin ( ) , incomming . end ( ) , nodes . begin ( ) ,

[ ] ( Link∗ l ){

return l−>GetFrom ( ) ;} ) ;

l ogger−>Debug( ” Trying to connect the node ( s ) ” + MakeSpgCompatible : : NodesToString ( nodes ) +” to node ” + t o s t r i n g ( changeGraphLink−>GetTo()−>GetIndex ( ) ) +” without ” + changeGraphLink−>ToString ( ) ) ;

vector<pair<Node∗ , Node∗>> connec t i ons ( incomming . s i z e ( ) ) ;t rans form ( incomming . begin ( ) , incomming . end ( ) , connec t i ons . begin ( ) ,

[&] ( Link∗ l ){

return make pair ( l−>GetFrom ( ) , changeGraphLink−>GetTo ( ) ) ;} ) ;

return Exclude ( changeGraphLink , connect i ons ) ;}

bool MakeCompatible : : ReplaceUsingOutgoingLinks ( Link∗ changeGraphLink , vector<Link∗> outgoing ) {vector<Node∗> nodes ( outgoing . s i z e ( ) ) ;t rans form ( outgoing . begin ( ) , outgoing . end ( ) , nodes . begin ( ) ,

[ ] ( Link∗ l ){

return l−>GetTo ( ) ;} ) ;

54

Page 68: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

l ogger−>Debug( ” Trying to connect the node ” + t o s t r i n g ( changeGraphLink−>GetFrom()−>GetIndex ( ) ) +” to node ( s ) ” + MakeSpgCompatible : : NodesToString ( nodes ) +” without ” + changeGraphLink−>ToString ( ) ) ;

vector<pair<Node∗ , Node∗>> connec t i ons ( outgoing . s i z e ( ) ) ;t rans form ( outgoing . begin ( ) , outgoing . end ( ) , connec t i ons . begin ( ) ,

[&] ( Link∗ l ){

return make pair ( changeGraphLink−>GetFrom ( ) , l−>GetTo ( ) ) ;} ) ;

return Exclude ( changeGraphLink , connect i ons ) ;}

bool MakeCompatible : : ReplaceUsingBothLinks ( Link∗ changeGraphLink ,vector<Link∗> incomming ,vector<Link∗> outgoing ) {

returnReplaceUsingIncommingLinks ( changeGraphLink , incomming ) &&ReplaceUsingOutgoingLinks ( changeGraphLink , outgoing ) ;

}

bool MakeCompatible : : Exclude ( Link∗ exclude , vector<pair<Node∗ , Node∗>> requestedConnect ions ) {i f ( requestedConnect ions . s i z e ( ) == 0) {

l ogger−>Debug( ”New paths s u c c e s s f u l l y found ! ” ) ;return true ;

}

vector<Link∗> path { exc lude } ;

pa ir<Node∗ , Node∗> p = requestedConnect ions . f r o n t ( ) ;Node∗ from = p . f i r s t ;Node∗ to = p . second ;logger−>Debug( ” Trying to f i n d a path between nodes ”

+ t o s t r i n g ( from−>GetIndex ( ) ) + ” and ” + t o s t r i n g ( to−>GetIndex ( ) ) +” without ” + exclude−>ToString ( ) ) ;

map<int , vector<vector<Link∗>>> rankedReplacements = GetRankedReplacements ( from , to , path ) ;

map<int , vector<vector<Link∗>>>:: i t e r a t o r i t ;int rank ;vector<vector<Link∗>> rankedPaths ;vector<Link∗> replacement ;

for ( i t = rankedReplacements . begin ( ) ; i t != rankedReplacements . end ( ) ; ++i t ) {int rank = (∗ i t ) . f i r s t ;rankedPaths = (∗ i t ) . second ;

logger−>Debug( ” Search ing rank ” + t o s t r i n g ( rank ) ) ;

55

Page 69: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

while ( rankedPaths . s i z e ( ) > 0) {replacement = GetPath ( rankedPaths ) ;l ogger−>Debug( ” Test ing replacement ” + MakeSpgCompatible : : LinksToStr ing ( replacement ) ) ;i f ( IsVal idReplacement ( path , replacement ) ) {

i f ( spgb−>Val idCycleIsBroken ( ) ) {vector<pair<Node∗ , Node∗>> r e s tConnect ions ( requestedConnect ions ) ;r e s tConnect ions . e r a s e ( r e s tConnect ions . begin ( ) ) ;i f ( Exclude ( exclude , r e s tConnect ions ) ) {

m o d i f i c a t i o n s += rank ;logger−>In f o ( ” Replacements found f o r a l l paths ! ” ) ;return true ;

}l ogger−>Debug( ” Current t r e e does not l ead to v a l i d paths f o r a l l rep lacements . ” ) ;

}else {

l ogger−>Debug( ”Replacement does not i n v a l i d a t e the c y c l e ! Keep sea r ch ing . ” ) ;}

}else {

l ogger−>Debug( ”Replacement i s not v a l i d . Keep sea r ch ing . ” ) ;}

}}

l ogger−>In f o ( ”No v a l i d replacement found that connects the nodes ” +t o s t r i n g ( from−>GetIndex ( ) ) + ” and ” + t o s t r i n g ( to−>GetIndex ( ) ) +” without us ing l i n k ” + exclude−>ToString ( ) + ” ! ” ) ;

return fa l se ;}

void MakeCompatible : : SetOutputPath ( s t r i n g path ) {outputPath = path ;

}

void MakeCompatible : : WriteGraphs ( int step , int i t e r a t i o n , s t r i n g name) {s t r i n g d i r = GetDirectory ( step , i t e r a t i o n ) ;l ogger−>Debug( ” Writing ” + name + ” to ” + d i r ) ;o f s tream graphFi l e ;g raphFi l e . open ( d i r + name + ” . spg” ) ;g raphFi l e << ”2\n” ;NetworkFi leParser : : WriteGraphToFile ( graphFi le , fixGraph , true , 0 ) ;NetworkFi leParser : : WriteGraphToFile ( graphFi le , changeGraph , true , 0 ) ;g raphFi l e . c l o s e ( ) ;

}

void MakeCompatible : : WriteCycle ( int step ,int i t e r a t i o n ,vector<Link∗> va l idCyc le ,vector<Link∗> eFix ,vector<Link∗> eChange ) {

56

Page 70: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

s t r i n g d i r = GetDirectory ( step , i t e r a t i o n ) ;

o f s tream stream ;stream . open ( d i r + ” c y c l e . dbg” ) ;NetworkFi leParser : : WriteLinksToFile ( stream , va l idCyc le , 0 ) ;stream . c l o s e ( ) ;stream . open ( d i r + ” e l i g i b l e F i x . dbg” ) ;NetworkFi leParser : : WriteLinksToFile ( stream , eFix , 0 ) ;stream . c l o s e ( ) ;stream . open ( d i r + ” e l i g i b l eChange . dbg” ) ;NetworkFi leParser : : WriteLinksToFile ( stream , eChange , 0 ) ;stream . c l o s e ( ) ;

}

void MakeCompatible : : WriteReplaceAction ( int step ,int i t e r a t i o n ,Link∗ toRemove ,vector<Link∗> before ,vector<Link∗> a f t e r ) {

s t r i n g d i r = GetDirectory ( step , i t e r a t i o n ) ;

vector<Link∗> r ep laced = VectorMethods<Link ∗> : : GetDi f f ( be fore , a f t e r ) ;vector<Link∗> rep lacements = VectorMethods<Link ∗> : : GetDi f f ( a f t e r , b e f o r e ) ;

o f s tream stream ;stream . open ( d i r + ” ac t i on . dbg” ) ;stream << ”Removing arc ” << toRemove−>ToString ( )

<< ” and f i n d i n g new paths f o r ad jacent a r c s ” << endl<< ” Replaced : ” << MakeSpgCompatible : : LinksToStr ing ( r ep laced ) << endl<< ” Replacements : ” << MakeSpgCompatible : : LinksToStr ing ( rep lacements ) << endl ;

stream . c l o s e ( ) ;}

void MakeCompatible : : WriteRemoveAction ( int step ,int i t e r a t i o n ,Link∗ toRemove ) {

s t r i n g d i r = GetDirectory ( step , i t e r a t i o n ) ;o f s tream stream ;stream . open ( d i r + ” ac t i on . dbg” ) ;stream << ”Removing arc ” << toRemove−>ToString ( ) ;stream . c l o s e ( ) ;

}

void MakeCompatible : : WriteAddAction ( int step ,int i t e r a t i o n ,vector<Link∗> toAdd ) {

s t r i n g d i r = GetDirectory ( step , i t e r a t i o n ) ;o f s tream stream ;stream . open ( d i r + ” ac t i on . dbg” ) ;stream << ”Adding a r c s ” << MakeSpgCompatible : : LinksToStr ing ( toAdd ) ;

57

Page 71: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

stream . c l o s e ( ) ;}

s t r i n g MakeCompatible : : GetDirectory ( int step , int i t e r a t i o n ) {char b u f f e r [ 2 5 6 ] ;s p r i n t f ( bu f f e r , ”%02d” , s tep ) ;s t r i n g s t e p s t r ( b u f f e r ) ;s p r i n t f ( bu f f e r , ”%02d” , i t e r a t i o n ) ;s t r i n g i t e r s t r ( b u f f e r ) ;s t r i n g d = NetworkFi leParser : :

AppendPath ( outputPath , ” Step ” + s t e p s t r + ” i t e r a t i o n ” + i t e r s t r + ”/” ) ;NetworkFi leParser : : CreateDir (d ) ;return d ;

}

SpgbCommunication∗ MakeCompatible : : GetSpgb ( ) {return spgb ;

}

void MakeCompatible : : SetGraphs ( Graph∗ f ixGraph , Graph∗ changeGraph ) {SetFixGraph ( f ixGraph ) ;SetChangeGraph ( changeGraph ) ;

}

void MakeCompatible : : SetFixGraph ( Graph∗ f ixGraph ) {this−>f ixGraph = fixGraph ;spgb−>SetFixGraph ( f ixGraph ) ;

}

void MakeCompatible : : SetChangeGraph ( Graph∗ changeGraph ) {m o d i f i c a t i o n s = 0 ;this−>changeGraph = changeGraph ;spgb−>SetChangeGraph ( changeGraph ) ;

}

Graph∗ MakeCompatible : : GetFixGraph ( ) {return this−>f ixGraph ;

}

Graph∗ MakeCompatible : : GetChangeGraph ( ) {return this−>changeGraph ;

}

int MakeCompatible : : GetModi f i cat ions ( ) {return m o d i f i c a t i o n s ;

}

58

Page 72: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

#include <sstream>#include <fstream>#include <vector>

#include ”SpgbCommunication . hpp”#include ” NetworkFi leParser . hpp”#include ”MakeSpgCompatibleException . hpp”#include ”MakeSpgCompatible . hpp”#include ”Graph . hpp”#include ”Link . hpp”#include ”Node . hpp”#include ”spgb . h”#include ”VectorMethods . hpp”#include ”LogModule . hpp”#include ” Logging . hpp”

/∗============================================================================∗∗ c t o r and dtor∗∗============================================================================∗/

SpgbCommunication : : SpgbCommunication ( Graph∗ fu l lNetwork ) :SpgbCommunication ( fu l lNetwork , Logging : : DisplayLogger ( ) ) {

// This c o n s t r u c t o r w i l l most ly be used f o r t e s t c a s e s when not debugg ing .this−>l ogger−>SetLeve l ( LogLevel : : I n f o ) ;

}

SpgbCommunication : : SpgbCommunication ( Graph∗ fu l lNetwork , LogModule∗ l o g g e r ) {twoGraphFile = ”TwoGraphs . tmp” ;p f i l = ” p f i l ” ;r e s u l t F i l e = ” aspgout ” ;f u l lNe tworkF i l e = ” FullNetwork . tmp” ;this−>fu l lNetwork = fu l lNetwork ;this−>l o g g e r = l o g g e r ;S e t O f f s e t ( ) ;In i t i a l i z eCommunicat ion ( ) ;

}

SpgbCommunication : : ˜ SpgbCommunication ( ) {RemoveFile ( twoGraphFile ) ;RemoveFile ( p f i l ) ;RemoveFile ( r e s u l t F i l e ) ;RemoveFile ( f u l lNe tworkF i l e ) ;

}

/∗============================================================================∗∗ P u b l i c methods

59

Page 73: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

∗∗============================================================================∗/

void SpgbCommunication : : SetFixGraph ( Graph∗ f ixGraph ) {this−>f ixGraph = fixGraph ;

}

void SpgbCommunication : : SetChangeGraph ( Graph∗ changeGraph ) {this−>changeGraph = changeGraph ;

}

bool SpgbCommunication : : Va l idCyc leExi s t ( ) {CallSpgb ( ) ;vector<pair<int , int>> va l idCyc l e ;ReadCycle ( va l idCyc l e ) ;c y c l e . c l e a r ( ) ;GetLinksFromCycle ( va l idCyc le , c y c l e ) ;return c y c l e . s i z e ( ) != 0 ;

}

bool SpgbCommunication : : Val idCycleIsBroken ( ) {CallSpgb ( ) ;vector<pair<int , int>> va l idCyc l e ;ReadCycle ( va l idCyc l e ) ;vector<Link∗> newCycle ;GetLinksFromCycle ( va l idCyc le , newCycle ) ;

return ! VectorMethods<Link ∗> : :Equals ( newCycle ,

cyc l e ,[ ] ( Link∗ l1 , Link∗ l 2 ){

returnl1−>GetFrom()−>GetIndex ( ) == l2−>GetFrom()−>GetIndex ( ) &&l1−>GetTo()−>GetIndex ( ) == l2−>GetTo()−>GetIndex ( ) ;

} ) ;}

const vector<Link∗> SpgbCommunication : : GetCycle ( ) {return c y c l e ;

}

void SpgbCommunication : :GetLinksFromCycle ( vector<pair<int , int>> cyc l e , vector<Link∗> &r e s u l t ) {

i f ( c y c l e . s i z e ( ) == 0) {return ;

}

vector<pair<int , int >>:: i t e r a t o r i t ;

60

Page 74: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

for ( i t = c y c l e . begin ( ) ; i t != c y c l e . end ( ) ; ++i t ) {int f i r s t = (∗ i t ) . f i r s t ;int second = (∗ i t ) . second ;

// l o g g e r−>Debug (” Test ing ” + t o s t r i n g ( f i r s t ) + ”−” + t o s t r i n g ( second ) ) ;

i f ( changeGraph−>Ex i s t s ( f i r s t , second ) && ! fixGraph−>Ex i s t s ( second , f i r s t ) ) {// l o g g e r−>Debug (” Adding change ” ) ;r e s u l t . push back ( changeGraph−>GetLink ( f i r s t , second ) ) ;

} else i f ( changeGraph−>Ex i s t s ( second , f i r s t ) && ! fixGraph−>Ex i s t s ( f i r s t , second ) ) {// l o g g e r−>Debug (” Adding rev change ” ) ;r e s u l t . push back ( changeGraph−>GetLink ( second , f i r s t ) ) ;

} else i f ( fixGraph−>Ex i s t s ( f i r s t , second ) && ! changeGraph−>Ex i s t s ( second , f i r s t ) ) {// l o g g e r−>Debug (” Adding f i x ” ) ;r e s u l t . push back ( fixGraph−>GetLink ( f i r s t , second ) ) ;

} else i f ( fixGraph−>Ex i s t s ( second , f i r s t ) && ! changeGraph−>Ex i s t s ( f i r s t , second ) ) {// l o g g e r−>Debug (” Adding rev f i x ” ) ;r e s u l t . push back ( fixGraph−>GetLink ( second , f i r s t ) ) ;

} else {l ogger−>Error ( ”The node pa i r ” + t o s t r i n g ( f i r s t ) + ” − ” + t o s t r i n g ( second ) +

” i s part o f the c y c l e but not added from e i t h e r f i x− nor change graph ! ” ) ;}

}}

/∗============================================================================∗∗ P r i v a t e methods∗∗============================================================================∗/

void SpgbCommunication : : CallSpgb ( ) {l ogger−>Debug( ” Reset communication” ) ;ResetCommunication ( ) ;o f s tream graphFi l e ;g raphFi l e . open ( twoGraphFile ) ;g raphFi l e << ”2\n” ;NetworkFi leParser : : WriteGraphToFile ( graphFi le , fixGraph , true , nodeIndexOf fset ) ;NetworkFi leParser : : WriteGraphToFile ( graphFi le , changeGraph , true , nodeIndexOf fset ) ;g raphFi l e . c l o s e ( ) ;

l ogger−>Debug( ” Ca l l i ng spgb” ) ;main spgb ( ) ;l ogger−>Debug( ”Returned from spgb” ) ;

}

void SpgbCommunication : : ReadCycle ( vector<pair<int , int>> &va l idCyc l e ) {i f ( NetworkFi leParser : : F i l e E x i s t ( r e s u l t F i l e ) ) {

61

Page 75: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

l ogger−>Debug( ”Reading r e s u l t f i l e ” ) ;i f s t r e a m stream ( r e s u l t F i l e ) ;int g1 , g2 ;std : : s t r i n g l i n e ;g e t l i n e ( stream , l i n e ) ;i s t r i n g s t r e a m i s s ( l i n e ) ;i s s >> g1 >> g2 ;stream . c l o s e ( ) ;i f ( g1 != g2 ) {

NetworkFi leParser : : ReadAspgOut ( r e s u l t F i l e , va l idCyc l e ) ;s td : : t rans form ( va l idCyc l e . begin ( ) ,

va l idCyc l e . end ( ) ,va l idCyc l e . begin ( ) ,[&] ( pair<int , int> l ){

return make pair ( l . f i r s t − nodeIndexOffset ,l . second − nodeIndexOf fset ) ;

} ) ;}

}}

void SpgbCommunication : : RemoveFile ( std : : s t r i n g f i l ename ) {i f ( NetworkFi leParser : : F i l e E x i s t ( f i l ename ) ) {

remove ( f i l ename . c s t r ( ) ) ;}

}

void SpgbCommunication : : Copy f i l e ( s t r i n g source , s t r i n g d e s t i n a t i o n ) {std : : i f s t r e a m s r c ( source . c s t r ( ) , s td : : i o s : : b inary ) ;s td : : o f s tream dest ( d e s t i n a t i o n . c s t r ( ) , s td : : i o s : : b inary ) ;des t << s r c . rdbuf ( ) ;des t . c l o s e ( ) ;s r c . c l o s e ( ) ;

}

void SpgbCommunication : : In i t i a l i z eCommunicat ion ( ) {ofstream stream ( p f i l ) ;stream << f u l lNe tworkF i l e << endl ;stream << twoGraphFile << endl ;stream . c l o s e ( ) ;

o f s tream fu l lNetwork ( fu l lNe tworkF i l e ) ;fu l lNetwork << ”0” << endl << ”0” << endl << this−>fu l lNetwork−>GetNodes ( ) . s i z e ( ) << endl ;NetworkFi leParser : : WriteGraphToFile ( fu l lNetwork , this−>fu l lNetwork , false , nodeIndexOf fset ) ;fu l lNetwork . c l o s e ( ) ;

}

void SpgbCommunication : : ResetCommunication ( ) {

62

Page 76: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

RemoveFile ( twoGraphFile ) ;RemoveFile ( r e s u l t F i l e ) ;

}

void SpgbCommunication : : S e t O f f s e t ( ) {nodeIndexOf fset = 0 ;vector<Link∗> l i n k s = ful lNetwork−>GetLinks ( ) ;s td : : f o r e a c h ( l i n k s . begin ( ) ,

l i n k s . end ( ) ,[&] ( Link∗ l ){

i f ( l−>GetFrom()−>GetIndex ( ) == 0 | |l−>GetTo()−>GetIndex ( ) == 0) {

nodeIndexOf fset = 1 ;}

} ) ;}

63

Page 77: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

#include ”Network/ NetworkSearchAlgorithms . hpp”#include ”Network/Link . hpp”#include ”Network/Node . hpp”#include ”Network/Graph . hpp”#include ”VectorMethods . hpp”

std : : vector<Link∗> NetworkSearchAlgorithms : : DeepFirstSearch ( Graph∗ graph , Node∗ from , Node∗ to ){

std : : vector<Link∗> r e s u l t ;s td : : vector<Node∗> queue ;Node∗ cur rent ;s td : : vector<Node∗> nodes = graph−>GetNodes ( ) ;

for ( std : : vector<Node∗> : : i t e r a t o r i t = nodes . begin ( ) ; i t != nodes . end ( ) ; ++i t ) {(∗ i t )−>GetData()−> i 1 = 0 ;(∗ i t )−>GetData()−> i 2 = 0 ;

}

queue . push back ( to ) ;

while ( queue . s i z e ( ) > 0) {cur rent = queue . back ( ) ;queue . pop back ( ) ;

const std : : vector<Link∗> l i n k s = current−>GetIncomming ( ) ;for (auto i t = l i n k s . begin ( ) ; i t != l i n k s . end ( ) ; ++i t ) {

Node∗ neighbour = (∗ i t )−>GetFrom ( ) ;i f ( neighbour−>GetData()−> i 1 == 0) {

queue . i n s e r t ( queue . begin ( ) , neighbour ) ;}

neighbour−>GetData()−>v1 . push back ( current−>GetIndex ( ) ) ;}current−>GetData()−> i 1 = 1 ;

}

queue . push back ( from ) ;

while ( queue . s i z e ( ) > 0) {cur rent = queue . back ( ) ;queue . pop back ( ) ;

vector<int> next = current−>GetData()−>v1 ;vector<Link∗> outgoing = current−>GetOutgoing ( ) ;for (auto i t = outgoing . begin ( ) ; i t != outgoing . end ( ) ; ++i t ) {

i f ( VectorMethods<int > : : Contains ( next , (∗ i t )−>GetTo()−>GetIndex ( ) ) &&! VectorMethods<Link ∗> : : Contains ( r e s u l t , ∗ i t ) ) {

r e s u l t . push back (∗ i t ) ;Node∗ neighbour = (∗ i t )−>GetTo ( ) ;

64

Page 78: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

i f ( neighbour−>GetData()−> i 2 == 0) {queue . i n s e r t ( queue . begin ( ) , neighbour ) ;

}}

}

current−>GetData()−> i 2 = 1 ;}

return r e s u l t ;}

std : : vector<std : : vector<Link∗>> NetworkSearchAlgorithms : : AsPath ( std : : vector<Link∗> l i nk s , Node∗ from , Node∗ to ){

std : : vector<std : : vector<Link∗>> paths ;f o r e a c h ( l i n k s . begin ( ) , l i n k s . end ( ) , [& ] ( Link∗ l ) {

i f ( l−>GetFrom ( ) == from ) {paths . push back ({ l } ) ;

}} ) ;AsPath ( l i nk s , to , paths ) ;return paths ;

}

void NetworkSearchAlgorithms : : AsPath ( std : : vector<Link∗> l i nk s ,Node∗ to ,std : : vector<std : : vector<Link∗>>& paths )

{std : : vector<std : : vector<Link∗>> r e s u l t ;

for ( std : : vector<std : : vector<Link∗> > : : i t e r a t o r i t = paths . begin ( ) ; i t != paths . end ( ) ; ++i t ) {std : : vector<Link∗> path = ∗ i t ;s td : : vector<Node∗> or ig inNodes ;or ig inNodes . r e s i z e ( path . s i z e ( ) ) ;s td : : t rans form ( path . begin ( ) , path . end ( ) , or ig inNodes . begin ( ) , [ ] ( Link∗ l ) { return l−>GetFrom ( ) ; } ) ;

Node∗ lastNode = path . back()−>GetTo ( ) ;i f ( lastNode != to ) {

std : : vector<Link∗> outgoing =VectorMethods<Link ∗> : : F i l t e r ( l i nk s , [& ] ( Link∗ l ) { return l−>GetFrom ( ) == lastNode ; } ) ;

for ( std : : vector<Link ∗> : : i t e r a t o r l i n k I t = outgoing . begin ( ) ; l i n k I t != outgoing . end ( ) ; ++l i n k I t ) {i f ( ! VectorMethods<Node∗> : : Contains ( or ig inNodes , (∗ l i n k I t )−>GetTo ( ) ) ) {

std : : vector<Link∗> pathCopy = path ;pathCopy . push back (∗ l i n k I t ) ;r e s u l t . push back ( pathCopy ) ;

}}

} else {r e s u l t . push back ( path ) ;

65

Page 79: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

}}

paths = r e s u l t ;

bool a l lPa th sF in i shed = true ;for (auto i t = paths . begin ( ) ; i t != paths . end ( ) ; ++i t ) {

Node∗ n = (∗ i t ) . back()−>GetTo ( ) ;i f (n != to ) {

a l lPa th sF in i shed = fa l se ;}

}

i f ( ! a l lPa th sF in i shed ) {AsPath ( l i nk s , to , paths ) ;

}}

66

Page 80: Examensarbete Routing of tra c in an IP-network using ...838801/FULLTEXT01.pdf · Routing of tra c in an IP-network using combined routing patterns Andreas Lindblad In IP networks

Copyright

The publishers will keep this document online on the Internet - or its possi-ble replacement - for a period of 25 years from the date of publication barringexceptional circumstances. The online availability of the document implies apermanent permission for anyone to read, to download, to print out single copiesfor your own use and to use it unchanged for any non-commercial research andeducational purpose. Subsequent transfers of copyright cannot revoke this per-mission. All other uses of the document are conditional on the consent of thecopyright owner. The publisher has taken technical and administrative mea-sures to assure authenticity, security and accessibility. According to intellectualproperty law the author has the right to be mentioned when his/her work isaccessed as described above and to be protected against infringement. For ad-ditional information about the Linkoping University Electronic Press and itsprocedures for publication and for assurance of document integrity, please referto its WWW home page: http://www.ep.liu.se/

Upphovsratt

Detta dokument halls tillgangligt pa Internet - eller dess framtida ersattare- under 25 ar fran publiceringsdatum under forutsattning att inga extraordi-nara omstandigheter uppstar. Tillgang till dokumentet innebar tillstand forvar och en att lasa, ladda ner, skriva ut enstaka kopior for enskilt bruk ochatt anvanda det oforandrat for ickekommersiell forskning och for undervisning.Overforing av upphovsratten vid en senare tidpunkt kan inte upphava dettatillstand. All annan anvandning av dokumentet kraver upphovsmannens med-givande. For att garantera aktheten, sakerheten och tillgangligheten finns detlosningar av teknisk och administrativ art. Upphovsmannens ideella ratt in-nefattar ratt att bli namnd som upphovsman i den omfattning som god sedkraver vid anvandning av dokumentet pa ovan beskrivna satt samt skydd motatt dokumentet andras eller presenteras i sadan form eller i sadant sammanhangsom ar krankande for upphovsmannens litterara eller konstnarliga anseende elleregenart. For ytterligare information om Linkoping University Electronic Pressse forlagets hemsida http://www.ep.liu.se/

c© June 2015, Andreas Lindblad