Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 1 | /** |
| 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 | |
| 18 | package net.floodlightcontroller.routing; |
| 19 | import java.util.HashMap; |
| 20 | |
| 21 | import net.floodlightcontroller.routing.Link; |
| 22 | |
| 23 | import org.openflow.util.HexString; |
| 24 | |
| 25 | public 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 | } |