Davide Sanvito | 05983ba | 2017-12-01 11:46:44 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 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.imr.data; |
| 18 | |
| 19 | import com.fasterxml.jackson.annotation.JsonCreator; |
| 20 | import com.fasterxml.jackson.annotation.JsonProperty; |
| 21 | import com.google.common.base.MoreObjects; |
| 22 | import org.onosproject.core.ApplicationId; |
| 23 | import org.onosproject.core.DefaultApplicationId; |
| 24 | import org.onosproject.net.intent.Key; |
| 25 | |
| 26 | import java.util.List; |
| 27 | import java.util.Map; |
| 28 | |
| 29 | /** |
| 30 | * Representation of a route submitted by the off-platform application |
| 31 | * to be applied to an existing intent. |
| 32 | * It is composed by the key and the application id of the intent to modify |
| 33 | * and a list of possible {@link Path}. |
| 34 | */ |
| 35 | public class Route { |
| 36 | private Key key; |
| 37 | private ApplicationId appId; |
| 38 | private List<Path> paths; |
| 39 | |
| 40 | /** |
| 41 | * Returns the intent key the route refers to. |
| 42 | * @return the intent key |
| 43 | */ |
| 44 | public Key key() { |
| 45 | return key; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Returns the Application ID of the intent that has to be modified. |
| 50 | * @return the Application ID |
| 51 | */ |
| 52 | public ApplicationId appId() { |
| 53 | return appId; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Returns the list of the {@link Path} on which the intent has to be routed. |
| 58 | * @return the list of path |
| 59 | */ |
| 60 | public List<Path> paths() { |
| 61 | return paths; |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public String toString() { |
| 66 | return MoreObjects.toStringHelper(this) |
| 67 | .add("IntentKey", this.key) |
| 68 | .add("ApplicationId", this.appId) |
| 69 | .add("Paths", this.paths) |
| 70 | .toString(); |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Creates the route using Jackson from a JSON Object. |
| 75 | * @param iKey the intent key |
| 76 | * @param appId application id |
| 77 | * @param paths list of paths |
| 78 | */ |
| 79 | @JsonCreator |
| 80 | public Route(@JsonProperty("key") String iKey, |
| 81 | @JsonProperty("appId") Map<String, String> appId, |
| 82 | @JsonProperty("paths") List<Path> paths) { |
| 83 | this.paths = paths; |
| 84 | this.appId = new DefaultApplicationId(Integer.valueOf(appId.get("id")), appId.get("name")); |
| 85 | this.key = Key.of(iKey, this.appId); |
| 86 | } |
| 87 | } |