Jonathan Hart | aa38097 | 2014-04-03 10:24:46 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.intent; |
Toshio Koide | ad17d5e | 2014-02-11 11:36:02 -0800 | [diff] [blame] | 2 | |
Toshio Koide | 7d3cee0 | 2014-06-05 18:56:19 -0700 | [diff] [blame^] | 3 | import java.util.Objects; |
Toshio Koide | ad17d5e | 2014-02-11 11:36:02 -0800 | [diff] [blame] | 4 | |
| 5 | /** |
| 6 | * @author Toshio Koide (t-koide@onlab.us) |
| 7 | */ |
| 8 | public class PathIntent extends Intent { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 9 | protected Path path; |
| 10 | protected double bandwidth; |
| 11 | protected Intent parentIntent; |
Toshio Koide | c406e79 | 2014-02-14 16:52:42 -0800 | [diff] [blame] | 12 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 13 | public static String createFirstId(String parentId) { |
| 14 | return String.format("%s___0", parentId); |
| 15 | } |
Toshio Koide | a10c037 | 2014-02-20 17:28:10 -0800 | [diff] [blame] | 16 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 17 | public static String createNextId(String currentId) { |
Ray Milkey | 45614c5 | 2014-04-07 16:30:54 -0700 | [diff] [blame] | 18 | String[] parts = currentId.split("___"); |
Yuta HIGUCHI | 0fe749a | 2014-05-27 09:35:16 -0700 | [diff] [blame] | 19 | return String.format("%s___%d", parts[0], Long.parseLong(parts[1]) + 1); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 20 | } |
Toshio Koide | a10c037 | 2014-02-20 17:28:10 -0800 | [diff] [blame] | 21 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 22 | /** |
Ray Milkey | b41100a | 2014-04-10 10:42:15 -0700 | [diff] [blame] | 23 | * Default constructor for Kryo deserialization. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 24 | */ |
| 25 | protected PathIntent() { |
| 26 | } |
Toshio Koide | ad17d5e | 2014-02-11 11:36:02 -0800 | [diff] [blame] | 27 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 28 | /** |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 29 | * @param path |
| 30 | * @param bandwidth bandwidth which should be allocated for the path. |
| 31 | * If 0, no intent for bandwidth allocation (best effort). |
| 32 | * @param parentIntent parent intent. If null, this is root intent. |
| 33 | * @param id |
| 34 | */ |
| 35 | public PathIntent(String id, Path path, double bandwidth, Intent parentIntent) { |
| 36 | super(id); |
| 37 | this.path = path; |
| 38 | this.bandwidth = bandwidth; |
| 39 | this.parentIntent = parentIntent; |
| 40 | } |
Toshio Koide | ad17d5e | 2014-02-11 11:36:02 -0800 | [diff] [blame] | 41 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 42 | public double getBandwidth() { |
| 43 | return bandwidth; |
| 44 | } |
Toshio Koide | ad17d5e | 2014-02-11 11:36:02 -0800 | [diff] [blame] | 45 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 46 | public Path getPath() { |
| 47 | return path; |
| 48 | } |
Toshio Koide | c406e79 | 2014-02-14 16:52:42 -0800 | [diff] [blame] | 49 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 50 | public Intent getParentIntent() { |
| 51 | return parentIntent; |
| 52 | } |
Toshio Koide | 93be5d6 | 2014-02-23 19:30:57 -0800 | [diff] [blame] | 53 | |
Toshio Koide | 7d3cee0 | 2014-06-05 18:56:19 -0700 | [diff] [blame^] | 54 | /** |
| 55 | * Checks the specified PathIntent have the same fields of |
| 56 | * path, bandwidth and parentIntent's id with this PathIntent. |
| 57 | * |
| 58 | * @param target target PathIntent instance |
| 59 | * @return true if the specified intent has the same fields, otherwise false |
| 60 | */ |
| 61 | public boolean hasSameFields(PathIntent target) { |
| 62 | if (target == null) { |
| 63 | return false; |
| 64 | } |
| 65 | if (!Objects.equals(getPath(), target.getPath())) { |
| 66 | return false; |
| 67 | } |
| 68 | if (getBandwidth() != target.getBandwidth()) { |
| 69 | return false; |
| 70 | } |
| 71 | return Objects.equals(getParentIntent(), target.getParentIntent()); |
| 72 | } |
| 73 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 74 | @Override |
Pavlin Radoslavov | 7fb1641 | 2014-04-11 18:45:19 -0700 | [diff] [blame] | 75 | public int hashCode() { |
| 76 | // TODO: Is this the intended behavior? |
| 77 | return (super.hashCode()); |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public boolean equals(Object obj) { |
| 82 | // TODO: Is this the intended behavior? |
| 83 | return (super.equals(obj)); |
| 84 | } |
| 85 | |
| 86 | @Override |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 87 | public String toString() { |
| 88 | return String.format("%s, %s, %s", getId(), getState(), getPath()); |
| 89 | } |
Toshio Koide | ad17d5e | 2014-02-11 11:36:02 -0800 | [diff] [blame] | 90 | } |