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