blob: 211a924f7d5e912753882e88d5d54ae70009bca0 [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
2* Copyright 2011, Big Switch Networks, Inc.
3* Originally created by David Erickson, Stanford University
4*
5* Licensed under the Apache License, Version 2.0 (the "License"); you may
6* not use this file except in compliance with the License. You may obtain
7* a copy of the License at
8*
9* http://www.apache.org/licenses/LICENSE-2.0
10*
11* Unless required by applicable law or agreed to in writing, software
12* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14* License for the specific language governing permissions and limitations
15* under the License.
16**/
17
18package net.floodlightcontroller.routing;
19
20import java.util.ArrayList;
21import java.util.List;
22
23import net.floodlightcontroller.topology.NodePortTuple;
24
25/**
26 * Represents a route between two switches
27 *
28 * @author David Erickson (daviderickson@cs.stanford.edu)
29 */
30public class Route implements Comparable<Route> {
31 protected RouteId id;
32 protected List<NodePortTuple> switchPorts;
33
34 public Route(RouteId id, List<NodePortTuple> switchPorts) {
35 super();
36 this.id = id;
37 this.switchPorts = switchPorts;
38 }
39
40 public Route(Long src, Long dst) {
41 super();
42 this.id = new RouteId(src, dst);
43 this.switchPorts = new ArrayList<NodePortTuple>();
44 }
45
46 /**
47 * @return the id
48 */
49 public RouteId getId() {
50 return id;
51 }
52
53 /**
54 * @param id the id to set
55 */
56 public void setId(RouteId id) {
57 this.id = id;
58 }
59
60 /**
61 * @return the path
62 */
63 public List<NodePortTuple> getPath() {
64 return switchPorts;
65 }
66
67 /**
68 * @param path the path to set
69 */
70 public void setPath(List<NodePortTuple> switchPorts) {
71 this.switchPorts = switchPorts;
72 }
73
74 @Override
75 public int hashCode() {
76 final int prime = 5791;
77 int result = 1;
78 result = prime * result + ((id == null) ? 0 : id.hashCode());
79 result = prime * result + ((switchPorts == null) ? 0 : switchPorts.hashCode());
80 return result;
81 }
82
83 @Override
84 public boolean equals(Object obj) {
85 if (this == obj)
86 return true;
87 if (obj == null)
88 return false;
89 if (getClass() != obj.getClass())
90 return false;
91 Route other = (Route) obj;
92 if (id == null) {
93 if (other.id != null)
94 return false;
95 } else if (!id.equals(other.id))
96 return false;
97 if (switchPorts == null) {
98 if (other.switchPorts != null)
99 return false;
100 } else if (!switchPorts.equals(other.switchPorts))
101 return false;
102 return true;
103 }
104
105 @Override
106 public String toString() {
107 return "Route [id=" + id + ", switchPorts=" + switchPorts + "]";
108 }
109
110 /**
111 * Compares the path lengths between Routes.
112 */
113 @Override
114 public int compareTo(Route o) {
115 return ((Integer)switchPorts.size()).compareTo(o.switchPorts.size());
116 }
117}