1 package org.onosproject.segmentrouting.config;
4 import java.util.Map.Entry;
6 import java.util.concurrent.ConcurrentHashMap;
8 import org.onosproject.net.Link;
9 import org.onosproject.segmentrouting.config.NetworkConfig.LinkConfig;
10 import org.slf4j.Logger;
11 import org.slf4j.LoggerFactory;
13 import com.fasterxml.jackson.databind.JsonNode;
16 * Reserved for future use.
17 * Configuration for a link between two packet-switches.
19 public class PktLinkConfig extends LinkConfig {
20 protected static final Logger log = LoggerFactory
21 .getLogger(PktLinkConfig.class);
24 private String nodeName1;
25 private String nodeName2;
26 private List<Link> linkTupleList;
28 public PktLinkConfig(LinkConfig lkc) {
29 nodeDpid1 = lkc.getNodeDpid1();
30 nodeDpid2 = lkc.getNodeDpid2();
31 dpid1 = lkc.getDpid1();
32 dpid2 = lkc.getDpid2();
34 allowed = lkc.isAllowed();
35 params = lkc.getParams();
36 publishAttributes = new ConcurrentHashMap<String, String>();
39 setPublishAttributes();
42 // ********************
43 // Packet Link Configuration
44 // ********************
46 public int getPort1() {
50 public void setPort1(int port1) {
54 public int getPort2() {
58 public void setPort2(int port2) {
62 public String getNodeName1() {
66 public void setNodeName1(String nodeName1) {
67 this.nodeName1 = nodeName1;
70 public String getNodeName2() {
74 public void setNodeName2(String nodeName2) {
75 this.nodeName2 = nodeName2;
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.
84 * @return a list of LinkTuple with exactly 2 unidirectional links
86 public List<Link> getLinkTupleList() {
90 private void setPublishAttributes() {
94 private void parseParams() {
96 throw new PktLinkParamsNotSpecified(nodeDpid1, nodeDpid2);
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")) {
108 } else if (key.equals("port2")) {
111 throw new UnknownPktLinkConfig(key, nodeDpid1, nodeDpid2);
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
122 public static class PktLinkParamsNotSpecified extends RuntimeException {
123 private static final long serialVersionUID = 6247582323691265513L;
125 public PktLinkParamsNotSpecified(String dpidA, String dpidB) {
127 log.error("Params required for packet link - not specified "
128 + "for link between switch1:{} and switch2:{}",
133 public static class UnknownPktLinkConfig extends RuntimeException {
134 private static final long serialVersionUID = -5750132094884129179L;
136 public UnknownPktLinkConfig(String key, String dpidA, String dpidB) {
138 log.error("Unknown packet-link config {} for link between"
139 + " dpid1: {} and dpid2: {}", key,