blob: 8565a1bdb0910eb6ef9e8a144fd0a395f7a7904a [file] [log] [blame]
ke han81a38b92017-03-10 18:41:44 +08001/*
Brian O'Connor4d084702017-08-03 22:45:58 -07002 * Copyright 2017-present Open Networking Foundation
ke han81a38b92017-03-10 18:41:44 +08003 *
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 */
ke han81a38b92017-03-10 18:41:44 +080016package org.opencord.igmpproxy;
17
18import com.fasterxml.jackson.databind.JsonNode;
19import com.fasterxml.jackson.databind.node.ObjectNode;
20import org.onlab.packet.IpAddress;
21import org.onosproject.core.ApplicationId;
Esin Karamaneff10392019-06-27 18:09:13 +000022import org.onosproject.mcast.api.McastRoute;
ke han81a38b92017-03-10 18:41:44 +080023import org.onosproject.net.config.Config;
ke han81a38b92017-03-10 18:41:44 +080024
25import java.util.ArrayList;
26import java.util.List;
27
28/**
29 * IGMP proxy SSM translate configuration.
30 */
31public class IgmpproxySsmTranslateConfig extends Config<ApplicationId> {
32
33 private static final String SOURCE = "source";
34 private static final String GROUP = "group";
35
36 @Override
37 public boolean isValid() {
38 for (JsonNode node : array) {
39 if (!hasOnlyFields((ObjectNode) node, SOURCE, GROUP)) {
40 return false;
41 }
42
43 if (!(isIpAddress((ObjectNode) node, SOURCE, FieldPresence.MANDATORY) &&
44 isIpAddress((ObjectNode) node, GROUP, FieldPresence.MANDATORY))) {
45 return false;
46 }
47
48 }
49 return true;
50 }
51
52 /**
53 * Gets the list of SSM translations.
54 *
55 * @return SSM translations
56 */
57 public List<McastRoute> getSsmTranslations() {
58 List<McastRoute> translations = new ArrayList();
59 for (JsonNode node : array) {
60 translations.add(
61 new McastRoute(
62 IpAddress.valueOf(node.path(SOURCE).asText().trim()),
63 IpAddress.valueOf(node.path(GROUP).asText().trim()),
64 McastRoute.Type.STATIC));
65 }
66
67 return translations;
68 }
69}