blob: a55096163d3dfd11e89a80a9ef935e9f624d8e93 [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 org.openflow.util.HexString;
21
22/**
23 * Stores the endpoints of a route, in this case datapath ids
24 *
25 * @author David Erickson (daviderickson@cs.stanford.edu)
26 */
27public class RouteId implements Cloneable, Comparable<RouteId> {
28 protected Long src;
29 protected Long dst;
30
31 public RouteId(Long src, Long dst) {
32 super();
33 this.src = src;
34 this.dst = dst;
35 }
36
37 public Long getSrc() {
38 return src;
39 }
40
41 public void setSrc(Long src) {
42 this.src = src;
43 }
44
45 public Long getDst() {
46 return dst;
47 }
48
49 public void setDst(Long dst) {
50 this.dst = dst;
51 }
52
53 @Override
54 public int hashCode() {
55 final int prime = 2417;
56 int result = 1;
57 result = prime * result + ((dst == null) ? 0 : dst.hashCode());
58 result = prime * result + ((src == null) ? 0 : src.hashCode());
59 return result;
60 }
61
62 @Override
63 public boolean equals(Object obj) {
64 if (this == obj)
65 return true;
66 if (obj == null)
67 return false;
68 if (getClass() != obj.getClass())
69 return false;
70 RouteId other = (RouteId) obj;
71 if (dst == null) {
72 if (other.dst != null)
73 return false;
74 } else if (!dst.equals(other.dst))
75 return false;
76 if (src == null) {
77 if (other.src != null)
78 return false;
79 } else if (!src.equals(other.src))
80 return false;
81 return true;
82 }
83
84 @Override
85 public String toString() {
86 return "RouteId [src=" + HexString.toHexString(this.src) + " dst="
87 + HexString.toHexString(this.dst) + "]";
88 }
89
90 @Override
91 protected Object clone() throws CloneNotSupportedException {
92 return super.clone();
93 }
94
95 @Override
96 public int compareTo(RouteId o) {
97 int result = src.compareTo(o.getSrc());
98 if (result != 0)
99 return result;
100 return dst.compareTo(o.getDst());
101 }
102}