blob: 3a668bb9ef9cb787b93c8f173a33e9487fdd9dc4 [file] [log] [blame]
Jonathan Hartaa380972014-04-03 10:24:46 -07001package net.onrc.onos.core.intent;
Toshio Koidead17d5e2014-02-11 11:36:02 -08002
Toshio Koide7d3cee02014-06-05 18:56:19 -07003import java.util.Objects;
Toshio Koidead17d5e2014-02-11 11:36:02 -08004
5/**
6 * @author Toshio Koide (t-koide@onlab.us)
7 */
8public class PathIntent extends Intent {
Ray Milkey269ffb92014-04-03 14:43:30 -07009 protected Path path;
10 protected double bandwidth;
11 protected Intent parentIntent;
Toshio Koidec406e792014-02-14 16:52:42 -080012
Ray Milkey269ffb92014-04-03 14:43:30 -070013 public static String createFirstId(String parentId) {
14 return String.format("%s___0", parentId);
15 }
Toshio Koidea10c0372014-02-20 17:28:10 -080016
Ray Milkey269ffb92014-04-03 14:43:30 -070017 public static String createNextId(String currentId) {
Ray Milkey45614c52014-04-07 16:30:54 -070018 String[] parts = currentId.split("___");
Yuta HIGUCHI0fe749a2014-05-27 09:35:16 -070019 return String.format("%s___%d", parts[0], Long.parseLong(parts[1]) + 1);
Ray Milkey269ffb92014-04-03 14:43:30 -070020 }
Toshio Koidea10c0372014-02-20 17:28:10 -080021
Ray Milkey269ffb92014-04-03 14:43:30 -070022 /**
Ray Milkeyb41100a2014-04-10 10:42:15 -070023 * Default constructor for Kryo deserialization.
Ray Milkey269ffb92014-04-03 14:43:30 -070024 */
25 protected PathIntent() {
26 }
Toshio Koidead17d5e2014-02-11 11:36:02 -080027
Ray Milkey269ffb92014-04-03 14:43:30 -070028 /**
Ray Milkey269ffb92014-04-03 14:43:30 -070029 * @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 Koidead17d5e2014-02-11 11:36:02 -080041
Ray Milkey269ffb92014-04-03 14:43:30 -070042 public double getBandwidth() {
43 return bandwidth;
44 }
Toshio Koidead17d5e2014-02-11 11:36:02 -080045
Ray Milkey269ffb92014-04-03 14:43:30 -070046 public Path getPath() {
47 return path;
48 }
Toshio Koidec406e792014-02-14 16:52:42 -080049
Ray Milkey269ffb92014-04-03 14:43:30 -070050 public Intent getParentIntent() {
51 return parentIntent;
52 }
Toshio Koide93be5d62014-02-23 19:30:57 -080053
Toshio Koide7d3cee02014-06-05 18:56:19 -070054 /**
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 Milkey269ffb92014-04-03 14:43:30 -070074 @Override
Pavlin Radoslavov7fb16412014-04-11 18:45:19 -070075 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 Milkey269ffb92014-04-03 14:43:30 -070087 public String toString() {
88 return String.format("%s, %s, %s", getId(), getState(), getPath());
89 }
Toshio Koidead17d5e2014-02-11 11:36:02 -080090}