Jonathan Hart | 8f6dc09 | 2014-04-18 15:56:43 -0700 | [diff] [blame] | 1 | package net.onrc.onos.apps.sdnip; |
Jonathan Hart | 4dfc365 | 2013-08-02 20:22:36 +1200 | [diff] [blame] | 2 | |
| 3 | import java.net.InetAddress; |
| 4 | |
Jonathan Hart | 31e15f1 | 2014-04-10 10:33:00 -0700 | [diff] [blame] | 5 | /** |
| 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 Hart | 99ff20a | 2014-06-15 16:53:00 -0700 | [diff] [blame] | 14 | * other ingress port to the {@code Interface}. |
Jonathan Hart | 31e15f1 | 2014-04-10 10:33:00 -0700 | [diff] [blame] | 15 | * <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 Hart | 4dfc365 | 2013-08-02 20:22:36 +1200 | [diff] [blame] | 30 | */ |
Jonathan Hart | a23ffdb | 2013-08-14 14:36:54 +1200 | [diff] [blame] | 31 | public class Path { |
Jonathan Hart | 738980f | 2014-04-04 10:11:15 -0700 | [diff] [blame] | 32 | private final Interface dstInterface; |
| 33 | private final InetAddress dstIpAddress; |
| 34 | private int numUsers; // initialized to 0 |
Jonathan Hart | 4dfc365 | 2013-08-02 20:22:36 +1200 | [diff] [blame] | 35 | |
Jonathan Hart | c78b8f6 | 2014-08-07 22:31:09 -0700 | [diff] [blame] | 36 | // XXX PushedFlowMod has been removed |
| 37 | //private List<PushedFlowMod> flowMods; // initialized to null |
Jonathan Hart | 738980f | 2014-04-04 10:11:15 -0700 | [diff] [blame] | 38 | private boolean permanent; // initialized to false |
Jonathan Hart | 4dfc365 | 2013-08-02 20:22:36 +1200 | [diff] [blame] | 39 | |
Jonathan Hart | 31e15f1 | 2014-04-10 10:33:00 -0700 | [diff] [blame] | 40 | /** |
| 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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 47 | public Path(Interface dstInterface, InetAddress dstIpAddress) { |
| 48 | this.dstInterface = dstInterface; |
| 49 | this.dstIpAddress = dstIpAddress; |
| 50 | } |
| 51 | |
Jonathan Hart | 31e15f1 | 2014-04-10 10:33:00 -0700 | [diff] [blame] | 52 | /** |
| 53 | * Gets the destination {@link Interface} of the path. |
| 54 | * |
| 55 | * @return the destination interface |
| 56 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 57 | public Interface getDstInterface() { |
| 58 | return dstInterface; |
| 59 | } |
| 60 | |
Jonathan Hart | 31e15f1 | 2014-04-10 10:33:00 -0700 | [diff] [blame] | 61 | /** |
| 62 | * Gets the destination IP address. |
| 63 | * |
| 64 | * @return the destination IP address |
| 65 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 66 | public InetAddress getDstIpAddress() { |
| 67 | return dstIpAddress; |
| 68 | } |
| 69 | |
Jonathan Hart | 31e15f1 | 2014-04-10 10:33:00 -0700 | [diff] [blame] | 70 | /** |
| 71 | * Increments the count of prefixes that use this path. |
| 72 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 73 | public void incrementUsers() { |
| 74 | numUsers++; |
| 75 | } |
| 76 | |
Jonathan Hart | 31e15f1 | 2014-04-10 10:33:00 -0700 | [diff] [blame] | 77 | /** |
| 78 | * Decrements the count of prefixes that use this path. |
| 79 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 80 | public void decrementUsers() { |
| 81 | numUsers--; |
| 82 | } |
| 83 | |
Jonathan Hart | 31e15f1 | 2014-04-10 10:33:00 -0700 | [diff] [blame] | 84 | /** |
| 85 | * Gets the count of prefixes that use this path. |
| 86 | * |
| 87 | * @return the number of prefixes currently using the path |
| 88 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 89 | public int getUsers() { |
| 90 | return numUsers; |
| 91 | } |
| 92 | |
Jonathan Hart | 31e15f1 | 2014-04-10 10:33:00 -0700 | [diff] [blame] | 93 | /** |
| 94 | * Gets the list of flow mods that were installed to realize this path in |
| 95 | * the network. |
| 96 | * |
Jonathan Hart | 99ff20a | 2014-06-15 16:53:00 -0700 | [diff] [blame] | 97 | * @return the list of {@link PushedFlowMod}s |
Jonathan Hart | 31e15f1 | 2014-04-10 10:33:00 -0700 | [diff] [blame] | 98 | */ |
Jonathan Hart | c78b8f6 | 2014-08-07 22:31:09 -0700 | [diff] [blame] | 99 | // XXX PushedFlowMod has been removed |
| 100 | /*public List<PushedFlowMod> getFlowMods() { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 101 | return Collections.unmodifiableList(flowMods); |
Jonathan Hart | c78b8f6 | 2014-08-07 22:31:09 -0700 | [diff] [blame] | 102 | }*/ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 103 | |
Jonathan Hart | 31e15f1 | 2014-04-10 10:33:00 -0700 | [diff] [blame] | 104 | /** |
| 105 | * Sets the list of flow mods that were installed to realize this path in |
| 106 | * the network. |
| 107 | * |
Jonathan Hart | 99ff20a | 2014-06-15 16:53:00 -0700 | [diff] [blame] | 108 | * @param flowMods the list of {@link PushedFlowMod}s |
Jonathan Hart | 31e15f1 | 2014-04-10 10:33:00 -0700 | [diff] [blame] | 109 | */ |
Jonathan Hart | c78b8f6 | 2014-08-07 22:31:09 -0700 | [diff] [blame] | 110 | // XXX PushedFlowMod has been removed |
| 111 | /*public void setFlowMods(List<PushedFlowMod> flowMods) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 112 | this.flowMods = flowMods; |
Jonathan Hart | c78b8f6 | 2014-08-07 22:31:09 -0700 | [diff] [blame] | 113 | }*/ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 114 | |
Jonathan Hart | 31e15f1 | 2014-04-10 10:33:00 -0700 | [diff] [blame] | 115 | /** |
| 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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 121 | public boolean isPermanent() { |
| 122 | return permanent; |
| 123 | } |
| 124 | |
Jonathan Hart | 31e15f1 | 2014-04-10 10:33:00 -0700 | [diff] [blame] | 125 | /** |
| 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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 130 | public void setPermanent() { |
| 131 | permanent = true; |
| 132 | } |
Jonathan Hart | 4dfc365 | 2013-08-02 20:22:36 +1200 | [diff] [blame] | 133 | } |