blob: 618ebbc0676c433688206f1c0b52bf412360e576 [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
19import org.onlab.packet.Ip4Address;
20import org.onlab.packet.MacAddress;
21import org.onosproject.net.DeviceId;
22import org.onosproject.net.config.Config;
23import org.onosproject.net.config.basics.BasicElementConfig;
24
25import java.util.ArrayList;
26import java.util.List;
27import java.util.Optional;
28
29/**
30 * Configuration object for Segment Routing Application.
31 */
32public class SegmentRoutingConfig extends Config<DeviceId> {
33 private static final String NAME = "name";
34 private static final String IP = "routerIp";
35 private static final String MAC = "routerMac";
36 private static final String SID = "nodeSid";
37 private static final String EDGE = "isEdgeRouter";
38
39 public Optional<String> getName() {
40 String name = get(NAME, null);
41 return name != null ? Optional.of(name) : Optional.empty();
42 }
43
44 public BasicElementConfig setName(String name) {
45 return (BasicElementConfig) setOrClear(NAME, name);
46 }
47
48 public Ip4Address getIp() {
49 String ip = get(IP, null);
50 return ip != null ? Ip4Address.valueOf(ip) : null;
51 }
52
53 public BasicElementConfig setIp(String ip) {
54 return (BasicElementConfig) setOrClear(IP, ip);
55 }
56
57 public MacAddress getMac() {
58 String mac = get(MAC, null);
59 return mac != null ? MacAddress.valueOf(mac) : null;
60 }
61
62 public BasicElementConfig setMac(String mac) {
63 return (BasicElementConfig) setOrClear(MAC, mac);
64 }
65
66 public int getSid() {
67 return get(SID, -1);
68 }
69
70 public BasicElementConfig setSid(int sid) {
71 return (BasicElementConfig) setOrClear(SID, sid);
72 }
73
74 public boolean isEdgeRouter() {
75 return get(EDGE, false);
76 }
77
78 public BasicElementConfig setEdgeRouter(boolean isEdgeRouter) {
79 return (BasicElementConfig) setOrClear(EDGE, isEdgeRouter);
80 }
81
82 // TODO extract array from JsonNode
83 public List<AdjacencySid> getAdjacencySids() {
84 return new ArrayList<AdjacencySid>();
85 }
86
87 public class AdjacencySid {
88 int sid;
89 List<Integer> ports;
90
91 public AdjacencySid(int sid, List<Integer> ports) {
92 this.sid = sid;
93 this.ports = ports;
94 }
95
96 public int getSid() {
97 return sid;
98 }
99
100 public List<Integer> getPorts() {
101 return ports;
102 }
103 }
104}