Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 1 | /** |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 2 | * Copyright 2011, Big Switch Networks, Inc. |
| 3 | * Originally created by David Erickson, Stanford University |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | * not use this file except in compliance with the License. You may obtain |
| 7 | * a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | * License for the specific language governing permissions and limitations |
| 15 | * under the License. |
| 16 | **/ |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 17 | |
| 18 | package net.floodlightcontroller.core.internal; |
| 19 | |
| 20 | import java.util.List; |
| 21 | import java.util.concurrent.CopyOnWriteArrayList; |
| 22 | import java.util.concurrent.TimeUnit; |
| 23 | |
| 24 | import net.floodlightcontroller.core.IOFSwitch; |
| 25 | import net.floodlightcontroller.threadpool.IThreadPoolService; |
| 26 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 27 | import org.projectfloodlight.openflow.protocol.OFMessage; |
| 28 | import org.projectfloodlight.openflow.protocol.OFStatsReply; |
| 29 | import org.projectfloodlight.openflow.protocol.OFStatsReplyFlags; |
| 30 | import org.projectfloodlight.openflow.protocol.OFType; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * A concrete implementation that handles asynchronously receiving OFStatistics |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 34 | * |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 35 | * @author David Erickson (daviderickson@cs.stanford.edu) |
| 36 | */ |
| 37 | public class OFStatisticsFuture extends |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 38 | OFMessageFuture<List<OFStatsReply>> { |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 39 | |
| 40 | protected volatile boolean finished; |
| 41 | |
| 42 | public OFStatisticsFuture(IThreadPoolService tp, |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 43 | IOFSwitch sw, int transactionId) { |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 44 | super(tp, sw, OFType.STATS_REPLY, transactionId); |
| 45 | init(); |
| 46 | } |
| 47 | |
| 48 | public OFStatisticsFuture(IThreadPoolService tp, |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 49 | IOFSwitch sw, int transactionId, long timeout, |
| 50 | TimeUnit unit) { |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 51 | super(tp, sw, OFType.STATS_REPLY, transactionId, timeout, unit); |
| 52 | init(); |
| 53 | } |
| 54 | |
| 55 | private void init() { |
| 56 | this.finished = false; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 57 | this.result = new CopyOnWriteArrayList<OFStatsReply>(); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | @Override |
| 61 | protected void handleReply(IOFSwitch sw, OFMessage msg) { |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 62 | OFStatsReply sr = (OFStatsReply) msg; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 63 | synchronized (this.result) { |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 64 | this.result.add(sr); |
| 65 | if ( !(sr.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) ) { |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 66 | this.finished = true; |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | protected boolean isFinished() { |
| 73 | return finished; |
| 74 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 75 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 76 | @Override |
| 77 | protected void unRegister() { |
| 78 | super.unRegister(); |
| 79 | sw.cancelStatisticsReply(transactionId); |
| 80 | } |
| 81 | } |