Jonathan Hart | 16e1fa2 | 2016-02-16 13:06:26 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.igmp; |
| 18 | |
| 19 | import com.fasterxml.jackson.databind.JsonNode; |
Jonathan Hart | 965b9f9 | 2016-02-16 13:06:26 -0800 | [diff] [blame] | 20 | import com.fasterxml.jackson.databind.node.ObjectNode; |
Jonathan Hart | 16e1fa2 | 2016-02-16 13:06:26 -0800 | [diff] [blame] | 21 | import org.onlab.packet.IpAddress; |
| 22 | import org.onosproject.core.ApplicationId; |
| 23 | import org.onosproject.net.config.Config; |
| 24 | import org.onosproject.net.mcast.McastRoute; |
| 25 | |
| 26 | import java.util.ArrayList; |
| 27 | import java.util.List; |
| 28 | |
| 29 | /** |
Jonathan Hart | 965b9f9 | 2016-02-16 13:06:26 -0800 | [diff] [blame] | 30 | * IGMP SSM translate configuration. |
Jonathan Hart | 16e1fa2 | 2016-02-16 13:06:26 -0800 | [diff] [blame] | 31 | */ |
| 32 | public class IgmpSsmTranslateConfig extends Config<ApplicationId> { |
Jonathan Hart | 965b9f9 | 2016-02-16 13:06:26 -0800 | [diff] [blame] | 33 | |
Jonathan Hart | 16e1fa2 | 2016-02-16 13:06:26 -0800 | [diff] [blame] | 34 | private static final String SOURCE = "source"; |
| 35 | private static final String GROUP = "group"; |
| 36 | |
Jonathan Hart | 965b9f9 | 2016-02-16 13:06:26 -0800 | [diff] [blame] | 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 | */ |
Jonathan Hart | 16e1fa2 | 2016-02-16 13:06:26 -0800 | [diff] [blame] | 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 | } |