VirtualBox

Changeset 36275 in vbox


Ignore:
Timestamp:
Mar 14, 2011 6:01:34 PM (14 years ago)
Author:
vboxsync
Message:

Main/NetworkAdapter: Bandwidth group attribute implementation (#5582)

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/settings.h

    r36082 r36275  
    441441          mode(NetworkAttachmentType_Null),
    442442          ulBootPriority(0),
    443           fHasDisabledNAT(false),
    444           ulBandwidthLimit(0)
     443          fHasDisabledNAT(false)
    445444    {}
    446445
     
    466465    uint32_t                            ulBootPriority;
    467466    bool                                fHasDisabledNAT;
    468     uint32_t                            ulBandwidthLimit;
     467    com::Utf8Str                        strBandwidthGroup; // requires settings version 1.13 (VirtualBox 4.2)
    469468};
    470469typedef std::list<NetworkAdapter> NetworkAdaptersList;
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp

    r36082 r36275  
    208208                     "                            [--nicbootprio<1-N> <priority>]\n"
    209209                     "                            [--nicpromisc<1-N> deny|allow-vms|allow-all]\n"
     210                     "                            [--nicbandwidthgroup<1-N> <name>\n"
    210211                     "                            [--bridgeadapter<1-N> none|<devicename>]\n"
    211212#if defined(VBOX_WITH_NETFLT)
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageModifyVM.cpp

    r36082 r36275  
    105105    MODIFYVM_NICBOOTPRIO,
    106106    MODIFYVM_NICPROMISC,
     107    MODIFYVM_NICBWGROUP,
    107108    MODIFYVM_NIC,
    108109    MODIFYVM_CABLECONNECTED,
     
    232233    { "--nicbootprio",              MODIFYVM_NICBOOTPRIO,               RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_INDEX },
    233234    { "--nicpromisc",               MODIFYVM_NICPROMISC,                RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
     235    { "--nicbandwidthgroup",        MODIFYVM_NICBWGROUP,                RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
    234236    { "--nic",                      MODIFYVM_NIC,                       RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
    235237    { "--cableconnected",           MODIFYVM_CABLECONNECTED,            RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX },
     
    11091111            }
    11101112
     1113            case MODIFYVM_NICBWGROUP:
     1114            {
     1115                ComPtr<INetworkAdapter> nic;
     1116                CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
     1117                ASSERT(nic);
     1118
     1119                if (!RTStrICmp(ValueUnion.psz, "none"))
     1120                {
     1121                    /* Just remove the bandwidth group. */
     1122                    CHECK_ERROR(nic, COMSETTER(BandwidthGroup)(NULL));
     1123                    //CHECK_ERROR(nic, COMSETTER(BandwidthGroup)(bwGroup));
     1124                    //CHECK_ERROR(machine, SetBandwidthGroupForNetworkAdapter(GetOptState.uIndex - 1, NULL));
     1125                }
     1126                else
     1127                {
     1128                    ComPtr<IBandwidthControl> bwCtrl;
     1129                    ComPtr<IBandwidthGroup> bwGroup;
     1130
     1131                    CHECK_ERROR(machine, COMGETTER(BandwidthControl)(bwCtrl.asOutParam()));
     1132
     1133                    if (SUCCEEDED(rc))
     1134                    {
     1135                        CHECK_ERROR(bwCtrl, GetBandwidthGroup(Bstr(ValueUnion.psz).raw(), bwGroup.asOutParam()));
     1136                        if (SUCCEEDED(rc))
     1137                        {
     1138                            CHECK_ERROR(nic, COMSETTER(BandwidthGroup)(bwGroup));
     1139                        }
     1140                    }
     1141                }
     1142                break;
     1143            }
     1144
    11111145            case MODIFYVM_NIC:
    11121146            {
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r36224 r36275  
    488488    </const>
    489489
     490    <const name="v1_13"     value="15">
     491      <desc>Settings version "1.13", written by VirtualBox 4.2.x.</desc>
     492      <!--
     493          NetworkAdapter changes: bandwidth group.
     494      -->
     495    </const>
     496
    490497    <const name="Future"     value="99999">
    491       <desc>Settings version greater than "1.11", written by a future VirtualBox version.</desc>
     498      <desc>Settings version greater than "1.13", written by a future VirtualBox version.</desc>
    492499    </const>
    493500  </enum>
     
    1182711834  <interface
    1182811835    name="INetworkAdapter" extends="$unknown"
    11829     uuid="2178cf4f-d961-42f4-ba76-59539234b337"
     11836    uuid="6aa240a1-dd58-478e-92e8-aac001ce5547"
    1183011837    wsmap="managed"
    1183111838    >
     
    1194911956    </attribute>
    1195011957
    11951     <attribute name="bandwidthLimit" type="unsigned long">
    11952       <desc>
    11953         Maximum throughput allowed for this network adapter, in units of 1 mbps.
    11954         A zero value means uncapped/unlimited.
    11955       </desc>
     11958    <attribute name="bandwidthGroup" type="IBandwidthGroup">
     11959      <desc>The bandwidth group this network adapter is assigned to.</desc>
    1195611960    </attribute>
    1195711961
  • trunk/src/VBox/Main/include/NetworkAdapterImpl.h

    r36082 r36275  
    2323#include "VirtualBoxBase.h"
    2424#include "NATEngineImpl.h"
     25#include "BandwidthGroupImpl.h"
    2526
    2627class GuestOSType;
     
    7172        Bstr mNATNetwork;
    7273        ULONG mBootPriority;
    73         ULONG mBandwidthLimit;
     74        ComObjPtr<BandwidthGroup> mBandwidthGroup;
    7475    };
    7576
     
    125126    STDMETHOD(COMGETTER(BootPriority)) (ULONG *aBootPriority);
    126127    STDMETHOD(COMSETTER(BootPriority)) (ULONG aBootPriority);
    127     STDMETHOD(COMGETTER(BandwidthLimit)) (ULONG *aLimit);
    128     STDMETHOD(COMSETTER(BandwidthLimit)) (ULONG aLimit);
     128    STDMETHOD(COMGETTER(BandwidthGroup)) (IBandwidthGroup **aBwGroup);
     129    STDMETHOD(COMSETTER(BandwidthGroup)) (IBandwidthGroup *aBwGroup);
    129130
    130131    // INetworkAdapter methods
     
    138139    // public methods only for internal purposes
    139140
    140     HRESULT loadSettings(const settings::NetworkAdapter &data);
     141    HRESULT loadSettings(BandwidthControl *bwctl, const settings::NetworkAdapter &data);
    141142    HRESULT saveSettings(settings::NetworkAdapter &data);
    142143
     
    151152    void detach();
    152153    void generateMACAddress();
     154    HRESULT updateMacAddress(Utf8Str aMacAddress);
     155    void updateBandwidthGroup(BandwidthGroup *aBwGroup);
    153156
    154157    Machine * const     mParent;
  • trunk/src/VBox/Main/src-server/MachineImpl.cpp

    r36219 r36275  
    74687468        if (FAILED(rc)) return rc;
    74697469
     7470        // Bandwidth control (must come before network adapters)
     7471        rc = mBandwidthControl->loadSettings(data.ioSettings);
     7472        if (FAILED(rc)) return rc;
     7473
    74707474        /* USB Controller */
    74717475        rc = mUSBController->loadSettings(data.usbController);
     
    74817485            /* slot unicity is guaranteed by XML Schema */
    74827486            AssertBreak(nic.ulSlot < RT_ELEMENTS(mNetworkAdapters));
    7483             rc = mNetworkAdapters[nic.ulSlot]->loadSettings(nic);
     7487            rc = mNetworkAdapters[nic.ulSlot]->loadSettings(mBandwidthControl, nic);
    74847488            if (FAILED(rc)) return rc;
    74857489        }
     
    75337537        mHWData->mIoCacheEnabled = data.ioSettings.fIoCacheEnabled;
    75347538        mHWData->mIoCacheSize = data.ioSettings.ulIoCacheSize;
    7535 
    7536         // Bandwidth control
    7537         rc = mBandwidthControl->loadSettings(data.ioSettings);
    7538         if (FAILED(rc)) return rc;
    75397539
    75407540        // Host PCI devices
  • trunk/src/VBox/Main/src-server/NetworkAdapterImpl.cpp

    r36105 r36275  
    8585    /* initialize data */
    8686    mData->mSlot = aSlot;
    87 
    88     /* Default limit is not capped/unlimited. */
    89     mData->mBandwidthLimit = 0;
    9087
    9188    /* default to Am79C973 */
     
    340337}
    341338
    342 STDMETHODIMP NetworkAdapter::COMSETTER(MACAddress)(IN_BSTR aMACAddress)
    343 {
    344     AutoCaller autoCaller(this);
    345     if (FAILED(autoCaller.rc())) return autoCaller.rc();
    346 
    347     /* the machine needs to be mutable */
    348     AutoMutableStateDependency adep(mParent);
    349     if (FAILED(adep.rc())) return adep.rc();
    350 
     339HRESULT NetworkAdapter::updateMacAddress(Utf8Str aMACAddress)
     340{
    351341    HRESULT rc = S_OK;
    352     bool emitChangeEvent = false;
    353342
    354343    /*
    355344     * Are we supposed to generate a MAC?
    356345     */
    357     if (!aMACAddress || !*aMACAddress)
    358     {
    359         AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    360         mData.backup();
    361 
     346    if (aMACAddress.isEmpty())
    362347        generateMACAddress();
    363         emitChangeEvent = true;
    364 
    365         m_fModified = true;
    366         // leave the lock before informing callbacks
    367         alock.release();
    368 
    369         AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS);       // mParent is const, no need to lock
    370         mParent->setModified(Machine::IsModified_NetworkAdapters);
    371         mlock.release();
    372     }
    373348    else
    374349    {
    375         AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    376350        if (mData->mMACAddress != aMACAddress)
    377351        {
     
    379353             * Verify given MAC address
    380354             */
    381             Utf8Str macAddressUtf = aMACAddress;
    382             char *macAddressStr = macAddressUtf.mutableRaw();
     355            char *macAddressStr = aMACAddress.mutableRaw();
    383356            int i = 0;
    384357            while ((i < 13) && macAddressStr && *macAddressStr && (rc == S_OK))
     
    408381
    409382            if (SUCCEEDED(rc))
    410             {
    411                 mData.backup();
    412 
    413                 mData->mMACAddress = macAddressUtf;
    414 
    415                 emitChangeEvent = true;
    416 
    417                 m_fModified = true;
    418                 // leave the lock before informing callbacks
    419                 alock.release();
    420 
    421                 AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS);       // mParent is const, no need to lock
    422                 mParent->setModified(Machine::IsModified_NetworkAdapters);
    423                 mlock.release();
    424             }
     383                mData->mMACAddress = aMACAddress;
    425384        }
    426385    }
    427386
    428     // we have left the lock in any case at this point
    429 
    430     if (emitChangeEvent)
    431     {
     387    return rc;
     388}
     389
     390STDMETHODIMP NetworkAdapter::COMSETTER(MACAddress)(IN_BSTR aMACAddress)
     391{
     392    AutoCaller autoCaller(this);
     393    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     394
     395    /* the machine needs to be mutable */
     396    AutoMutableStateDependency adep(mParent);
     397    if (FAILED(adep.rc())) return adep.rc();
     398
     399
     400    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     401    mData.backup();
     402
     403    HRESULT rc = updateMacAddress(aMACAddress);
     404    if (SUCCEEDED(rc))
     405    {
     406        m_fModified = true;
     407        // leave the lock before informing callbacks
     408        alock.release();
     409
     410        AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS);       // mParent is const, no need to lock
     411        mParent->setModified(Machine::IsModified_NetworkAdapters);
     412        mlock.release();
     413
    432414        /* Changing the MAC via the Main API during runtime is not allowed,
    433415         * therefore no immediate change in CFGM logic => changeAdapter=FALSE. */
     
    799781
    800782    return hrc;
    801 }
    802 
    803 STDMETHODIMP NetworkAdapter::COMGETTER(BandwidthLimit) (ULONG *aLimit)
    804 {
    805     CheckComArgOutPointerValid(aLimit);
    806 
    807     AutoCaller autoCaller(this);
    808     if (FAILED(autoCaller.rc())) return autoCaller.rc();
    809 
    810     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    811 
    812     *aLimit = mData->mBandwidthLimit;
    813     return S_OK;
    814 }
    815 
    816 STDMETHODIMP NetworkAdapter::COMSETTER(BandwidthLimit) (ULONG aLimit)
    817 {
    818     AutoCaller autoCaller(this);
    819     if (FAILED(autoCaller.rc())) return autoCaller.rc();
    820 
    821     /* the machine doesn't need to be mutable */
    822 
    823     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    824 
    825     if (aLimit != mData->mBandwidthLimit)
    826     {
    827         mData.backup();
    828         mData->mBandwidthLimit = aLimit;
    829 
    830         m_fModified = true;
    831         // leave the lock before informing callbacks
    832         alock.release();
    833 
    834         AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS);       // mParent is const, no need to lock
    835         mParent->setModified(Machine::IsModified_NetworkAdapters);
    836         mlock.release();
    837 
    838         /* No change in CFGM logic => changeAdapter=FALSE. */
    839         mParent->onNetworkAdapterChange(this, FALSE);
    840     }
    841     return S_OK;
    842783}
    843784
     
    12791220 *  @note Locks this object for writing.
    12801221 */
    1281 HRESULT NetworkAdapter::loadSettings(const settings::NetworkAdapter &data)
     1222HRESULT NetworkAdapter::loadSettings(BandwidthControl *bwctl,
     1223                                     const settings::NetworkAdapter &data)
    12821224{
    12831225    AutoCaller autoCaller(this);
    12841226    AssertComRCReturnRC(autoCaller.rc());
     1227
     1228    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    12851229
    12861230    /* Note: we assume that the default values for attributes of optional
     
    13001244    mData->mEnabled = data.fEnabled;
    13011245    /* MAC address (can be null) */
    1302     rc = COMSETTER(MACAddress)(Bstr(data.strMACAddress).raw());
     1246    rc = updateMacAddress(data.strMACAddress);
    13031247    if (FAILED(rc)) return rc;
    13041248    /* cable (required) */
     
    13121256    /* boot priority (defaults to 0, i.e. lowest) */
    13131257    mData->mBootPriority = data.ulBootPriority;
    1314     /* Bandwidth limit in Mbps. */
    1315     mData->mBandwidthLimit = data.ulBandwidthLimit;
     1258    /* bandwidth group */
     1259    if (data.strBandwidthGroup.isEmpty())
     1260        updateBandwidthGroup(NULL);
     1261    else
     1262    {
     1263        ComObjPtr<BandwidthGroup> group;
     1264        rc = bwctl->getBandwidthGroupByName(data.strBandwidthGroup, group, true); // TODO: set error?
     1265        if (FAILED(rc)) return rc;
     1266    }
     1267   
     1268    // leave the lock before attaching
     1269    alock.release();
    13161270
    13171271    switch (data.mode)
     
    13981352    data.ulBootPriority = mData->mBootPriority;
    13991353
    1400     data.ulBandwidthLimit = mData->mBandwidthLimit;
     1354    if (mData->mBandwidthGroup.isNull())
     1355        data.strBandwidthGroup = "";
     1356    else
     1357        data.strBandwidthGroup = mData->mBandwidthGroup->getName();
    14011358
    14021359    data.type = mData->mAdapterType;
     
    16291586    mData->mMACAddress = strMAC;
    16301587}
     1588
     1589STDMETHODIMP NetworkAdapter::COMGETTER(BandwidthGroup) (IBandwidthGroup **aBwGroup)
     1590{
     1591    LogFlowThisFuncEnter();
     1592    CheckComArgOutPointerValid(aBwGroup);
     1593
     1594    AutoCaller autoCaller(this);
     1595    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     1596
     1597    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     1598
     1599    mData->mBandwidthGroup.queryInterfaceTo(aBwGroup);
     1600
     1601    LogFlowThisFuncLeave();
     1602    return S_OK;
     1603}
     1604
     1605STDMETHODIMP NetworkAdapter::COMSETTER(BandwidthGroup) (IBandwidthGroup *aBwGroup)
     1606{
     1607    LogFlowThisFuncEnter();
     1608    CheckComArgOutPointerValid(aBwGroup);
     1609
     1610    AutoCaller autoCaller(this);
     1611    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     1612
     1613    /* the machine needs to be mutable */
     1614    AutoMutableStateDependency adep(mParent);
     1615    if (FAILED(adep.rc())) return adep.rc();
     1616
     1617    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     1618
     1619    //HRESULT hrc = S_OK;
     1620
     1621    if (mData->mBandwidthGroup != aBwGroup)
     1622    {
     1623        mData.backup();
     1624
     1625        updateBandwidthGroup(static_cast<BandwidthGroup*>(aBwGroup));
     1626
     1627        m_fModified = true;
     1628        // leave the lock before informing callbacks
     1629        alock.release();
     1630
     1631        AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS);
     1632        mParent->setModified(Machine::IsModified_NetworkAdapters);
     1633        mlock.release();
     1634
     1635        /* TODO: changeAdapter=???. */
     1636        mParent->onNetworkAdapterChange(this, FALSE);
     1637    }
     1638
     1639    LogFlowThisFuncLeave();
     1640    return S_OK;
     1641}
     1642
     1643void NetworkAdapter::updateBandwidthGroup(BandwidthGroup *aBwGroup)
     1644{
     1645    LogFlowThisFuncEnter();
     1646    Assert(isWriteLockOnCurrentThread());
     1647
     1648    mData.backup();
     1649    if (!mData->mBandwidthGroup.isNull())
     1650    {
     1651        mData->mBandwidthGroup->release();
     1652        mData->mBandwidthGroup.setNull();
     1653    }
     1654
     1655    if (aBwGroup)
     1656    {
     1657        mData->mBandwidthGroup = aBwGroup;
     1658        mData->mBandwidthGroup->reference();
     1659    }
     1660
     1661    LogFlowThisFuncLeave();
     1662}
    16311663/* vi: set tabstop=4 shiftwidth=4 expandtab: */
  • trunk/src/VBox/Main/xml/Settings.cpp

    r36168 r36275  
    19461946        pelmAdapter->getAttributeValue("tracefile", nic.strTraceFile);
    19471947        pelmAdapter->getAttributeValue("bootPriority", nic.ulBootPriority);
    1948         pelmAdapter->getAttributeValue("bandwidthLimit", nic.ulBandwidthLimit);
     1948        pelmAdapter->getAttributeValue("bandwidthGroup", nic.strBandwidthGroup);
    19491949
    19501950        xml::ElementNodesList llNetworkModes;
     
    36953695            pelmAdapter->setAttribute("tracefile", nic.strTraceFile);
    36963696        }
    3697         if (nic.ulBandwidthLimit)
    3698             pelmAdapter->setAttribute("bandwidthLimit", nic.ulBandwidthLimit);
     3697        if (nic.strBandwidthGroup.isNotEmpty())
     3698            pelmAdapter->setAttribute("bandwidthGroup", nic.strBandwidthGroup);
    36993699
    37003700        const char *pszPolicy;
     
    47294729             ++netit)
    47304730        {
    4731             if (    (m->sv < SettingsVersion_v1_11)
    4732                  && (netit->ulBandwidthLimit)
     4731            if (    (m->sv < SettingsVersion_v1_12)
     4732                 && (netit->strBandwidthGroup.isNotEmpty())
    47334733               )
    47344734            {
    4735                 /* New in VirtualBox 4.0 */
    4736                 m->sv = SettingsVersion_v1_11;
     4735                /* New in VirtualBox 4.1 */
     4736                m->sv = SettingsVersion_v1_12;
    47374737                break;
    47384738            }
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette