All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.sdnwiselab.sdnwise.flowtable.FlowTableStats Maven / Gradle / Ivy

/* 
 * Copyright (C) 2015 SDN-WISE
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see .
 */
package com.github.sdnwiselab.sdnwise.flowtable;

import java.util.Arrays;

/**
 *
 * @author seby
 */
public class FlowTableStats implements FlowTableInterface {

    public final static byte SIZE = 2;
    public final static byte COPY_SIZE = 2;
    
    private final byte[] stats = new byte[SIZE];
    private final byte ttlIndex = 0;
    private final byte countIndex = 1;

    public FlowTableStats() {
        stats[ttlIndex] = (byte) 255;
        stats[countIndex] = 0;
    }

    public FlowTableStats(byte[] value) {
        if (value.length == 2) {
            stats[ttlIndex] = value[ttlIndex];
            stats[countIndex] = value[countIndex];
        } else {
            stats[ttlIndex] = (byte) 255;
            stats[countIndex] = 0;
        }
    }

    public FlowTableStats(int ttl, int count) {
        this.stats[ttlIndex] = (byte) ttl;
        this.stats[ttlIndex] = (byte) count;
    }

    public int getTtl() {
        return stats[ttlIndex] & 0xFF;
    }

    public FlowTableStats setTtl(int ttl) {
        this.stats[ttlIndex] = (byte) ttl;
        return this;
    }

    public int getCounter() {
        return stats[countIndex] & 0xFF;
    }

    public FlowTableStats setCounter(int count) {
        this.stats[countIndex] = (byte) count;
        return this;
    }

    @Override
    public String toString() {
        return (stats[ttlIndex] & 0xFF) + "," + (stats[countIndex] & 0xFF) + ' ';
    }

    @Override
    public byte[] toByteArray() {
        return Arrays.copyOf(stats, SIZE);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy