2 * Copyright 2014-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.
17 package org.onosproject.segmentrouting.config;
19 import com.fasterxml.jackson.databind.node.ArrayNode;
20 import org.onlab.packet.Ip4Address;
21 import org.onlab.packet.MacAddress;
22 import org.onosproject.net.DeviceId;
23 import org.onosproject.net.config.Config;
24 import org.onosproject.net.config.basics.BasicElementConfig;
26 import java.util.ArrayList;
27 import java.util.List;
28 import java.util.Optional;
31 * Configuration object for Segment Routing Application.
33 public class SegmentRoutingConfig extends Config<DeviceId> {
34 private static final String NAME = "name";
35 private static final String IP = "routerIp";
36 private static final String MAC = "routerMac";
37 private static final String SID = "nodeSid";
38 private static final String EDGE = "isEdgeRouter";
39 private static final String ADJSID = "adjacencySids";
41 public Optional<String> getName() {
42 String name = get(NAME, null);
43 return name != null ? Optional.of(name) : Optional.empty();
46 public BasicElementConfig setName(String name) {
47 return (BasicElementConfig) setOrClear(NAME, name);
50 public Ip4Address getIp() {
51 String ip = get(IP, null);
52 return ip != null ? Ip4Address.valueOf(ip) : null;
55 public BasicElementConfig setIp(String ip) {
56 return (BasicElementConfig) setOrClear(IP, ip);
59 public MacAddress getMac() {
60 String mac = get(MAC, null);
61 return mac != null ? MacAddress.valueOf(mac) : null;
64 public BasicElementConfig setMac(String mac) {
65 return (BasicElementConfig) setOrClear(MAC, mac);
72 public BasicElementConfig setSid(int sid) {
73 return (BasicElementConfig) setOrClear(SID, sid);
76 public boolean isEdgeRouter() {
77 return get(EDGE, false);
80 public BasicElementConfig setEdgeRouter(boolean isEdgeRouter) {
81 return (BasicElementConfig) setOrClear(EDGE, isEdgeRouter);
84 public List<AdjacencySid> getAdjacencySids() {
85 ArrayList<AdjacencySid> adjacencySids = new ArrayList<>();
87 if (!object.has(ADJSID)) {
91 ArrayNode adjacencySidNodes = (ArrayNode) object.path(ADJSID);
92 adjacencySidNodes.forEach(adjacencySidNode -> {
93 int asid = adjacencySidNode.path(AdjacencySid.ASID).asInt();
95 ArrayList<Integer> ports = new ArrayList<Integer>();
96 ArrayNode portsNodes = (ArrayNode) adjacencySidNode.path(AdjacencySid.PORTS);
97 portsNodes.forEach(portNode -> {
98 ports.add(portNode.asInt());
101 AdjacencySid adjacencySid = new AdjacencySid(asid, ports);
102 adjacencySids.add(adjacencySid);
105 return adjacencySids;
108 public class AdjacencySid {
109 private static final String ASID = "adjSid";
110 private static final String PORTS = "ports";
115 public AdjacencySid(int asid, List<Integer> ports) {
120 public int getAsid() {
124 public List<Integer> getPorts() {