blob: f69d76aeccc044a363d560e9eb5228b0290690ab [file] [log] [blame]
Jonathan Hart5e8689c2016-02-16 13:06:26 -08001/*
2 * Copyright 2016 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.igmp;
18
19import com.fasterxml.jackson.databind.JsonNode;
Jonathan Hart3a8896b2016-02-16 13:06:26 -080020import com.fasterxml.jackson.databind.node.ObjectNode;
Jonathan Hart5e8689c2016-02-16 13:06:26 -080021import 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/**
Jonathan Hart3a8896b2016-02-16 13:06:26 -080030 * IGMP SSM translate configuration.
Jonathan Hart5e8689c2016-02-16 13:06:26 -080031 */
32public class IgmpSsmTranslateConfig extends Config<ApplicationId> {
Jonathan Hart3a8896b2016-02-16 13:06:26 -080033
Jonathan Hart5e8689c2016-02-16 13:06:26 -080034 private static final String SOURCE = "source";
35 private static final String GROUP = "group";
36
Jonathan Hart3a8896b2016-02-16 13:06:26 -080037 @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 */
Jonathan Hart5e8689c2016-02-16 13:06:26 -080058 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}