Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.matchaction; |
| 2 | |
Ray Milkey | c127a5a | 2014-08-20 11:22:12 -0700 | [diff] [blame] | 3 | import java.util.Collections; |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 4 | import java.util.EventListener; |
Ray Milkey | c127a5a | 2014-08-20 11:22:12 -0700 | [diff] [blame] | 5 | import java.util.HashSet; |
| 6 | import java.util.List; |
Brian O'Connor | dee2e6b | 2014-08-12 11:34:51 -0700 | [diff] [blame] | 7 | import java.util.Set; |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 8 | import net.onrc.onos.api.flowmanager.ConflictDetectionPolicy; |
| 9 | |
| 10 | /** |
| 11 | * Manages Match-Action entries. |
| 12 | * <p> |
| 13 | * TODO: Make all methods thread-safe |
| 14 | */ |
Toshio Koide | d8b077a | 2014-08-13 10:47:21 -0700 | [diff] [blame] | 15 | public class MatchActionModule implements MatchActionService { |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 16 | |
Ray Milkey | c127a5a | 2014-08-20 11:22:12 -0700 | [diff] [blame] | 17 | private final HashSet<MatchAction> currentOperations = new HashSet<>(); |
| 18 | |
| 19 | private boolean processMatchActionEntries( |
| 20 | final List<MatchActionOperationEntry> entries) { |
| 21 | int successfulOperations = 0; |
| 22 | for (final MatchActionOperationEntry entry : entries) { |
| 23 | if (currentOperations.add(entry.getTarget())) { |
| 24 | successfulOperations++; |
| 25 | } |
| 26 | } |
| 27 | return entries.size() == successfulOperations; |
| 28 | } |
| 29 | |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 30 | @Override |
| 31 | public boolean addMatchAction(MatchAction matchAction) { |
Brian O'Connor | dee2e6b | 2014-08-12 11:34:51 -0700 | [diff] [blame] | 32 | return false; |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | @Override |
Brian O'Connor | dee2e6b | 2014-08-12 11:34:51 -0700 | [diff] [blame] | 36 | public Set<MatchAction> getMatchActions() { |
Ray Milkey | c127a5a | 2014-08-20 11:22:12 -0700 | [diff] [blame] | 37 | return Collections.unmodifiableSet(currentOperations); |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | @Override |
Brian O'Connor | dee2e6b | 2014-08-12 11:34:51 -0700 | [diff] [blame] | 41 | public boolean executeOperations(final MatchActionOperations operations) { |
Ray Milkey | c127a5a | 2014-08-20 11:22:12 -0700 | [diff] [blame] | 42 | return processMatchActionEntries(operations.getOperations()); |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | @Override |
| 46 | public void setConflictDetectionPolicy(ConflictDetectionPolicy policy) { |
| 47 | // TODO Auto-generated method stub |
| 48 | |
| 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public ConflictDetectionPolicy getConflictDetectionPolicy() { |
| 53 | // TODO Auto-generated method stub |
| 54 | return null; |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public void addEventListener(EventListener listener) { |
| 59 | // TODO Auto-generated method stub |
| 60 | |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public void removeEventListener(EventListener listener) { |
| 65 | // TODO Auto-generated method stub |
| 66 | |
| 67 | } |
| 68 | } |