Saurav Das | f710bd3 | 2014-09-25 16:56:00 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.matchaction.match; |
| 2 | |
Sangho Shin | 47701ec | 2014-10-01 15:09:40 -0700 | [diff] [blame] | 3 | import net.onrc.onos.core.util.IPv4; |
Saurav Das | f710bd3 | 2014-09-25 16:56:00 -0700 | [diff] [blame] | 4 | import net.onrc.onos.core.util.IPv4Net; |
| 5 | |
| 6 | public class Ipv4Match implements Match { |
| 7 | |
| 8 | IPv4Net dstIp; |
| 9 | |
| 10 | public Ipv4Match(String ipAddressSlash) { |
| 11 | this.dstIp = new IPv4Net(ipAddressSlash); |
Sangho Shin | 47701ec | 2014-10-01 15:09:40 -0700 | [diff] [blame] | 12 | |
| 13 | IPv4 ip = dstIp.address(); |
| 14 | short prefLen = dstIp.prefixLen(); |
| 15 | int mask = ~((1 << (32 - prefLen)) - 1);; |
| 16 | int newIpInt = ip.value() & mask; |
| 17 | IPv4 newIp = new IPv4(newIpInt); |
| 18 | |
| 19 | this.dstIp = new IPv4Net(newIp, prefLen); |
Saurav Das | f710bd3 | 2014-09-25 16:56:00 -0700 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | public IPv4Net getDestination() { |
| 23 | return dstIp; |
| 24 | } |
| 25 | |
| 26 | } |