# Copyright (c) 2011-2013 Peng Sun. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the COPYRIGHT file.

# HONE application
# Test lazy materialization for conn measurement
# Matcht test in exp2: connStatsAll

from hone_lib import *

def query():
    q = (Select(['app', 
                 'ThruOctetsReceived',
                 'OtherReductionsCM',
                 'OtherReductionsCV',
                 'MaxRTT',
                 'SoftErrorReason',
                 'SndLimTimeSnd',
                 'MaxRTO',
                 'Rcvbuf',
                 'RetranThresh',
                 'SegmentsOut',
                 'NonRecovDAEpisodes',
                 'IpTtl',
                 'CongSignals',
                 'BytesSentOut',
                 'DataSegsOut',
                 'srcIP',
                 'LimRwin',
                 'dstPort',
                 'MSSRcvd',
                 'WinScaleSent',
                 'ZeroRwinRcvd',
                 'StartTimeSecs',
                 'AbruptTimeouts',
                 'NonRecovDA',
                 'WinScaleRcvd',
                 'Sndbuf',
                 'SpuriousFrDetected',
                 'IpTosOut',
                 'State',
                 'Nagle',
                 'CurReasmQueue',
                 'ECESent',
                 'DupAcksOut',
                 'SndLimTimeCwnd',
                 'MaxReasmQueue',
                 'CurSsthresh',
                 'MSSSent',
                 'SpuriousRtoDetected',
                 'CurAppRQueue',
                 'RTT',
                 'DupAcksIn',
                 'MaxMSS',
                 'LimCwnd',
                 'TimeStamps',
                 'MinSsthresh',
                 'RcvRTT',
                 'BytesReceived',
                 'CurAppWQueue',
                 'SendStall',
                 'SACKsRcvd',
                 'SndLimTimeRwin',
                 'SegsIn',
                 'RTTVar',
                 'SndLimTransCwnd',
                 'MaxRwinSent',
                 'IpTosIn',
                 'SndInitial',
                 'MaxPipeSize',
                 'ECNsignals',
                 'PreCongSumCwnd',
                 'InRecovery',
                 'SndLimTransRwin',
                 'SubsequentTimeouts',
                 'MaxAppRQueue',
                 'ElapsedMicroSecs',
                 'LocalAddressType',
                 'DSACKDups',
                 'BytesRetran',
                 'MinRTO',
                 'MinMSS',
                 'WillSendSACK',
                 'ECN',
                 'MaxSsthresh',
                 'PipeSize',
                 'SumOctetsReordered',
                 'MinRTT',
                 'MaxCaCwnd',
                 'SumRTT',
                 'PostCongSumRTT',
                 'RecInitial',
                 'DupAckEpisodes',
                 'SACKBlocksRcvd',
                 'WillUseSACK',
                 'ThruOctetsAcked',
                 'OtherReductions',
                 'MaxRwinRcvd',
                 'SlowStart',
                 'MaxSsCwnd',
                 'SegsRetrans',
                 'CongOverCount',
                 'LimMSS',
                 'CurRTO',
                 'CERcvd',
                 'CountRTT',
                 'CurRetxQueue',
                 'dstIP',
                 'PreCongSumRTT',
                 'SoftErrors',
                 'srcPort',
                 'SndLimTransSnd',
                 'ElapsedSecs',
                 'PostCongCountRTT',
                 'ActiveOpen',
                 'StartTimeMicroSecs',
                 'SmoothedRTT',
                 'Rwnd',
                 'CongAvoid',
                 'ZeroRwinSent',
                 'Timeouts',
                 'SndMax',
                 'SndUna',
                 'MaxRetxQueue',
                 'CurRwinSent',
                 'FastRetran',
                 'LimSsthresh',
                 'SndNxt',
                 'RemAddressType',
                 'Cwnd',
                 'CurTimeoutCount',
                 'MaxAppWQueue',
                 'DataSegsIn',
                 'RcvNxt',
                 'CurMSS']) *
         From('HostConnection') *
         #Where([('app', '==', 'test_prog')]) *
         Every(1000))
    return q

def GetLen(x):
    print len(x)
    if x:
        print x[0]
    return x

def main():
    return (query()>>MapStreamSet(GetLen)>>MergeHosts()>>Print(GetLen))
