package org.freertr.spf; import java.util.ArrayList; import java.util.List; import org.freertr.addr.addrIP; import org.freertr.addr.addrType; import org.freertr.tab.tabGen; import org.freertr.tab.tabRoute; /** * spf node * * @param type of nodes * @author matecsaba */ public class spfNode implements Comparable> { /** * node id */ protected Ta name; /** * stub node */ protected boolean stub; /** * identifier data */ protected String ident; /** * reachable */ protected boolean visited; /** * next hop metric */ protected int nxtMet; /** * connections */ protected List> conn = new ArrayList>(); /** * algorithms */ protected List algo = new ArrayList(); /** * best uplink */ protected spfResult uplink; /** * uplinks */ protected List> uplinks; /** * result */ protected List> result; /** * fixed metric prefixes */ protected tabRoute prfFix = new tabRoute("prf"); /** * cumulative metric prefixes */ protected tabRoute prfAdd = new tabRoute("prf"); /** * fixed metric other prefixes */ protected tabRoute othFix = new tabRoute("prf"); /** * cumulative metric other prefixes */ protected tabRoute othAdd = new tabRoute("prf"); /** * metric */ protected int metric; /** * segrou base */ protected int srBeg; /** * segrou index */ protected int srIdx; /** * bier base */ protected int brBeg; /** * bier index */ protected int brIdx; /** * bier subdomain */ protected int brSub; /** * bier nodes behind */ protected tabGen brLst = new tabGen(); /** * create new instance * * @param nam node id */ public spfNode(Ta nam) { name = nam; } public int compareTo(spfNode o) { return name.compareTo(o.name); } /** * find connection * * @param peer node id * @param met required metric * @return connection, null if not found */ protected spfConn findConn(spfNode peer, int met) { spfConn best = null; int diff = Integer.MAX_VALUE; for (int i = 0; i < conn.size(); i++) { spfConn ntry = conn.get(i); if (peer.compareTo(ntry.target) != 0) { continue; } if (met < 0) { return ntry; } if (met == ntry.metric) { return ntry; } int o = ntry.metric - met; if (o < 0) { o = -o; } if (o > diff) { continue; } best = ntry; diff = o; } return best; } public String toString() { if (ident != null) { return "" + ident; } return "" + name; } }