blob: 0c3703c97f9b3f8f07002203a0a7946c776cf0e7 [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;
19import java.util.HashMap;
20
21import net.floodlightcontroller.routing.Link;
22
23import org.openflow.util.HexString;
24
25public class BroadcastTree {
26 protected HashMap<Long, Link> links;
27 protected HashMap<Long, Integer> costs;
28
29 public BroadcastTree() {
30 links = new HashMap<Long, Link>();
31 costs = new HashMap<Long, Integer>();
32 }
33
34 public BroadcastTree(HashMap<Long, Link> links, HashMap<Long, Integer> costs) {
35 this.links = links;
36 this.costs = costs;
37 }
38
39 public Link getTreeLink(long node) {
40 return links.get(node);
41 }
42
43 public int getCost(long node) {
44 if (costs.get(node) == null) return -1;
45 return (costs.get(node));
46 }
47
48 public HashMap<Long, Link> getLinks() {
49 return links;
50 }
51
52 public void addTreeLink(long myNode, Link link) {
53 links.put(myNode, link);
54 }
55
56 public String toString() {
57 StringBuffer sb = new StringBuffer();
58 for(long n: links.keySet()) {
59 sb.append("[" + HexString.toHexString(n) + ": cost=" + costs.get(n) + ", " + links.get(n) + "]");
60 }
61 return sb.toString();
62 }
63
64 public HashMap<Long, Integer> getCosts() {
65 return costs;
66 }
67}