Srikanth Vavilapalli | 4db76e3 | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 1 | package org.onosproject.segmentrouting.config; |
| 2 | |
| 3 | import java.util.List; |
| 4 | import java.util.Map.Entry; |
| 5 | import java.util.Set; |
| 6 | import java.util.concurrent.ConcurrentHashMap; |
| 7 | |
| 8 | import org.onosproject.net.Link; |
| 9 | import org.onosproject.segmentrouting.config.NetworkConfig.LinkConfig; |
| 10 | import org.slf4j.Logger; |
| 11 | import org.slf4j.LoggerFactory; |
| 12 | |
| 13 | import com.fasterxml.jackson.databind.JsonNode; |
| 14 | |
| 15 | /** |
| 16 | * Reserved for future use. |
| 17 | * Configuration for a link between two packet-switches. |
| 18 | */ |
| 19 | public class PktLinkConfig extends LinkConfig { |
| 20 | protected static final Logger log = LoggerFactory |
| 21 | .getLogger(PktLinkConfig.class); |
| 22 | private int port1; |
| 23 | private int port2; |
| 24 | private String nodeName1; |
| 25 | private String nodeName2; |
| 26 | private List<Link> linkTupleList; |
| 27 | |
| 28 | public PktLinkConfig(LinkConfig lkc) { |
| 29 | nodeDpid1 = lkc.getNodeDpid1(); |
| 30 | nodeDpid2 = lkc.getNodeDpid2(); |
| 31 | dpid1 = lkc.getDpid1(); |
| 32 | dpid2 = lkc.getDpid2(); |
| 33 | type = lkc.getType(); |
| 34 | allowed = lkc.isAllowed(); |
| 35 | params = lkc.getParams(); |
| 36 | publishAttributes = new ConcurrentHashMap<String, String>(); |
| 37 | parseParams(); |
| 38 | validateParams(); |
| 39 | setPublishAttributes(); |
| 40 | } |
| 41 | |
| 42 | // ******************** |
| 43 | // Packet Link Configuration |
| 44 | // ******************** |
| 45 | |
| 46 | public int getPort1() { |
| 47 | return port1; |
| 48 | } |
| 49 | |
| 50 | public void setPort1(int port1) { |
| 51 | this.port1 = port1; |
| 52 | } |
| 53 | |
| 54 | public int getPort2() { |
| 55 | return port2; |
| 56 | } |
| 57 | |
| 58 | public void setPort2(int port2) { |
| 59 | this.port2 = port2; |
| 60 | } |
| 61 | |
| 62 | public String getNodeName1() { |
| 63 | return nodeName1; |
| 64 | } |
| 65 | |
| 66 | public void setNodeName1(String nodeName1) { |
| 67 | this.nodeName1 = nodeName1; |
| 68 | } |
| 69 | |
| 70 | public String getNodeName2() { |
| 71 | return nodeName2; |
| 72 | } |
| 73 | |
| 74 | public void setNodeName2(String nodeName2) { |
| 75 | this.nodeName2 = nodeName2; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Returns the two unidirectional links corresponding to the packet-link |
| 80 | * configuration. It is possible that the ports in the LinkTuple have |
| 81 | * portnumber '0', implying that the configuration applies to all links |
| 82 | * between the two switches. |
| 83 | * |
| 84 | * @return a list of LinkTuple with exactly 2 unidirectional links |
| 85 | */ |
| 86 | public List<Link> getLinkTupleList() { |
| 87 | return linkTupleList; |
| 88 | } |
| 89 | |
| 90 | private void setPublishAttributes() { |
| 91 | |
| 92 | } |
| 93 | |
| 94 | private void parseParams() { |
| 95 | if (params == null) { |
| 96 | throw new PktLinkParamsNotSpecified(nodeDpid1, nodeDpid2); |
| 97 | } |
| 98 | Set<Entry<String, JsonNode>> m = params.entrySet(); |
| 99 | for (Entry<String, JsonNode> e : m) { |
| 100 | String key = e.getKey(); |
| 101 | JsonNode j = e.getValue(); |
| 102 | if (key.equals("nodeName1")) { |
| 103 | setNodeName1(j.asText()); |
| 104 | } else if (key.equals("nodeName2")) { |
| 105 | setNodeName2(j.asText()); |
| 106 | } else if (key.equals("port1")) { |
| 107 | setPort1(j.asInt()); |
| 108 | } else if (key.equals("port2")) { |
| 109 | setPort2(j.asInt()); |
| 110 | } else { |
| 111 | throw new UnknownPktLinkConfig(key, nodeDpid1, nodeDpid2); |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | private void validateParams() { |
| 117 | // TODO - wrong-names, duplicate links, |
| 118 | // duplicate use of port, is switch-allowed for which link is allowed? |
| 119 | // valid port numbers |
| 120 | } |
| 121 | |
| 122 | public static class PktLinkParamsNotSpecified extends RuntimeException { |
| 123 | private static final long serialVersionUID = 6247582323691265513L; |
| 124 | |
| 125 | public PktLinkParamsNotSpecified(String dpidA, String dpidB) { |
| 126 | super(); |
| 127 | log.error("Params required for packet link - not specified " |
| 128 | + "for link between switch1:{} and switch2:{}", |
| 129 | dpidA, dpidB); |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | public static class UnknownPktLinkConfig extends RuntimeException { |
| 134 | private static final long serialVersionUID = -5750132094884129179L; |
| 135 | |
| 136 | public UnknownPktLinkConfig(String key, String dpidA, String dpidB) { |
| 137 | super(); |
| 138 | log.error("Unknown packet-link config {} for link between" |
| 139 | + " dpid1: {} and dpid2: {}", key, |
| 140 | dpidA, dpidB); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | } |