Beispiel #1
0
MT500::MT500(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MT500)
{
    log = true;
    if(log) MTLOG("MT500 Object Constructed");
    ui->setupUi(this);
    //Set program version here /////////
    progVer = "V.013";
    ////////////////////////////////////
    ui->versionLbl->setText("Program Version: " + progVer);
    ui->rxLabel->setText("Messages Transmitted: 0");
    initial = false;
    ui->ipTable->setColumnWidth(0, 120);
    getConfig();
    byteCount = 0;
    recordCnt = 0;
    cloudCnt = 0;
    setupRS232(COMin, COMout);
    initialCount = countFile("/home/administrator/Desktop/data.log");
    resetTimer = new QTimer(this);
    connect(resetTimer, SIGNAL(timeout()), this, SLOT(resetPorts()));
    validMsgTimer = new QTimer(this);
    connect(validMsgTimer, SIGNAL(timeout()), this, SLOT(clrBuf()));
    hbTimer = new QTimer(this);
    connect(hbTimer, SIGNAL(timeout()), this, SLOT(sendHB()));
    fipsTimer = new QTimer(this);
    connect(fipsTimer, SIGNAL(timeout()), this, SLOT(getFips()));
    msgCount = 0; //Does not include heartbeat messages
    getIPs();
    getFipsCounts();

    //
    // Initially we copy the current files to the previous file
    // directory so that we have something to compare to the first
    // time we sync the FIPS files
    //
    qDebug() << "Starting to copy...";
    //copyProc = new QProcess(this);
    QString oldDir = fipsDir + "old/";
    QString cmd = QString("cp %1*.dat %2").arg(fipsDir).arg(oldDir);
    system(cmd.toStdString().c_str());
    //copyParms << QString("%1*.dat").arg(fipsDir) << oldDir;
    //copyProc->start("cp", copyParms);
    //copyProc->waitForFinished(-1);
    //copyProc->terminate ();
    qDebug() << "Done copying...";

    for(int i = 0; i < 20; i++) {
        sockets[i] = new QTcpSocket(this);
    }
    if(log) MTLOG(QString("HB Interval: %1 min").arg(heartbeatInterval));
    if(log) MTLOG(QString("Fips Retrieval Interval: %1 min").arg(fipsInterval));
    hbTimer->start(heartbeatInterval*1000*60);
    fipsTimer->start(fipsInterval*60*1000);
    resetTimer->start(3600000 * 3); //Reset COM ports every 3 hours
    sendHB();
}
shared_ptr<SwitchState> ThriftConfigApplier::run() {
    auto newState = orig_->clone();
    bool changed = false;

    processVlanPorts();

    {
        auto newPorts = updatePorts();
        if (newPorts) {
            newState->resetPorts(std::move(newPorts));
            changed = true;
        }
    }

    {
        auto newIntfs = updateInterfaces();
        if (newIntfs) {
            newState->resetIntfs(std::move(newIntfs));
            changed = true;
        }
    }

    // Note: updateInterfaces() must be called before updateVlans(),
    // as updateInterfaces() populates the vlanInterfaces_ data structure.
    {
        auto newVlans = updateVlans();
        if (newVlans) {
            newState->resetVlans(std::move(newVlans));
            changed = true;
        }
    }

    // Note: updateInterfaces() must be called before updateRouteTables(),
    // as updateInterfaces() populates the intfRouteTables_ data structure.
    {
        auto newTables = updateRouteTables();
        if (newTables) {
            newState->resetRouteTables(std::move(newTables));
            changed = true;
        }
    }

    // Make sure all interfaces refer to valid VLANs.
    auto newVlans = newState->getVlans();
    for (const auto& vlanInfo : vlanInterfaces_) {
        if (newVlans->getVlanIf(vlanInfo.first) == nullptr) {
            throw FbossError("Interface ",
                             *(vlanInfo.second.interfaces.begin()),
                             " refers to non-existent VLAN ", vlanInfo.first);
        }
    }

    VlanID dfltVlan(cfg_->defaultVlan);
    if (orig_->getDefaultVlan() != dfltVlan) {
        if (newVlans->getVlanIf(dfltVlan) == nullptr) {
            throw FbossError("Default VLAN ", dfltVlan, " does not exist");
        }
        newState->setDefaultVlan(dfltVlan);
        changed = true;
    }

    std::chrono::seconds arpAgerInterval(cfg_->arpAgerInterval);
    if (orig_->getArpAgerInterval() != arpAgerInterval) {
        newState->setArpAgerInterval(arpAgerInterval);
        changed = true;
    }

    if (!changed) {
        return nullptr;
    }
    return newState;
}