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