blob: 6dc3f0dbbcff2a76829b6bc0d6a0ad901cdc6aa2 [file] [log] [blame]
Charles Chand6832882015-10-05 17:50:33 -07001/*
2 * Copyright 2014-2015 Open Networking Laboratory
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17package org.onosproject.segmentrouting.config;
18
Charles Chan4636be02015-10-07 14:21:45 -070019import com.fasterxml.jackson.databind.node.ArrayNode;
Charles Chand6832882015-10-05 17:50:33 -070020import org.onlab.packet.Ip4Address;
21import org.onlab.packet.MacAddress;
22import org.onosproject.net.DeviceId;
23import org.onosproject.net.config.Config;
24import org.onosproject.net.config.basics.BasicElementConfig;
25
26import java.util.ArrayList;
27import java.util.List;
28import java.util.Optional;
29
30/**
31 * Configuration object for Segment Routing Application.
32 */
33public 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";
Charles Chan4636be02015-10-07 14:21:45 -070039 private static final String ADJSID = "adjacencySids";
Charles Chand6832882015-10-05 17:50:33 -070040
41 public Optional<String> getName() {
42 String name = get(NAME, null);
43 return name != null ? Optional.of(name) : Optional.empty();
44 }
45
46 public BasicElementConfig setName(String name) {
47 return (BasicElementConfig) setOrClear(NAME, name);
48 }
49
50 public Ip4Address getIp() {
51 String ip = get(IP, null);
52 return ip != null ? Ip4Address.valueOf(ip) : null;
53 }
54
55 public BasicElementConfig setIp(String ip) {
56 return (BasicElementConfig) setOrClear(IP, ip);
57 }
58
59 public MacAddress getMac() {
60 String mac = get(MAC, null);
61 return mac != null ? MacAddress.valueOf(mac) : null;
62 }
63
64 public BasicElementConfig setMac(String mac) {
65 return (BasicElementConfig) setOrClear(MAC, mac);
66 }
67
68 public int getSid() {
69 return get(SID, -1);
70 }
71
72 public BasicElementConfig setSid(int sid) {
73 return (BasicElementConfig) setOrClear(SID, sid);
74 }
75
76 public boolean isEdgeRouter() {
77 return get(EDGE, false);
78 }
79
80 public BasicElementConfig setEdgeRouter(boolean isEdgeRouter) {
81 return (BasicElementConfig) setOrClear(EDGE, isEdgeRouter);
82 }
83
Charles Chand6832882015-10-05 17:50:33 -070084 public List<AdjacencySid> getAdjacencySids() {
Charles Chan4636be02015-10-07 14:21:45 -070085 ArrayList<AdjacencySid> adjacencySids = new ArrayList<>();
86
87 if (!object.has(ADJSID)) {
88 return adjacencySids;
89 }
90
91 ArrayNode adjacencySidNodes = (ArrayNode) object.path(ADJSID);
92 adjacencySidNodes.forEach(adjacencySidNode -> {
93 int asid = adjacencySidNode.path(AdjacencySid.ASID).asInt();
94
95 ArrayList<Integer> ports = new ArrayList<Integer>();
96 ArrayNode portsNodes = (ArrayNode) adjacencySidNode.path(AdjacencySid.PORTS);
97 portsNodes.forEach(portNode -> {
98 ports.add(portNode.asInt());
99 });
100
101 AdjacencySid adjacencySid = new AdjacencySid(asid, ports);
102 adjacencySids.add(adjacencySid);
103 });
104
105 return adjacencySids;
Charles Chand6832882015-10-05 17:50:33 -0700106 }
107
108 public class AdjacencySid {
Charles Chan4636be02015-10-07 14:21:45 -0700109 private static final String ASID = "adjSid";
110 private static final String PORTS = "ports";
111
112 int asid;
Charles Chand6832882015-10-05 17:50:33 -0700113 List<Integer> ports;
114
Charles Chan4636be02015-10-07 14:21:45 -0700115 public AdjacencySid(int asid, List<Integer> ports) {
116 this.asid = asid;
Charles Chand6832882015-10-05 17:50:33 -0700117 this.ports = ports;
118 }
119
Charles Chan4636be02015-10-07 14:21:45 -0700120 public int getAsid() {
121 return asid;
Charles Chand6832882015-10-05 17:50:33 -0700122 }
123
124 public List<Integer> getPorts() {
125 return ports;
126 }
127 }
128}