blob: 7a6dd27d8d3c14f99286afd3ea17299880c95b5c [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;
4
Jonathan Hart31e15f12014-04-10 10:33:00 -07005/**
6 * A {@link Path} represents paths within a network that forward traffic from
7 * ingress port to egress port. For every {@code next_hop} received in route
8 * updates from BGPd, we need to push forwarding paths from every other
9 * possible ingress port to the egress port connected to the {@code next_hop}.
10 * <p/>
11 * The {@link Path} object doesn't contain lists of hops along the path.
12 * Rather, it contains details about the egress {@link Interface} and
13 * {@code next_hop} IP address. Implicitly, it represents paths from every
Jonathan Hart99ff20a2014-06-15 16:53:00 -070014 * other ingress port to the {@code Interface}.
Jonathan Hart31e15f12014-04-10 10:33:00 -070015 * <p/>
16 * Once flow mods are pushed to realize the path in the network, the
17 * {@link Path} object will contain a list of pushed flow mods. These are used
18 * if the path ever needs to be deleted.
19 * <p/>
20 * On startup, paths are pushed to all configured BGP peers, on the assumption
21 * that they're likely to advertise routes to us. These paths are permanent
22 * because the list of peers can't currently change at runtime. If we receive
23 * a route for a {@code next_hop} which is not a peer, a temporary path will
24 * be installed. These paths are temporary because they are removed if all
25 * routes that use them are removed.
26 * <p/>
27 * Finally, the {@link Path} object counts references of prefixes that make use
28 * of the path. If the reference count drops to zero as prefixes are deleted,
29 * the path is no longer useful and will be removed from the network.
Jonathan Hart4dfc3652013-08-02 20:22:36 +120030 */
Jonathan Harta23ffdb2013-08-14 14:36:54 +120031public class Path {
Jonathan Hart738980f2014-04-04 10:11:15 -070032 private final Interface dstInterface;
33 private final InetAddress dstIpAddress;
34 private int numUsers; // initialized to 0
Jonathan Hart4dfc3652013-08-02 20:22:36 +120035
Jonathan Hartc78b8f62014-08-07 22:31:09 -070036 // XXX PushedFlowMod has been removed
37 //private List<PushedFlowMod> flowMods; // initialized to null
Jonathan Hart738980f2014-04-04 10:11:15 -070038 private boolean permanent; // initialized to false
Jonathan Hart4dfc3652013-08-02 20:22:36 +120039
Jonathan Hart31e15f12014-04-10 10:33:00 -070040 /**
41 * Class constructor, taking the destination {@link Interface} and
42 * destination IP address for the path.
43 *
44 * @param dstInterface the destination interface
45 * @param dstIpAddress the destination IP address
46 */
Ray Milkey269ffb92014-04-03 14:43:30 -070047 public Path(Interface dstInterface, InetAddress dstIpAddress) {
48 this.dstInterface = dstInterface;
49 this.dstIpAddress = dstIpAddress;
50 }
51
Jonathan Hart31e15f12014-04-10 10:33:00 -070052 /**
53 * Gets the destination {@link Interface} of the path.
54 *
55 * @return the destination interface
56 */
Ray Milkey269ffb92014-04-03 14:43:30 -070057 public Interface getDstInterface() {
58 return dstInterface;
59 }
60
Jonathan Hart31e15f12014-04-10 10:33:00 -070061 /**
62 * Gets the destination IP address.
63 *
64 * @return the destination IP address
65 */
Ray Milkey269ffb92014-04-03 14:43:30 -070066 public InetAddress getDstIpAddress() {
67 return dstIpAddress;
68 }
69
Jonathan Hart31e15f12014-04-10 10:33:00 -070070 /**
71 * Increments the count of prefixes that use this path.
72 */
Ray Milkey269ffb92014-04-03 14:43:30 -070073 public void incrementUsers() {
74 numUsers++;
75 }
76
Jonathan Hart31e15f12014-04-10 10:33:00 -070077 /**
78 * Decrements the count of prefixes that use this path.
79 */
Ray Milkey269ffb92014-04-03 14:43:30 -070080 public void decrementUsers() {
81 numUsers--;
82 }
83
Jonathan Hart31e15f12014-04-10 10:33:00 -070084 /**
85 * Gets the count of prefixes that use this path.
86 *
87 * @return the number of prefixes currently using the path
88 */
Ray Milkey269ffb92014-04-03 14:43:30 -070089 public int getUsers() {
90 return numUsers;
91 }
92
Jonathan Hart31e15f12014-04-10 10:33:00 -070093 /**
94 * Gets the list of flow mods that were installed to realize this path in
95 * the network.
96 *
Jonathan Hart99ff20a2014-06-15 16:53:00 -070097 * @return the list of {@link PushedFlowMod}s
Jonathan Hart31e15f12014-04-10 10:33:00 -070098 */
Jonathan Hartc78b8f62014-08-07 22:31:09 -070099 // XXX PushedFlowMod has been removed
100 /*public List<PushedFlowMod> getFlowMods() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700101 return Collections.unmodifiableList(flowMods);
Jonathan Hartc78b8f62014-08-07 22:31:09 -0700102 }*/
Ray Milkey269ffb92014-04-03 14:43:30 -0700103
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 */
Jonathan Hartc78b8f62014-08-07 22:31:09 -0700110 // XXX PushedFlowMod has been removed
111 /*public void setFlowMods(List<PushedFlowMod> flowMods) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700112 this.flowMods = flowMods;
Jonathan Hartc78b8f62014-08-07 22:31:09 -0700113 }*/
Ray Milkey269ffb92014-04-03 14:43:30 -0700114
Jonathan Hart31e15f12014-04-10 10:33:00 -0700115 /**
116 * Signifies whether the path is permanent and shouldn't be deleted when
117 * the number of users drops to zero.
118 *
119 * @return true if the path is permanent, false if not
120 */
Ray Milkey269ffb92014-04-03 14:43:30 -0700121 public boolean isPermanent() {
122 return permanent;
123 }
124
Jonathan Hart31e15f12014-04-10 10:33:00 -0700125 /**
126 * Set the permanent status of the path to true. Paths are not permanent
127 * by default when constructed, and this method can be used to designate
128 * them as permanent.
129 */
Ray Milkey269ffb92014-04-03 14:43:30 -0700130 public void setPermanent() {
131 permanent = true;
132 }
Jonathan Hart4dfc3652013-08-02 20:22:36 +1200133}