blob: 28b632bd82a93a0d75c7e5f9f99b4706f723d1e3 [file] [log] [blame]
Jonathan Hart8f6dc092014-04-18 15:56:43 -07001package net.onrc.onos.apps.sdnip;
Jonathan Hart4dfc3652013-08-02 20:22:36 +12002
3import java.net.InetAddress;
Jonathan Hart309889c2013-08-13 23:26:24 +12004import java.util.Collections;
5import java.util.List;
Jonathan Hart4dfc3652013-08-02 20:22:36 +12006
Jonathan Hart31e15f12014-04-10 10:33:00 -07007/**
8 * A {@link Path} represents paths within a network that forward traffic from
9 * ingress port to egress port. For every {@code next_hop} received in route
10 * updates from BGPd, we need to push forwarding paths from every other
11 * possible ingress port to the egress port connected to the {@code next_hop}.
12 * <p/>
13 * The {@link Path} object doesn't contain lists of hops along the path.
14 * Rather, it contains details about the egress {@link Interface} and
15 * {@code next_hop} IP address. Implicitly, it represents paths from every
Jonathan Hart99ff20a2014-06-15 16:53:00 -070016 * other ingress port to the {@code Interface}.
Jonathan Hart31e15f12014-04-10 10:33:00 -070017 * <p/>
18 * Once flow mods are pushed to realize the path in the network, the
19 * {@link Path} object will contain a list of pushed flow mods. These are used
20 * if the path ever needs to be deleted.
21 * <p/>
22 * On startup, paths are pushed to all configured BGP peers, on the assumption
23 * that they're likely to advertise routes to us. These paths are permanent
24 * because the list of peers can't currently change at runtime. If we receive
25 * a route for a {@code next_hop} which is not a peer, a temporary path will
26 * be installed. These paths are temporary because they are removed if all
27 * routes that use them are removed.
28 * <p/>
29 * Finally, the {@link Path} object counts references of prefixes that make use
30 * of the path. If the reference count drops to zero as prefixes are deleted,
31 * the path is no longer useful and will be removed from the network.
Jonathan Hart4dfc3652013-08-02 20:22:36 +120032 */
Jonathan Harta23ffdb2013-08-14 14:36:54 +120033public class Path {
Jonathan Hart738980f2014-04-04 10:11:15 -070034 private final Interface dstInterface;
35 private final InetAddress dstIpAddress;
36 private int numUsers; // initialized to 0
Jonathan Hart4dfc3652013-08-02 20:22:36 +120037
Jonathan Hart738980f2014-04-04 10:11:15 -070038 private List<PushedFlowMod> flowMods; // initialized to null
39 private boolean permanent; // initialized to false
Jonathan Hart4dfc3652013-08-02 20:22:36 +120040
Jonathan Hart31e15f12014-04-10 10:33:00 -070041 /**
42 * Class constructor, taking the destination {@link Interface} and
43 * destination IP address for the path.
44 *
45 * @param dstInterface the destination interface
46 * @param dstIpAddress the destination IP address
47 */
Ray Milkey269ffb92014-04-03 14:43:30 -070048 public Path(Interface dstInterface, InetAddress dstIpAddress) {
49 this.dstInterface = dstInterface;
50 this.dstIpAddress = dstIpAddress;
51 }
52
Jonathan Hart31e15f12014-04-10 10:33:00 -070053 /**
54 * Gets the destination {@link Interface} of the path.
55 *
56 * @return the destination interface
57 */
Ray Milkey269ffb92014-04-03 14:43:30 -070058 public Interface getDstInterface() {
59 return dstInterface;
60 }
61
Jonathan Hart31e15f12014-04-10 10:33:00 -070062 /**
63 * Gets the destination IP address.
64 *
65 * @return the destination IP address
66 */
Ray Milkey269ffb92014-04-03 14:43:30 -070067 public InetAddress getDstIpAddress() {
68 return dstIpAddress;
69 }
70
Jonathan Hart31e15f12014-04-10 10:33:00 -070071 /**
72 * Increments the count of prefixes that use this path.
73 */
Ray Milkey269ffb92014-04-03 14:43:30 -070074 public void incrementUsers() {
75 numUsers++;
76 }
77
Jonathan Hart31e15f12014-04-10 10:33:00 -070078 /**
79 * Decrements the count of prefixes that use this path.
80 */
Ray Milkey269ffb92014-04-03 14:43:30 -070081 public void decrementUsers() {
82 numUsers--;
83 }
84
Jonathan Hart31e15f12014-04-10 10:33:00 -070085 /**
86 * Gets the count of prefixes that use this path.
87 *
88 * @return the number of prefixes currently using the path
89 */
Ray Milkey269ffb92014-04-03 14:43:30 -070090 public int getUsers() {
91 return numUsers;
92 }
93
Jonathan Hart31e15f12014-04-10 10:33:00 -070094 /**
95 * Gets the list of flow mods that were installed to realize this path in
96 * the network.
97 *
Jonathan Hart99ff20a2014-06-15 16:53:00 -070098 * @return the list of {@link PushedFlowMod}s
Jonathan Hart31e15f12014-04-10 10:33:00 -070099 */
Ray Milkey269ffb92014-04-03 14:43:30 -0700100 public List<PushedFlowMod> getFlowMods() {
101 return Collections.unmodifiableList(flowMods);
102 }
103
Jonathan Hart31e15f12014-04-10 10:33:00 -0700104 /**
105 * Sets the list of flow mods that were installed to realize this path in
106 * the network.
107 *
Jonathan Hart99ff20a2014-06-15 16:53:00 -0700108 * @param flowMods the list of {@link PushedFlowMod}s
Jonathan Hart31e15f12014-04-10 10:33:00 -0700109 */
Ray Milkey269ffb92014-04-03 14:43:30 -0700110 public void setFlowMods(List<PushedFlowMod> flowMods) {
111 this.flowMods = flowMods;
112 }
113
Jonathan Hart31e15f12014-04-10 10:33:00 -0700114 /**
115 * Signifies whether the path is permanent and shouldn't be deleted when
116 * the number of users drops to zero.
117 *
118 * @return true if the path is permanent, false if not
119 */
Ray Milkey269ffb92014-04-03 14:43:30 -0700120 public boolean isPermanent() {
121 return permanent;
122 }
123
Jonathan Hart31e15f12014-04-10 10:33:00 -0700124 /**
125 * Set the permanent status of the path to true. Paths are not permanent
126 * by default when constructed, and this method can be used to designate
127 * them as permanent.
128 */
Ray Milkey269ffb92014-04-03 14:43:30 -0700129 public void setPermanent() {
130 permanent = true;
131 }
Jonathan Hart4dfc3652013-08-02 20:22:36 +1200132}