blob: 19107be623ffb8b8944e48b902d743991fddf551 [file] [log] [blame]
Jonathan Hart4cb39882015-08-12 23:50:55 -04001/*
2 * Copyright 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.routing.config;
18
19import com.fasterxml.jackson.databind.JsonNode;
20import com.google.common.collect.Sets;
21import org.onlab.packet.IpAddress;
22import org.onosproject.core.ApplicationId;
23import org.onosproject.net.config.Config;
24import org.onosproject.net.ConnectPoint;
25
26import java.util.Set;
27
28import static com.google.common.base.Preconditions.checkNotNull;
29
30/**
31 * Configuration object for BGP config.
32 */
33public class BgpConfig extends Config<ApplicationId> {
34
35 public static final String SPEAKERS = "bgpSpeakers";
36 public static final String CONNECT_POINT = "connectPoint";
37 public static final String PEERS = "peers";
38
39 // TODO add methods for updating config
40
41 /**
42 * Gets the set of configured BGP speakers.
43 *
44 * @return BGP speakers
45 */
46 public Set<BgpSpeakerConfig> bgpSpeakers() {
47 Set<BgpSpeakerConfig> speakers = Sets.newHashSet();
48
Thomas Vachuska0a400ea2015-09-04 11:25:03 -070049 JsonNode speakersNode = object.get(SPEAKERS);
Jonathan Hart4cb39882015-08-12 23:50:55 -040050 speakersNode.forEach(jsonNode -> {
51 Set<IpAddress> listenAddresses = Sets.newHashSet();
52 jsonNode.path(PEERS).forEach(addressNode ->
53 listenAddresses.add(IpAddress.valueOf(addressNode.asText()))
54 );
55 speakers.add(new BgpSpeakerConfig(
56 ConnectPoint.deviceConnectPoint(jsonNode.path(CONNECT_POINT).asText()),
57 listenAddresses));
58 });
59
60 return speakers;
61 }
62
63 /**
64 * Configuration for a BGP speaker.
65 */
66 public static class BgpSpeakerConfig {
67
68 private ConnectPoint connectPoint;
69 private Set<IpAddress> peers;
70
71 public BgpSpeakerConfig(ConnectPoint connectPoint, Set<IpAddress> peers) {
72 this.connectPoint = checkNotNull(connectPoint);
73 this.peers = checkNotNull(peers);
74 }
75
76 public ConnectPoint connectPoint() {
77 return connectPoint;
78 }
79
80 public Set<IpAddress> peers() {
81 return peers;
82 }
83 }
84}