2 * Copyright 2015 Open Networking Laboratory
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onosproject.segmentrouting.config;
18 import java.util.List;
19 import java.util.Map.Entry;
21 import java.util.concurrent.ConcurrentHashMap;
23 import org.onosproject.net.Link;
24 import org.onosproject.segmentrouting.config.NetworkConfig.LinkConfig;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 import com.fasterxml.jackson.databind.JsonNode;
31 * Reserved for future use.
32 * Configuration for a link between two packet-switches.
34 public class PktLinkConfig extends LinkConfig {
35 protected static final Logger log = LoggerFactory
36 .getLogger(PktLinkConfig.class);
39 private String nodeName1;
40 private String nodeName2;
41 private List<Link> linkTupleList;
43 public PktLinkConfig(LinkConfig lkc) {
44 nodeDpid1 = lkc.getNodeDpid1();
45 nodeDpid2 = lkc.getNodeDpid2();
46 dpid1 = lkc.getDpid1();
47 dpid2 = lkc.getDpid2();
49 allowed = lkc.isAllowed();
50 params = lkc.getParams();
51 publishAttributes = new ConcurrentHashMap<>();
54 setPublishAttributes();
57 // ********************
58 // Packet Link Configuration
59 // ********************
61 public int getPort1() {
65 public void setPort1(int port1) {
69 public int getPort2() {
73 public void setPort2(int port2) {
77 public String getNodeName1() {
81 public void setNodeName1(String nodeName1) {
82 this.nodeName1 = nodeName1;
85 public String getNodeName2() {
89 public void setNodeName2(String nodeName2) {
90 this.nodeName2 = nodeName2;
94 * Returns the two unidirectional links corresponding to the packet-link
95 * configuration. It is possible that the ports in the LinkTuple have
96 * portnumber '0', implying that the configuration applies to all links
97 * between the two switches.
99 * @return a list of LinkTuple with exactly 2 unidirectional links
101 public List<Link> getLinkTupleList() {
102 return linkTupleList;
105 private void setPublishAttributes() {
109 private void parseParams() {
110 if (params == null) {
111 throw new PktLinkParamsNotSpecified(nodeDpid1, nodeDpid2);
113 Set<Entry<String, JsonNode>> m = params.entrySet();
114 for (Entry<String, JsonNode> e : m) {
115 String key = e.getKey();
116 JsonNode j = e.getValue();
117 if (key.equals("nodeName1")) {
118 setNodeName1(j.asText());
119 } else if (key.equals("nodeName2")) {
120 setNodeName2(j.asText());
121 } else if (key.equals("port1")) {
123 } else if (key.equals("port2")) {
126 throw new UnknownPktLinkConfig(key, nodeDpid1, nodeDpid2);
131 private void validateParams() {
132 // TODO - wrong-names, duplicate links,
133 // duplicate use of port, is switch-allowed for which link is allowed?
134 // valid port numbers
137 public static class PktLinkParamsNotSpecified extends RuntimeException {
138 private static final long serialVersionUID = 6247582323691265513L;
140 public PktLinkParamsNotSpecified(String dpidA, String dpidB) {
142 log.error("Params required for packet link - not specified "
143 + "for link between switch1:{} and switch2:{}",
148 public static class UnknownPktLinkConfig extends RuntimeException {
149 private static final long serialVersionUID = -5750132094884129179L;
151 public UnknownPktLinkConfig(String key, String dpidA, String dpidB) {
153 log.error("Unknown packet-link config {} for link between"
154 + " dpid1: {} and dpid2: {}", key,