// Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package eu.teraflow.tid.bgp4Peer.peer;
import es.tid.bgp.bgp4.messages.BGP4Update;
import es.tid.bgp.bgp4.update.fields.ITNodeNLRI;
import es.tid.bgp.bgp4.update.fields.LinkNLRI;
import es.tid.bgp.bgp4.update.fields.NodeNLRI;
import es.tid.bgp.bgp4.update.fields.PathAttribute;
import es.tid.bgp.bgp4.update.fields.pathAttributes.*;
import es.tid.bgp.bgp4.update.tlv.LocalNodeDescriptorsTLV;
import es.tid.bgp.bgp4.update.tlv.ProtocolIDCodes;
import es.tid.bgp.bgp4.update.tlv.RemoteNodeDescriptorsTLV;
import es.tid.bgp.bgp4.update.tlv.linkstate_attribute_tlvs.*;
import es.tid.bgp.bgp4.update.tlv.node_link_prefix_descriptor_subTLVs.*;
import es.tid.ospf.ospfv2.OSPFv2LinkStateUpdatePacket;
import es.tid.ospf.ospfv2.lsa.LSA;
import es.tid.ospf.ospfv2.lsa.LSATypes;
import es.tid.ospf.ospfv2.lsa.OSPFTEv2LSA;
import es.tid.ospf.ospfv2.lsa.tlv.LinkTLV;
import es.tid.ospf.ospfv2.lsa.tlv.subtlv.*;
import es.tid.ospf.ospfv2.lsa.tlv.subtlv.complexFields.BitmapLabelSet;
import eu.teraflow.tid.bgp4Peer.bgp4session.BGP4SessionsInformation;
import eu.teraflow.tid.bgp4Peer.bgp4session.GenericBGP4Session;
import eu.teraflow.tid.tedb.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.Inet4Address;
import java.net.UnknownHostException;
import java.util.*;
/**
* Class to send periodically the topology. It sends the topology to the active BGP4 sessions.
* @author pac
*
*/
public class SendTopology implements Runnable {
/**
* 1= optical
* 0= L3
*/
private int identifier=1;
//TEDBs
private Hashtable<String,TEDB> intraTEDBs;
// Multi-domain TEDB to redistribute Multi-domain Topology
private MultiDomainTEDB multiDomainTEDB;
private boolean sendTopology;
private boolean isTest=false;
private BGP4SessionsInformation bgp4SessionsInformation;
private Logger log;
private int instanceId=1;
private boolean sendIntraDomainLinks=false;
private boolean send4AS=false;
private Inet4Address localBGPLSIdentifer;
private Inet4Address localAreaID;
public SendTopology(){
log = LoggerFactory.getLogger("BGP4Peer");
}
public void configure( Hashtable<String,TEDB> intraTEDBs,BGP4SessionsInformation bgp4SessionsInformation,boolean sendTopology,int instanceId,boolean sendIntraDomainLinks, MultiDomainTEDB multiTED){
this.intraTEDBs=intraTEDBs;
this.bgp4SessionsInformation=bgp4SessionsInformation;
this.sendTopology= sendTopology;
this.instanceId = instanceId;
this.sendIntraDomainLinks=sendIntraDomainLinks;
this.multiDomainTEDB=multiTED;
try {
this.localAreaID=(Inet4Address)Inet4Address.getByName("0.0.0.0");
this.localBGPLSIdentifer=(Inet4Address)Inet4Address.getByName("1.1.1.1");
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void configure( Hashtable<String,TEDB> intraTEDBs,BGP4SessionsInformation bgp4SessionsInformation,boolean sendTopology,int instanceId,boolean sendIntraDomainLinks, MultiDomainTEDB multiTED, boolean test){
this.intraTEDBs=intraTEDBs;
this.bgp4SessionsInformation=bgp4SessionsInformation;
this.sendTopology= sendTopology;
this.instanceId = instanceId;
this.sendIntraDomainLinks=sendIntraDomainLinks;
this.multiDomainTEDB=multiTED;
this.isTest=test;
try {
this.localAreaID=(Inet4Address)Inet4Address.getByName("0.0.0.0");
this.localBGPLSIdentifer=(Inet4Address)Inet4Address.getByName("1.1.1.1");
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* Function to send the topology database.
*/
public void run(){
try {
if (sendTopology){
if (!(bgp4SessionsInformation.getSessionList().isEmpty())){
if (multiDomainTEDB!=null){
log.debug("Sending Multi-Domain TEDB");
sendLinkNLRI( multiDomainTEDB.getInterDomainLinks());
}
else {
log.debug("Sending from TEDB");
Enumeration<TEDB> iter = intraTEDBs.elements();
while (iter.hasMoreElements()){
sendLinkNLRI( iter.nextElement().getInterDomainLinks());
}
}
if (sendIntraDomainLinks){//Intradomain Links
log.debug("sendIntraDomainLinks activated");
Enumeration<String> iter = intraTEDBs.keys();
while (iter.hasMoreElements()){
String domainID = iter.nextElement();
//Andrea
log.debug("Sending TED from domain "+domainID);
TEDB ted=intraTEDBs.get(domainID);
if (ted instanceof DomainTEDB) {
sendLinkNLRI( ((DomainTEDB)ted).getIntraDomainLinks(),domainID);
//log.info(" XXXX ted.getNodeTable():"+ted.getNodeTable());
sendNodeNLRI( ((DomainTEDB)ted).getIntraDomainLinksvertexSet(), ((DomainTEDB)ted).getNodeTable());
if (((DomainTEDB)ted).getItResources()!=null){
sendITNodeNLRI( domainID, ((DomainTEDB)ted).getItResources());
}
}
}
}
}
}
}catch (Exception e) {
e.printStackTrace();
log.error("PROBLEM SENDING TOPOLOGY: "+e.toString());
}
}
/**
* This function sends a BGP4 update message (encoded in a NodeNLRI) for each node in the set
* @param vertexIt
*/
private void sendNodeNLRI(Set<Object> vertexSet, Hashtable<Object , Node_Info> NodeTable){
Iterator<Object> vertexIt = vertexSet.iterator();
//Enviamos primero los nodos. Un Node NLRI por cada nodo.
while (vertexIt.hasNext()){
Inet4Address node=null;
Object v = vertexIt.next();
if( v instanceof eu.teraflow.tid.tedb.elements.Node){
try {
node = (Inet4Address)Inet4Address.getByName(((eu.teraflow.tid.tedb.elements.Node)v).getAddress().get(0));
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else{
node = (Inet4Address)v;
}
//log.info(" XXXX node: "+ node);
Node_Info node_info = NodeTable.get(node);
//log.info(" XXXX node_info: "+ node_info);
if (node_info!=null){
log.debug("Sending node: ("+node+")");
//Mandamos NodeNLRI
BGP4Update update = createMsgUpdateNodeNLRI(node_info);
sendMessage(update);
}else {
log.debug("Node "+node+ " HAS NO node_info in NodeTable");
}
}
}
/**
* This function sends a BGP4 update message (encoded in a ITNodeNLRI) for each node in the set
* @param vertexIt
*/
private void sendITNodeNLRI(String domainID, IT_Resources itResources){
//Andrea
log.debug("Sending IT REsources");
BGP4Update update = createMsgUpdateITNodeNLRI(domainID, itResources);
sendMessage(update);
// Iterator<Object> vertexIt = vertexSet.iterator();
// //Enviamos primero los nodos. Un Node NLRI por cada nodo.
// while (vertexIt.hasNext()){
// Inet4Address node = (Inet4Address)vertexIt.next();
// //log.info(" XXXX node: "+ node);
// Node_Info node_info = NodeTable.get(node);
// //log.info(" XXXX node_info: "+ node_info);
// if (node_info!=null){
// log.debug("Sending node: ("+node+")");
// //Mandamos NodeNLRI
// BGP4Update update = createMsgUpdateNodeNLRI(node_info);
// sendMessage(update);
// }else {
// log.error("Node "+node+ " HAS NO node_info in NodeTable");
// }
//
//
// }
}
/**
* This function sends a BGP4 update message (encoded in a LinkNLRI) for each link in the list
* @param interdomainLinks
*/
private void sendLinkNLRI(LinkedList<InterDomainEdge> interdomainLinks){
if (true){
int lanID = 1; ///INVENTADOO
ArrayList<Inet4Address> addressList = new ArrayList<Inet4Address>();
Iterator<InterDomainEdge> edgeIt = interdomainLinks.iterator();
while (edgeIt.hasNext()){
InterDomainEdge edge = edgeIt.next();
Inet4Address source = (Inet4Address)edge.getSrc_router_id();
Inet4Address dst = (Inet4Address)edge.getDst_router_id();
log.debug("Sending ID edge: ("+source.toString() +":"+((InterDomainEdge) edge).getSrc_if_id()+","+dst.toString()+")");
addressList = new ArrayList<Inet4Address>();
addressList.add(0,source);
addressList.add(1,dst);
//Link Local Remote Identifiers
ArrayList<Long> localRemoteIfList =null;
localRemoteIfList= new ArrayList<Long> ();
localRemoteIfList.add(0,((InterDomainEdge) edge).getSrc_if_id());//te_info.getLinkLocalRemoteIdentifiers().getLinkLocalIdentifier());
localRemoteIfList.add(1,((InterDomainEdge) edge).getDst_if_id());//te_info.getLinkLocalRemoteIdentifiers().getLinkRemoteIdentifier());
ArrayList<String> domainList = new ArrayList<String>(2);
//FIXME: chequear
TE_Information te_info = ((InterDomainEdge) edge).getTE_info();
domainList.add(((Inet4Address)edge.getDomain_src_router()).getHostAddress().toString());
//System.out.println("SRC Domain is "+((Inet4Address)edge.getDomain_src_router()).getHostAddress().toString() );
domainList.add( ((Inet4Address)edge.getDomain_dst_router()).getHostAddress().toString());
log.debug("SRC Domain is "+(Inet4Address)edge.getDomain_dst_router());
BGP4Update update = createMsgUpdateLinkNLRI(addressList,localRemoteIfList, lanID, domainList, false, te_info);
update.setLearntFrom(edge.getLearntFrom());
log.debug("Update message Created");
sendMessage(update);
}
}
}
/**
* This function sends a BGP4 update message (encoded in a LinkNLRI) for each link in the set
* @param edgeIt
*/
private void sendLinkNLRI(Set<IntraDomainEdge> edgeSet, String domainID){
int lanID = 1; ///INVENTADOO
ArrayList<Inet4Address> addressList = new ArrayList<Inet4Address>();
Iterator<IntraDomainEdge> edgeIt = edgeSet.iterator();
while (edgeIt.hasNext()){
IntraDomainEdge edge = edgeIt.next();
Inet4Address source=null;
if(edge.getSource() instanceof eu.teraflow.tid.tedb.elements.Node){
try {
source=(Inet4Address)Inet4Address.getByName(((eu.teraflow.tid.tedb.elements.Node)edge.getSource()).getAddress().get(0));
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else{
source = (Inet4Address)edge.getSource();
}
Inet4Address dst=null;
if(edge.getTarget() instanceof eu.teraflow.tid.tedb.elements.Node){
try {
dst=(Inet4Address)Inet4Address.getByName(((eu.teraflow.tid.tedb.elements.Node)edge.getTarget()).getAddress().get(0));
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else{
dst = (Inet4Address)edge.getTarget();
}
log.debug("Sending: ("+source.toString() +","+dst.toString()+")");
addressList = new ArrayList<Inet4Address>();
addressList.add(0,source);
addressList.add(1,dst);
//Link Local Remote Identifiers
ArrayList<Long> localRemoteIfList =null;
localRemoteIfList= new ArrayList<Long> ();
localRemoteIfList.add(0,((IntraDomainEdge) edge).getSrc_if_id());//te_info.getLinkLocalRemoteIdentifiers().getLinkLocalIdentifier());
localRemoteIfList.add(1,((IntraDomainEdge) edge).getDst_if_id());//te_info.getLinkLocalRemoteIdentifiers().getLinkRemoteIdentifier());
//MPLS
float maximumBandwidth = 0;
float[] unreservedBandwidth = null;
float maximumReservableBandwidth = 0;
int undirLinkDelay = 0;
int metric = 0;
long te_metric =0;
//GMPLS
AvailableLabels availableLabels = null;
MF_OTPAttribTLV mfOTP = null;
TE_Information te_info = ((IntraDomainEdge) edge).getTE_info();
ArrayList<String> domainList = new ArrayList<String>(2);
domainList.add(domainID);
domainList.add(domainID);
BGP4Update update = createMsgUpdateLinkNLRI(addressList,localRemoteIfList, lanID, domainList, true, te_info);
update.setLearntFrom(edge.getLearntFrom());
sendMessage(update);
}
}
/**
* Function to send a BGP4 update message to the connected peers.
* @param update
*/
private void sendMessage (BGP4Update update){
Enumeration <GenericBGP4Session > sessions = bgp4SessionsInformation.getSessionList().elements();
log.debug("Sending a BGP4 update message:"+update.toString());
while (sessions.hasMoreElements()){
GenericBGP4Session session = sessions.nextElement();
if (session==null) {
log.error("SESSION NULL");
}else {
if (session.getSendTo()) {
String destination = session.getRemotePeerIP().getHostAddress();
log.debug("BGP4 Update learnt from:" + update.getLearntFrom());
if (isTest){
log.debug("Sending BGP4 update to:" + destination+" with no check on the ID since it is test");
session.sendBGP4Message(update);
}
else{
try {
if ((update.getLearntFrom() != null) && (update.getLearntFrom().contains("/"))) {
//log.info(update.getLearntFrom().substring(1));
if (!destination.equals(update.getLearntFrom().substring(1))) {
//log.info("id da getLearnt "+ update.getLearntFrom());
log.debug("Sending update to destination " + destination + " for info learnt from " + update.getLearntFrom().substring(1));
log.debug("Sending BGP4 update to:" + destination);
session.sendBGP4Message(update);
} else
log.debug("destination " + destination + " and source of information " + update.getLearntFrom().substring(1) + " are equal");
}
else{
if (!destination.equals(update.getLearntFrom())) {
//log.info("id da getLearnt "+ update.getLearntFrom());
log.debug("Sending update to destination " + destination + " for info learnt from " + update.getLearntFrom());
log.debug("Sending BGP4 update to:" + destination);
session.sendBGP4Message(update);
} else
log.debug("destination " + destination + " and source of information " + update.getLearntFrom() + " are equal");
}
}
catch (Exception e){
e.printStackTrace();
}
}
}
}
}
}
/**
* This function create a BGP4 Message with NodeNLRI field
* @param node_info
*/
private BGP4Update createMsgUpdateNodeNLRI(Node_Info node_info){
try{
BGP4Update update= new BGP4Update();
//Path Attributes
ArrayList<PathAttribute> pathAttributes = update.getPathAttributes();
//Origin
OriginAttribute or = new OriginAttribute();
or.setValue(PathAttributesTypeCode.PATH_ATTRIBUTE_ORIGIN_IGP);
pathAttributes.add(or);
//AS_PATH
if (send4AS==true) {
AS_Path_Attribute as_path = new AS_Path_Attribute();
AS_Path_Segment as_path_seg = new AS_Path_Segment();
long[] segs = new long[1];
segs[0] = 65522;
as_path_seg.set4Segments(segs);
as_path.getAsPathSegments().add(as_path_seg);
pathAttributes.add(as_path);
}
else {
AS_Path_Attribute as_path = new AS_Path_Attribute();
AS_Path_Segment as_path_seg = new AS_Path_Segment();
int[] segs = new int[1];
segs[0] = 65522;
as_path_seg.setSegments(segs);
as_path.getAsPathSegments().add(as_path_seg);
pathAttributes.add(as_path);
}
//Node Attribute
LinkStateAttribute linkStateAttribute = new LinkStateAttribute();
boolean linkStateNeeded=false;
if (node_info.getSid()!=0){
int sid = node_info.getSid();
SidLabelNodeAttribTLV sidLabelTLV = new SidLabelNodeAttribTLV();
sidLabelTLV.setSid(sid);
linkStateAttribute.setSidLabelTLV(sidLabelTLV);
linkStateNeeded=true;
}
if (linkStateNeeded){
log.debug("Node Attribute added....");
pathAttributes.add(linkStateAttribute);
}
//NLRI
NodeNLRI nodeNLRI = new NodeNLRI();
nodeNLRI.setProtocolID(ProtocolIDCodes.Unknown_Protocol_ID);
nodeNLRI.setRoutingUniverseIdentifier(identifier);
LocalNodeDescriptorsTLV localNodeDescriptors = new LocalNodeDescriptorsTLV();
//igp router id
if(node_info.getIpv4Address()!=null){
IGPRouterIDNodeDescriptorSubTLV igpRouterIDLNSubTLV = new IGPRouterIDNodeDescriptorSubTLV();
igpRouterIDLNSubTLV.setIpv4AddressOSPF(node_info.getIpv4Address());
igpRouterIDLNSubTLV.setIGP_router_id_type(IGPRouterIDNodeDescriptorSubTLV.IGP_ROUTER_ID_TYPE_OSPF_NON_PSEUDO);
localNodeDescriptors.setIGPRouterID(igpRouterIDLNSubTLV);
}
//as number
if(node_info.getAs_number()!=null){
AutonomousSystemNodeDescriptorSubTLV asNodeDescrSubTLV = new AutonomousSystemNodeDescriptorSubTLV();
asNodeDescrSubTLV.setAS_ID(node_info.getAs_number());
localNodeDescriptors.setAutonomousSystemSubTLV(asNodeDescrSubTLV);
}
//Complete Dummy TLVs
BGPLSIdentifierNodeDescriptorSubTLV bGPLSIDSubTLV =new BGPLSIdentifierNodeDescriptorSubTLV();
bGPLSIDSubTLV.setBGPLS_ID(this.localBGPLSIdentifer);
localNodeDescriptors.setBGPLSIDSubTLV(bGPLSIDSubTLV);
AreaIDNodeDescriptorSubTLV areaID = new AreaIDNodeDescriptorSubTLV();
areaID.setAREA_ID(this.localAreaID);
localNodeDescriptors.setAreaID(areaID);
nodeNLRI.setLocalNodeDescriptors(localNodeDescriptors);
BGP_LS_MP_Reach_Attribute ra= new BGP_LS_MP_Reach_Attribute();
ra.setLsNLRI(nodeNLRI);
pathAttributes.add(ra);
update.setLearntFrom(node_info.getLearntFrom());
return update;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* This function create a BGP4 Message with NodeNLRI field
* @param addressList
* @param node_info
*/
private BGP4Update createMsgUpdateITNodeNLRI(String domainID, IT_Resources itResources){
try{
BGP4Update update= new BGP4Update();
//Path Attributes
ArrayList<PathAttribute> pathAttributes = update.getPathAttributes();
//Origin
OriginAttribute or = new OriginAttribute();
or.setValue(PathAttributesTypeCode.PATH_ATTRIBUTE_ORIGIN_IGP);
pathAttributes.add(or);
//AS_PATH
if (send4AS==true) {
AS_Path_Attribute as_path = new AS_Path_Attribute();
AS_Path_Segment as_path_seg = new AS_Path_Segment();
long[] segs = new long[1];
segs[0] = 65522;
as_path_seg.set4Segments(segs);
as_path.getAsPathSegments().add(as_path_seg);
pathAttributes.add(as_path);
}
else {
AS_Path_Attribute as_path = new AS_Path_Attribute();
AS_Path_Segment as_path_seg = new AS_Path_Segment();
int[] segs = new int[1];
segs[0] = 65522;
as_path_seg.setSegments(segs);
as_path.getAsPathSegments().add(as_path_seg);
pathAttributes.add(as_path);
}
//NLRI
ITNodeNLRI itNodeNLRI = new ITNodeNLRI();
itNodeNLRI.setNodeId(domainID);
itNodeNLRI.setControllerIT(itResources.getControllerIT());
itNodeNLRI.setCpu(itResources.getCpu());
itNodeNLRI.setMem(itResources.getMem());
itNodeNLRI.setStorage(itResources.getStorage());
update.setLearntFrom(itResources.getLearntFrom());
log.info("Creating IT Update related to domain "+domainID+" learnt from "+itResources.getLearntFrom());
LocalNodeDescriptorsTLV localNodeDescriptors = new LocalNodeDescriptorsTLV();
//Complete Dummy TLVs
BGPLSIdentifierNodeDescriptorSubTLV bGPLSIDSubTLV =new BGPLSIdentifierNodeDescriptorSubTLV();
bGPLSIDSubTLV.setBGPLS_ID(this.localBGPLSIdentifer);
localNodeDescriptors.setBGPLSIDSubTLV(bGPLSIDSubTLV);
AreaIDNodeDescriptorSubTLV areaID = new AreaIDNodeDescriptorSubTLV();
areaID.setAREA_ID(this.localAreaID);
localNodeDescriptors.setAreaID(areaID);
//itNodeNLRI.setLocalNodeDescriptors(localNodeDescriptors);
BGP_LS_MP_Reach_Attribute ra= new BGP_LS_MP_Reach_Attribute();
ra.setLsNLRI(itNodeNLRI);
pathAttributes.add(ra);
return update;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* Function to create a BGP4 update message with a link NRLI field. To send the links.
*
* @param addressList
* @param addressInterfaceList
* @param localRemoteIfList
* @param lanID
* @param maximumBandwidth
* @param unreservedBandwidth
* @param maximumReservableBandwidth
* @param availableLabels
* @param metric
* @param domainList
* @param intradomain
* @param linkDelay
*/
private BGP4Update createMsgUpdateLinkNLRI(ArrayList<Inet4Address> addressList,ArrayList<Long> localRemoteIfList,int lanID, ArrayList<String> domainList, boolean intradomain, TE_Information te_info ){
BGP4Update update= new BGP4Update();
//1. Path Attributes
ArrayList<PathAttribute> pathAttributes = update.getPathAttributes();
//1.1. Origin
OriginAttribute or = new OriginAttribute();
if (intradomain)
or.setValue(PathAttributesTypeCode.PATH_ATTRIBUTE_ORIGIN_IGP);
else
or.setValue(PathAttributesTypeCode.PATH_ATTRIBUTE_ORIGIN_EGP);
pathAttributes.add(or);
///Andreaaaaa
//update.setLearntFrom("192.168.0.1");
//1.2. AS-PATH
if (send4AS==true) {
AS_Path_Attribute as_path = new AS_Path_Attribute();
AS_Path_Segment as_path_seg = new AS_Path_Segment();
long[] segs = new long[1];
segs[0] = 65522;
as_path_seg.set4Segments(segs);
as_path.getAsPathSegments().add(as_path_seg);
pathAttributes.add(as_path);
}
else {
AS_Path_Attribute as_path = new AS_Path_Attribute();
AS_Path_Segment as_path_seg = new AS_Path_Segment();
int[] segs = new int[1];
segs[0] = 65522;
as_path_seg.setSegments(segs);
as_path.getAsPathSegments().add(as_path_seg);
pathAttributes.add(as_path);
}
//1.2. LINK-STATE
//MPLS
float maximumBandwidth = 0;
float[] unreservedBandwidth = null;
float maximumReservableBandwidth = 0;
//GMPLS
AvailableLabels availableLabels = null;
MF_OTPAttribTLV mfOTP = null;
int metric = 0;
int te_metric = 0;
if (te_info != null){
if (te_info.getLinkLocalRemoteIdentifiers() != null){
}
//MPLS
if (te_info.getMaximumBandwidth() != null) {
maximumBandwidth = te_info.getMaximumBandwidth().getMaximumBandwidth();
}
if (te_info.getUnreservedBandwidth() != null)
unreservedBandwidth = te_info.getUnreservedBandwidth().getUnreservedBandwidth();
if (te_info.getMaximumReservableBandwidth() != null)
maximumReservableBandwidth = te_info.getMaximumReservableBandwidth().getMaximumReservableBandwidth();
//GMPLS
if (te_info.getAvailableLabels() != null)
availableLabels = te_info.getAvailableLabels();
if(te_info.getDefaultTEMetric()!=null){
metric = (int) te_info.getDefaultTEMetric().getLinkMetric();
log.debug("Metric en el metodo sendLinkNLRI es: " + metric);
}
if(te_info.getTrafficEngineeringMetric()!=null){
te_metric = (int) te_info.getTrafficEngineeringMetric().getLinkMetric() ;
log.debug("Metric en el metodo sendLinkNLRI es: " + metric);
}
if(te_info.getMfOTF()!=null){
mfOTP = te_info.getMfOTF();
}
}else{
log.debug("TE_Info es null");
}
boolean linkStateNeeded = false;
LinkStateAttribute linkStateAttribute = new LinkStateAttribute();
//1.2.1. MaxReservableBandwidth
if (maximumReservableBandwidth != 0){
MaxReservableBandwidthLinkAttribTLV maxReservableBandwidthTLV = new MaxReservableBandwidthLinkAttribTLV();
maxReservableBandwidthTLV.setMaximumReservableBandwidth(maximumReservableBandwidth);
linkStateAttribute.setMaxReservableBandwidthTLV(maxReservableBandwidthTLV);
linkStateNeeded=true;
}
//1.2.2. maxBandwidth
if (maximumBandwidth != 0){
MaximumLinkBandwidthLinkAttribTLV maximumLinkBandwidthTLV = new MaximumLinkBandwidthLinkAttribTLV();
maximumLinkBandwidthTLV.setMaximumBandwidth(maximumBandwidth);
linkStateAttribute.setMaximumLinkBandwidthTLV(maximumLinkBandwidthTLV);
linkStateNeeded=true;
}
//1.2.3. unreservedBandwidth
if (unreservedBandwidth != null){
UnreservedBandwidthLinkAttribTLV unreservedBandwidthTLV = new UnreservedBandwidthLinkAttribTLV();
unreservedBandwidthTLV.setUnreservedBandwidth(unreservedBandwidth);
linkStateAttribute.setUnreservedBandwidthTLV(unreservedBandwidthTLV);
linkStateNeeded=true;
}
//1.2.4. AvailableLabels
if (availableLabels != null){
log.debug("Available labels fields: "+availableLabels.getLabelSet().getNumLabels());
AvailableLabels al = new AvailableLabels();
BitmapLabelSet bl = new BitmapLabelSet();
bl.setBytesBitmap(((BitmapLabelSet)availableLabels.getLabelSet()).getBytesBitMap());
bl.setNumLabels(availableLabels.getLabelSet().getNumLabels());
bl.setDwdmWavelengthLabel(((BitmapLabelSet)availableLabels.getLabelSet()).getDwdmWavelengthLabel());
bl.setBytesBitmapReserved(((BitmapLabelSet)availableLabels.getLabelSet()).getBytesBitmapReserved());
al.setLabelSet(bl);
log.debug("Campo BytesBitmap: "+Integer.toHexString(((int)bl.getBytesBitMap()[0])&0xFF));
log.debug("Campo DwdmWavelengthLabel: "+bl.getDwdmWavelengthLabel());
if (bl.getBytesBitmapReserved()!=null){
log.debug("Campo BytesBitmapReserved: "+bl.getBytesBitmapReserved()[0]);
}
linkStateAttribute.setAvailableLabels(al);
linkStateNeeded=true;
}
//1.2.5 metric
// if (metric != 0){
// DefaultTEMetricLinkAttribTLV defaultMetric = new DefaultTEMetricLinkAttribTLV();
// defaultMetric.setLinkMetric(metric);
// log.info("Metric en el metodo createMsgUpdateLinkNLRI es: " + metric);
// linkStateAttribute.setTEMetricTLV(defaultMetric);
// linkStateNeeded=true;
// }
if (te_metric != 0){
DefaultTEMetricLinkAttribTLV defaultMetric = new DefaultTEMetricLinkAttribTLV();
//defaultMetric.setLinkMetric(metric);
defaultMetric.setLinkMetric(te_metric);
log.debug("Metric en el metodo createMsgUpdateLinkNLRI es: " + te_metric);
linkStateAttribute.setTEMetricTLV(defaultMetric);
linkStateNeeded=true;
}
//1.2.6 MF_OPT
if (mfOTP != null){
MF_OTPAttribTLV mfOTPTLV = mfOTP.duplicate();
log.debug("SENDING MFOTP OSCAR");
linkStateAttribute.setMF_OTP_ATLV(mfOTPTLV);
linkStateNeeded=true;
}
if (linkStateNeeded){
pathAttributes.add(linkStateAttribute);
}
//2. NLRI
LinkNLRI linkNLRI = new LinkNLRI();
linkNLRI.setProtocolID(ProtocolIDCodes.Unknown_Protocol_ID);
linkNLRI.setIdentifier(instanceId);
//2.1. Local Y Remote Descriptors
LocalNodeDescriptorsTLV localNodeDescriptors = new LocalNodeDescriptorsTLV();
RemoteNodeDescriptorsTLV remoteNodeDescriptors = new RemoteNodeDescriptorsTLV();
//2.1.1. IPv4
IGPRouterIDNodeDescriptorSubTLV igpRouterIDLNSubTLV = new IGPRouterIDNodeDescriptorSubTLV();
igpRouterIDLNSubTLV.setIpv4AddressOSPF(addressList.get(0));
igpRouterIDLNSubTLV.setIGP_router_id_type(IGPRouterIDNodeDescriptorSubTLV.IGP_ROUTER_ID_TYPE_OSPF_NON_PSEUDO);
localNodeDescriptors.setIGPRouterID(igpRouterIDLNSubTLV);
//Complete Dummy TLVs
BGPLSIdentifierNodeDescriptorSubTLV bGPLSIDSubTLV =new BGPLSIdentifierNodeDescriptorSubTLV();
bGPLSIDSubTLV.setBGPLS_ID(this.localBGPLSIdentifer);
localNodeDescriptors.setBGPLSIDSubTLV(bGPLSIDSubTLV);
AreaIDNodeDescriptorSubTLV areaID = new AreaIDNodeDescriptorSubTLV();
areaID.setAREA_ID(this.localAreaID);
localNodeDescriptors.setAreaID(areaID);
IGPRouterIDNodeDescriptorSubTLV igpRouterIDDNSubTLV = new IGPRouterIDNodeDescriptorSubTLV();
igpRouterIDDNSubTLV.setIpv4AddressOSPF(addressList.get(1));
igpRouterIDDNSubTLV.setIGP_router_id_type(IGPRouterIDNodeDescriptorSubTLV.IGP_ROUTER_ID_TYPE_OSPF_NON_PSEUDO);
remoteNodeDescriptors.setIGPRouterID(igpRouterIDDNSubTLV);
//2.1.2. AS
if (domainList != null){
AutonomousSystemNodeDescriptorSubTLV as_local = new AutonomousSystemNodeDescriptorSubTLV();
try {
as_local.setAS_ID((Inet4Address) Inet4Address.getByName(domainList.get(0)));
localNodeDescriptors.setAutonomousSystemSubTLV(as_local);
AutonomousSystemNodeDescriptorSubTLV as_remote = new AutonomousSystemNodeDescriptorSubTLV();
as_remote.setAS_ID((Inet4Address) Inet4Address.getByName(domainList.get(1)));
remoteNodeDescriptors.setAutonomousSystemSubTLV(as_remote);
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//Complete Dummy TLVs
remoteNodeDescriptors.setBGPLSIDSubTLV(bGPLSIDSubTLV);
remoteNodeDescriptors.setAreaID(areaID);
linkNLRI.setLocalNodeDescriptors(localNodeDescriptors);
linkNLRI.setRemoteNodeDescriptorsTLV(remoteNodeDescriptors);
//2.2. Link NLRI TLVs
//2.2.1. Ipv4 interface and neighbour address
IPv4InterfaceAddressLinkDescriptorsSubTLV ipv4InterfaceAddressTLV = new IPv4InterfaceAddressLinkDescriptorsSubTLV();
IPv4NeighborAddressLinkDescriptorSubTLV ipv4NeighborAddressTLV = new IPv4NeighborAddressLinkDescriptorSubTLV();
ipv4InterfaceAddressTLV.setIpv4Address(addressList.get(0));
ipv4NeighborAddressTLV.setIpv4Address(addressList.get(1));
linkNLRI.setIpv4InterfaceAddressTLV(ipv4InterfaceAddressTLV);
linkNLRI.setIpv4NeighborAddressTLV(ipv4NeighborAddressTLV);
//2.2.2. Link Local/Remote identifiers TLV
if (localRemoteIfList != null){
LinkLocalRemoteIdentifiersLinkDescriptorSubTLV linkIdentifiersTLV = new LinkLocalRemoteIdentifiersLinkDescriptorSubTLV();
linkIdentifiersTLV.setLinkLocalIdentifier(localRemoteIfList.get(0));
linkIdentifiersTLV.setLinkRemoteIdentifier(localRemoteIfList.get(1));
linkNLRI.setLinkIdentifiersTLV(linkIdentifiersTLV);
}
//2.2.3 LinkDelay
if (te_info != null){
if(te_info.getUndirLinkDelay() != null){
int undirLinkDelay = te_info.getUndirLinkDelay().getDelay();
UndirectionalLinkDelayDescriptorSubTLV uSTLV =new UndirectionalLinkDelayDescriptorSubTLV();
uSTLV.setDelay(undirLinkDelay);
linkNLRI.setUndirectionalLinkDelayTLV(uSTLV);
}
if(te_info.getUndirDelayVar() != null){
int undirDelayVar = te_info.getUndirDelayVar().getDelayVar();
UndirectionalDelayVariationDescriptorSubTLV uSTLV =new UndirectionalDelayVariationDescriptorSubTLV();
uSTLV.setDelayVar(undirDelayVar);
linkNLRI.setUndirectionalDelayVariationTLV(uSTLV);
}
if(te_info.getMinMaxUndirLinkDelay() != null){
int minDelay = te_info.getMinMaxUndirLinkDelay().getLowDelay();
int maxDelay = te_info.getMinMaxUndirLinkDelay().getHighDelay();
MinMaxUndirectionalLinkDelayDescriptorSubTLV uSTLV =new MinMaxUndirectionalLinkDelayDescriptorSubTLV();
uSTLV.setHighDelay(maxDelay);
uSTLV.setLowDelay(minDelay);
linkNLRI.setMinMaxUndirectionalLinkDelayTLV(uSTLV);
}
if(te_info.getUndirLinkLoss() != null){
int linkLoss = te_info.getUndirLinkLoss().getLinkLoss();
UndirectionalLinkLossDescriptorSubTLV uSTLV =new UndirectionalLinkLossDescriptorSubTLV();
uSTLV.setLinkLoss(linkLoss);
linkNLRI.setUndirectionalLinkLossTLV(uSTLV);
}
if(te_info.getUndirResidualBw() != null){
int resBw = te_info.getUndirResidualBw().getResidualBw();
UndirectionalResidualBandwidthDescriptorSubTLV uSTLV =new UndirectionalResidualBandwidthDescriptorSubTLV();
uSTLV.setResidualBw(resBw);
linkNLRI.setUndirectionalResidualBwTLV(uSTLV);
}
if(te_info.getUndirAvailableBw() != null){
int availableBw = te_info.getUndirAvailableBw().getAvailableBw();
UndirectionalAvailableBandwidthDescriptorSubTLV uSTLV =new UndirectionalAvailableBandwidthDescriptorSubTLV();
uSTLV.setAvailableBw(availableBw);
linkNLRI.setUndirectionalAvailableBwTLV(uSTLV);
}
if(te_info.getUndirUtilizedBw() != null){
int utilizedBw = te_info.getUndirUtilizedBw().getUtilizedBw();
UndirectionalUtilizedBandwidthDescriptorSubTLV uSTLV =new UndirectionalUtilizedBandwidthDescriptorSubTLV();
uSTLV.setUtilizedBw(utilizedBw);
linkNLRI.setUndirectionalUtilizedBwTLV(uSTLV);
}
}
linkNLRI.setIdentifier(this.identifier);
BGP_LS_MP_Reach_Attribute ra= new BGP_LS_MP_Reach_Attribute();
ra.setLsNLRI(linkNLRI);
pathAttributes.add(ra);
return update;
}
/**
* Funcion que crea un mensaje OSPF inventado desde cero.
* Solo se meten en el mensaje los campos:
* - source
* - destino
* - maximun bandwithd
* @return OSPFv2 Link State Update Packet
*/
public static OSPFv2LinkStateUpdatePacket createMsgOSPF(){
Inet4Address src = null;
Inet4Address dst = null;
MaximumBandwidth maximumBandwidth = new MaximumBandwidth();
maximumBandwidth.setMaximumBandwidth(100);
UnreservedBandwidth unreservedBandwidth = new UnreservedBandwidth();
float[] unReservedB = new float[8];
unReservedB[0]=18309;
unReservedB[1]=130;
unreservedBandwidth.setUnreservedBandwidth(unReservedB);
try {
src = (Inet4Address) Inet4Address.getByName( "179.123.123.123");
dst = (Inet4Address) Inet4Address.getByName( "179.123.123.111");
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
OSPFv2LinkStateUpdatePacket ospfv2Packet = new OSPFv2LinkStateUpdatePacket();
ospfv2Packet.setRouterID(src);
LinkedList<LSA> lsaList = new LinkedList<LSA>();
OSPFTEv2LSA lsa = new OSPFTEv2LSA();
LinkTLV linkTLV=new LinkTLV();
lsa.setLinkTLV(linkTLV);
linkTLV.setMaximumBandwidth(maximumBandwidth);
linkTLV.setUnreservedBandwidth(unreservedBandwidth);
LocalInterfaceIPAddress localInterfaceIPAddress= new LocalInterfaceIPAddress();
LinkedList<Inet4Address> lista =localInterfaceIPAddress.getLocalInterfaceIPAddressList();
lista.add(src);
linkTLV.setLocalInterfaceIPAddress(localInterfaceIPAddress);
RemoteInterfaceIPAddress remoteInterfaceIPAddress= new RemoteInterfaceIPAddress();
LinkedList<Inet4Address> listar = remoteInterfaceIPAddress.getRemoteInterfaceIPAddressList();
listar.add(dst);
linkTLV.setRemoteInterfaceIPAddress(remoteInterfaceIPAddress);
LinkID linkID = new LinkID();
linkID.setLinkID(dst);
linkTLV.setLinkID(linkID);
// if (edge.getTE_info().getAvailableLabels() != null){
// linkTLV.setAvailableLabels(edge.getTE_info().getAvailableLabels());
// }
lsaList.add(lsa);
ospfv2Packet.setLSAlist(lsaList);
return ospfv2Packet;
}
//* Funcion que decodifica un mensaje OSPFv2LinkStateUpdatePacket creando con los campos extraidos un mensaje BGP4 update.
public BGP4Update decodificarMsgOSPF(OSPFv2LinkStateUpdatePacket ospfv2Packet){
boolean intradomain = true;
Inet4Address localIPAddress = ospfv2Packet.getRouterID();
Inet4Address remoteIPAddress = null;
long localInterfaceIPAddress = -1;
long remoteInterfaceIPAddress = -1;
Inet4Address remoteASNumber = null;
LinkedList<LSA> lsaList;
OSPFTEv2LSA lsa;
//GMPLS Parameter
AvailableLabels al = null;
//MPLS Parameter
float maxBandwidth = 0;
float[] unBandwidth = null;
float maximumReservableBandwidth=0;
lsaList = ((OSPFv2LinkStateUpdatePacket)ospfv2Packet).getLSAlist();
for (int i =0;i< lsaList.size();i++){
if (lsaList.get(i).getLStype() == LSATypes.TYPE_10_OPAQUE_LSA){
lsa=(OSPFTEv2LSA)lsaList.get(i);
log.debug("Starting to process LSA");
LinkTLV linkTLV = lsa.getLinkTLV();
if (linkTLV!=null){
//Local and Remote interface IP address
remoteIPAddress = linkTLV.getLinkID().getLinkID();
log.debug("Remote IP Address: "+remoteIPAddress);
localInterfaceIPAddress = linkTLV.getLinkLocalRemoteIdentifiers().getLinkLocalIdentifier();
log.debug("Local Interface: "+localInterfaceIPAddress);
remoteInterfaceIPAddress =linkTLV.getLinkLocalRemoteIdentifiers().getLinkRemoteIdentifier();
log.debug("Remote Interface: "+remoteInterfaceIPAddress);
//MPLS fields
if (linkTLV.getMaximumBandwidth() != null)
maxBandwidth = linkTLV.getMaximumBandwidth().getMaximumBandwidth();
if (linkTLV.getUnreservedBandwidth() != null)
unBandwidth = linkTLV.getUnreservedBandwidth().getUnreservedBandwidth();
if (linkTLV.getMaximumReservableBandwidth()!= null)
maximumReservableBandwidth = linkTLV.getMaximumReservableBandwidth().getMaximumReservableBandwidth();
//GMPLS
al = linkTLV.getAvailableLabels();
//FIXME: Como ver si es inter o intra domain
if (linkTLV.getRemoteASNumber() != null)
remoteASNumber = linkTLV.getRemoteASNumber().getRemoteASNumber();
}
}
}
//Create the address list
ArrayList<Inet4Address> addressList = new ArrayList<Inet4Address>();
addressList.add(localIPAddress);
addressList.add(remoteIPAddress);
//Create the interface list
ArrayList<Long> localRemoteIfList = new ArrayList<Long>();
localRemoteIfList.add(localInterfaceIPAddress);
localRemoteIfList.add(remoteInterfaceIPAddress);
//Create the domain List
ArrayList<Inet4Address> domainList = new ArrayList<Inet4Address>(2);
//FIXME CHECK IF THIS METHOD IS USED
//return createMsgUpdateLinkNLRI(addressList,localRemoteIfList,23,maxBandwidth,unBandwidth,maximumReservableBandwidth,al, 0,0, domainList, intradomain, null);
return null;
}
public boolean isSendTopology() {
return sendTopology;
}
public void setSendTopology(boolean sendTopology) {
this.sendTopology = sendTopology;
}
public void setisTest(boolean test) {
this.isTest = test;
}
public boolean getisTest() {
return this.isTest;
}
public BGP4SessionsInformation getBgp4SessionsInformation() {
return bgp4SessionsInformation;
}
public void setBgp4SessionsInformation(
BGP4SessionsInformation bgp4SessionsInformation) {
this.bgp4SessionsInformation = bgp4SessionsInformation;
}
public void setInstanceId(int instanceId) {
this.instanceId = instanceId;
}
}
// Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package eu.teraflow.tid.bgp4Peer.tedb;
import java.util.LinkedList;
import eu.teraflow.tid.tedb.InterDomainEdge;
import eu.teraflow.tid.tedb.TEDB;
public class BGP4DomainTEDB implements TEDB {
@Override
public void initializeFromFile(String file) {
// TODO Auto-generated method stub
}
@Override
public void initializeFromFile(String file, String learnFrom) {
}
@Override
public boolean isITtedb() {
// TODO Auto-generated method stub
return false;
}
@Override
public String printTopology() {
// TODO Auto-generated method stub
return null;
}
@Override
public LinkedList<InterDomainEdge> getInterDomainLinks() {
// TODO Auto-generated method stub
return null;
}
}
// Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package eu.teraflow.tid.bgp4Peer.tedb;
import java.net.Inet4Address;
import java.util.Hashtable;
import java.util.LinkedList;
import eu.teraflow.tid.tedb.InterDomainEdge;
public class BGP4IntradomainTEDB implements IntraTEDBS {
Hashtable<Inet4Address,BGP4DomainTEDB> tedb;
@Override
public void initializeFromFile(String file) {
// TODO Auto-generated method stub
}
@Override
public void initializeFromFile(String file, String learnFrom) {
}
@Override
public boolean isITtedb() {
// TODO Auto-generated method stub
return false;
}
@Override
public String printTopology() {
// TODO Auto-generated method stub
return null;
}
@Override
public LinkedList<InterDomainEdge> getInterDomainLinks() {
// TODO Auto-generated method stub
return null;
}
@Override
public void addIntradomainEdge() {
// TODO Auto-generated method stub
}
@Override
public void addIntradomainNode(Inet4Address domain, Inet4Address node) {
BGP4DomainTEDB bgp4TEDB = tedb.get(domain);
}
}
// Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package eu.teraflow.tid.bgp4Peer.tedb;
import java.net.Inet4Address;
import eu.teraflow.tid.tedb.TEDB;
public interface IntraTEDBS extends TEDB {
//Metodo (annadir enlace intradominio) que le pases un domain id, + cosas que necesites para el intradomain edge.
//Las clases que implemente para esta interface ya tengra que ver c�mo hacerlo. Tener una hashtable.
public void addIntradomainEdge();
public void addIntradomainNode(Inet4Address domain, Inet4Address node);
}
// Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package eu.teraflow.tid.bgp4Peer.updateTEDB;
import java.net.Inet4Address;
import java.util.Hashtable;
import java.util.concurrent.LinkedBlockingQueue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import es.tid.bgp.bgp4.messages.BGP4Update;
import eu.teraflow.tid.bgp4Peer.tedb.IntraTEDBS;
import eu.teraflow.tid.tedb.DomainTEDB;
import eu.teraflow.tid.tedb.MultiDomainTEDB;
import eu.teraflow.tid.tedb.SimpleTEDB;
import eu.teraflow.tid.tedb.TEDB;
/**
* This class is in charge of storing the BGP4 update messages in a queue to be processing
*
* @author pac
*
*/
public class UpdateDispatcher {
private Logger log;
private LinkedBlockingQueue<BGP4Update> updateList;
private UpdateProccesorThread upt;
public UpdateDispatcher(MultiDomainTEDB multiTedb,Hashtable<String,TEDB> intraTEDBs ){
this.updateList=new LinkedBlockingQueue<BGP4Update>();
this.upt=new UpdateProccesorThread(updateList, multiTedb,intraTEDBs );
upt.start();
log=LoggerFactory.getLogger("BGP4Server");
}
public void dispatchRequests(BGP4Update updateMessage){
updateList.add(updateMessage);
}
}
// Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package eu.teraflow.tid.bgp4Peer.updateTEDB;
import java.net.Inet4Address;
import java.util.ArrayList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import es.tid.bgp.bgp4.update.fields.LinkNLRI;
import es.tid.bgp.bgp4.update.tlv.linkstate_attribute_tlvs.MaxReservableBandwidthLinkAttribTLV;
import es.tid.bgp.bgp4.update.tlv.linkstate_attribute_tlvs.MaximumLinkBandwidthLinkAttribTLV;
import es.tid.bgp.bgp4.update.tlv.linkstate_attribute_tlvs.UnreservedBandwidthLinkAttribTLV;
import es.tid.bgp.bgp4.update.tlv.node_link_prefix_descriptor_subTLVs.AutonomousSystemNodeDescriptorSubTLV;
import es.tid.bgp.bgp4.update.tlv.node_link_prefix_descriptor_subTLVs.NodeDescriptorsSubTLV;
import es.tid.bgp.bgp4.update.tlv.node_link_prefix_descriptor_subTLVs.NodeDescriptorsSubTLVTypes;
import es.tid.ospf.ospfv2.lsa.LSA;
/**
* This class is used to control BGP updates (not changing database when is a 'refresh BGP message')
*
* WARNING: we only control when adding new link or when bitmap changes.
* @author baam
*
*/
public class UpdateLink {
private MaximumLinkBandwidthLinkAttribTLV maximumLinkBandwidthTLV;
private MaxReservableBandwidthLinkAttribTLV maxReservableBandwidthTLV;
private UnreservedBandwidthLinkAttribTLV unreservedBandwidthTLV;
private LinkNLRI linkNLRI;
private Inet4Address localDomainID;
private Inet4Address localRouterASBR;
private Inet4Address remoteDomainID;
private Inet4Address remoteRouterASBR;
private byte[] bitmap;
private byte[] bitmapReserved;
public UpdateLink(Inet4Address remote, Inet4Address local, byte[] bitMap, byte[] bitmapRes) {
this.bitmap=new byte[bitMap.length];
for(int i=0; i<bitMap.length; i++){
this.bitmap[i]=bitMap[i];
}
if (bitmapRes!=null){
this.bitmapReserved=new byte[bitmapRes.length];
for(int i=0; i<bitmapRes.length; i++){
this.bitmapReserved[i]=bitmapRes[i];
}
}
this.remoteRouterASBR=remote;
this.localRouterASBR=local;
}
public byte[] getBitmap(){
return bitmap;
}
public byte[] getBitmapRserved(){
return bitmapReserved;
}
@Override
public boolean equals(Object updateLink){
if (updateLink == null) {
return false;
}
try {
final UpdateLink other = (UpdateLink) updateLink;
if (!(other.localRouterASBR.equals(this.localRouterASBR)))
return false;
if (!(other.remoteRouterASBR.equals(this.remoteRouterASBR)))
return false;
}catch (Exception e){
return false;
}
return true;
}
}
// Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package eu.teraflow.tid.bgp4Peer.updateTEDB;
import java.io.IOException;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import es.tid.bgp.bgp4.messages.BGP4Update;
import es.tid.bgp.bgp4.update.fields.IPv4PrefixNLRI;
import es.tid.bgp.bgp4.update.fields.ITNodeNLRI;
import es.tid.bgp.bgp4.update.fields.LinkNLRI;
import es.tid.bgp.bgp4.update.fields.LinkStateNLRI;
import es.tid.bgp.bgp4.update.fields.NLRITypes;
import es.tid.bgp.bgp4.update.fields.NodeNLRI;
import es.tid.bgp.bgp4.update.fields.PathAttribute;
import es.tid.bgp.bgp4.update.fields.pathAttributes.AFICodes;
import es.tid.bgp.bgp4.update.fields.pathAttributes.AS_Path_Attribute;
import es.tid.bgp.bgp4.update.fields.pathAttributes.AS_Path_Segment;
import es.tid.bgp.bgp4.update.fields.pathAttributes.BGP_LS_MP_Reach_Attribute;
import es.tid.bgp.bgp4.update.fields.pathAttributes.LinkStateAttribute;
import es.tid.bgp.bgp4.update.fields.pathAttributes.MP_Reach_Attribute;
import es.tid.bgp.bgp4.update.fields.pathAttributes.PathAttributesTypeCode;
import es.tid.bgp.bgp4.update.tlv.linkstate_attribute_tlvs.AdministrativeGroupLinkAttribTLV;
import es.tid.bgp.bgp4.update.tlv.linkstate_attribute_tlvs.DefaultTEMetricLinkAttribTLV;
import es.tid.bgp.bgp4.update.tlv.linkstate_attribute_tlvs.IGPFlagBitsPrefixAttribTLV;
import es.tid.bgp.bgp4.update.tlv.linkstate_attribute_tlvs.IPv4RouterIDLocalNodeLinkAttribTLV;
import es.tid.bgp.bgp4.update.tlv.linkstate_attribute_tlvs.IPv4RouterIDRemoteNodeLinkAttribTLV;
import es.tid.bgp.bgp4.update.tlv.linkstate_attribute_tlvs.IS_IS_AreaIdentifierNodeAttribTLV;
import es.tid.bgp.bgp4.update.tlv.linkstate_attribute_tlvs.LinkProtectionTypeLinkAttribTLV;
import es.tid.bgp.bgp4.update.tlv.linkstate_attribute_tlvs.MF_OTPAttribTLV;
import es.tid.bgp.bgp4.update.tlv.linkstate_attribute_tlvs.MaxReservableBandwidthLinkAttribTLV;
import es.tid.bgp.bgp4.update.tlv.linkstate_attribute_tlvs.MaximumLinkBandwidthLinkAttribTLV;
import es.tid.bgp.bgp4.update.tlv.linkstate_attribute_tlvs.MetricLinkAttribTLV;
import es.tid.bgp.bgp4.update.tlv.linkstate_attribute_tlvs.NodeFlagBitsNodeAttribTLV;
import es.tid.bgp.bgp4.update.tlv.linkstate_attribute_tlvs.NodeNameNodeAttribTLV;
import es.tid.bgp.bgp4.update.tlv.linkstate_attribute_tlvs.OSPFForwardingAddressPrefixAttribTLV;
import es.tid.bgp.bgp4.update.tlv.linkstate_attribute_tlvs.PrefixMetricPrefixAttribTLV;
import es.tid.bgp.bgp4.update.tlv.linkstate_attribute_tlvs.RouteTagPrefixAttribTLV;
import es.tid.bgp.bgp4.update.tlv.linkstate_attribute_tlvs.SidLabelNodeAttribTLV;
import es.tid.bgp.bgp4.update.tlv.linkstate_attribute_tlvs.TransceiverClassAndAppAttribTLV;
import es.tid.bgp.bgp4.update.tlv.linkstate_attribute_tlvs.UnreservedBandwidthLinkAttribTLV;
import es.tid.bgp.bgp4.update.tlv.node_link_prefix_descriptor_subTLVs.MinMaxUndirectionalLinkDelayDescriptorSubTLV;
import es.tid.bgp.bgp4.update.tlv.node_link_prefix_descriptor_subTLVs.NodeDescriptorsSubTLV;
import es.tid.bgp.bgp4.update.tlv.node_link_prefix_descriptor_subTLVs.UndirectionalAvailableBandwidthDescriptorSubTLV;
import es.tid.bgp.bgp4.update.tlv.node_link_prefix_descriptor_subTLVs.UndirectionalDelayVariationDescriptorSubTLV;
import es.tid.bgp.bgp4.update.tlv.node_link_prefix_descriptor_subTLVs.UndirectionalLinkDelayDescriptorSubTLV;
import es.tid.bgp.bgp4.update.tlv.node_link_prefix_descriptor_subTLVs.UndirectionalLinkLossDescriptorSubTLV;
import es.tid.bgp.bgp4.update.tlv.node_link_prefix_descriptor_subTLVs.UndirectionalResidualBandwidthDescriptorSubTLV;
import es.tid.bgp.bgp4.update.tlv.node_link_prefix_descriptor_subTLVs.UndirectionalUtilizedBandwidthDescriptorSubTLV;
import es.tid.ospf.ospfv2.lsa.tlv.subtlv.AdministrativeGroup;
import es.tid.ospf.ospfv2.lsa.tlv.subtlv.AvailableLabels;
import es.tid.ospf.ospfv2.lsa.tlv.subtlv.MaximumBandwidth;
import es.tid.ospf.ospfv2.lsa.tlv.subtlv.MaximumReservableBandwidth;
import es.tid.ospf.ospfv2.lsa.tlv.subtlv.TrafficEngineeringMetric;
import es.tid.ospf.ospfv2.lsa.tlv.subtlv.UnreservedBandwidth;
import es.tid.ospf.ospfv2.lsa.tlv.subtlv.complexFields.BitmapLabelSet;
import eu.teraflow.tid.bgp4Peer.grpc.grpcClient;
import eu.teraflow.tid.bgp4Peer.json.bgpMarshal;
import eu.teraflow.tid.bgp4Peer.models.LinkNLRIMsg;
import eu.teraflow.tid.bgp4Peer.models.NodeNLRIMsg;
import eu.teraflow.tid.bgp4Peer.models.PathAttributeMsg;
import eu.teraflow.tid.bgp4Peer.models.UpdateMsg;
import eu.teraflow.tid.bgp4Peer.models.UpdateMsgList;
import eu.teraflow.tid.tedb.DomainTEDB;
import eu.teraflow.tid.tedb.IT_Resources;
import eu.teraflow.tid.tedb.InterDomainEdge;
import eu.teraflow.tid.tedb.IntraDomainEdge;
import eu.teraflow.tid.tedb.MultiDomainTEDB;
import eu.teraflow.tid.tedb.Node_Info;
import eu.teraflow.tid.tedb.SSONInformation;
import eu.teraflow.tid.tedb.SimpleTEDB;
import eu.teraflow.tid.tedb.TEDB;
import eu.teraflow.tid.tedb.TE_Information;
import eu.teraflow.tid.tedb.WSONInformation;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
/**
* This class process the update messages updating the TEDB.
*
* WARNING: it is suppose to be a SimpleTEDB!!! It is not finished yet.
* @author pac
*
*/
public class UpdateProccesorThread extends Thread {
/**
* Parameter to run the class if it is true
*/
private boolean running;
/**
* Queue which stores the BGP4 update messages to be read and process
*/
private LinkedBlockingQueue<BGP4Update> updateList;
/** LINK ATTRIBUTE TLVs */
MaximumLinkBandwidthLinkAttribTLV maximumLinkBandwidthTLV;
MaxReservableBandwidthLinkAttribTLV maxReservableBandwidthTLV;
UnreservedBandwidthLinkAttribTLV unreservedBandwidthTLV;
AdministrativeGroupLinkAttribTLV administrativeGroupTLV;
LinkProtectionTypeLinkAttribTLV linkProtectionTLV;
MetricLinkAttribTLV metricTLV;
IPv4RouterIDLocalNodeLinkAttribTLV iPv4RouterIDLocalNodeLATLV;
IPv4RouterIDRemoteNodeLinkAttribTLV iPv4RouterIDRemoteNodeLATLV;
DefaultTEMetricLinkAttribTLV TEMetricTLV;
TransceiverClassAndAppAttribTLV transceiverClassAndAppATLV;
MF_OTPAttribTLV mF_OTP_ATLV;
int linkDelay;
int linkDelayVar;
int minDelay;
int maxDelay;
int linkLoss;
int residualBw;
int availableBw;
int utilizedBw;
/** NODE ATTRIBUTE TLVs
* Ipv4 of local node link attribute TLV also used
*
* */
NodeFlagBitsNodeAttribTLV nodeFlagBitsTLV = new NodeFlagBitsNodeAttribTLV();
NodeNameNodeAttribTLV nodeNameTLV = new NodeNameNodeAttribTLV();
IS_IS_AreaIdentifierNodeAttribTLV areaIDTLV = new IS_IS_AreaIdentifierNodeAttribTLV();
SidLabelNodeAttribTLV sidTLV = new SidLabelNodeAttribTLV();
/**PREFIX ATTRIBUTE TLVs */
IGPFlagBitsPrefixAttribTLV igpFlagBitsTLV = new IGPFlagBitsPrefixAttribTLV();
RouteTagPrefixAttribTLV routeTagTLV = new RouteTagPrefixAttribTLV();
PrefixMetricPrefixAttribTLV prefixMetricTLV = new PrefixMetricPrefixAttribTLV();
OSPFForwardingAddressPrefixAttribTLV OSPFForwardingAddrTLV = new OSPFForwardingAddressPrefixAttribTLV();
private AvailableLabels availableLabels;
/**
* Logger
*/
private Logger log;
/**
* Topology database for interDomain Links which will be updated.
*/
private MultiDomainTEDB multiTedb;
/**
* Topology database for intradomain Links. It owns several domains and.
*/
private Hashtable<String,TEDB> intraTEDBs;
private LinkedList<UpdateLink> updateLinks;
private TE_Information te_info;
public UpdateProccesorThread(LinkedBlockingQueue<BGP4Update> updateList,
MultiDomainTEDB multiTedb ,Hashtable<String,TEDB> intraTEDBs ){
log=LoggerFactory.getLogger("BGP4Server");
running=true;
this.updateList=updateList;
this.multiTedb = multiTedb;
this.intraTEDBs=intraTEDBs;
this.availableLabels= new AvailableLabels();
this.updateLinks=new LinkedList<UpdateLink>();
}
/**
* Starts processing updates
*/
public void run(){
BGP4Update updateMsg;
UpdateMsgList updateMsgList = new UpdateMsgList();//write nodes and links info to a file
bgpMarshal m = new bgpMarshal();//add to json file
try {
m.bgpMarshaller();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
int j=0; //debug coverage
while (running && j<100) {
try {
clearAttributes();
UpdateMsg update = new UpdateMsg();//class to send grpc message
PathAttribute att_ls = null;
PathAttribute att_mpreach = null;
PathAttribute att = null;
PathAttribute att_path = null;
updateMsg= updateList.take();
log.info("Update Procesor Thread Reading the message: \n"+ updateMsg.toString());
log.info("\n \n");
//guille update processor
log.debug("END string UPDATE msg");
//Andrea To be checked
String learntFrom = updateMsg.getLearntFrom();
log.info("Received from "+learntFrom);
ArrayList<PathAttribute> pathAttributeList = updateMsg.getPathAttributes();
ArrayList<PathAttribute> pathAttributeListUtil = new ArrayList<PathAttribute>();
update.setLearntFrom(learntFrom);
// buscamos los dos atributos que nos interesan...
for (int i=0;i<pathAttributeList.size();i++){
att = pathAttributeList.get(i);
int typeCode = att.getTypeCode();
switch (typeCode){
case PathAttributesTypeCode.PATH_ATTRIBUTE_TYPECODE_BGP_LS_ATTRIBUTE:
att_ls = att;
break;
case PathAttributesTypeCode.PATH_ATTRIBUTE_TYPECODE_MP_REACH_NLRI:
att_mpreach = att;
break;
case PathAttributesTypeCode.PATH_ATTRIBUTE_TYPECODE_ASPATH:
//log.info("We don't use ASPATH");
att_path=att;
break;
case PathAttributesTypeCode.PATH_ATTRIBUTE_TYPECODE_ORIGIN:
//log.info("We don't use ORIGIN");
break;
default:
//log.info("Attribute typecode " + typeCode +"unknown");
break;
}
}
//guille
log.info("NLRI type: ");
String currentName=null;
if(att_ls!=null)
pathAttributeListUtil.add(att_ls);
if(att_mpreach!=null)
pathAttributeListUtil.add(att_mpreach);
if(att_path!=null) {
//More than 1 as_path segment??
List<AS_Path_Segment> as_path_segments= ((AS_Path_Attribute)att_path).getAsPathSegments();
AS_Path_Segment as_path_segment;
int as_path=0;
if(as_path_segments.size()>0){
as_path_segment=as_path_segments.get(0);
int numberOfSeg=as_path_segment.getNumberOfSegments();
as_path=as_path_segment.getSegments()[0];
}
update.setAsPathSegment(as_path);
}
if (pathAttributeListUtil != null){
for (int i=0;i<pathAttributeListUtil.size();i++){
att = pathAttributeListUtil.get(i);
int typeCode = att.getTypeCode();
switch (typeCode){
// cuando encontramos el link state attribute rellenamos las tlvs que nos llegan para luego
// meterlas en la te_info o en la node_info
case PathAttributesTypeCode.PATH_ATTRIBUTE_TYPECODE_BGP_LS_ATTRIBUTE:
processAttributeLinkState((LinkStateAttribute) att);
PathAttributeMsg pathAtt = new PathAttributeMsg((LinkStateAttribute)att);
log.info("Path attributes: " + pathAtt.toString());
//get node name for current update so then its possible to substitute for the nodeID
currentName=pathAtt.getNodeName();
updateMsgList.addpathToJson(pathAtt);
continue;
// cuando procesamos el mp_reach distinguimos entre nodo y link...
// prefijo aun por hacer
case PathAttributesTypeCode.PATH_ATTRIBUTE_TYPECODE_MP_REACH_NLRI:
int afi;
afi = ((MP_Reach_Attribute)att).getAddressFamilyIdentifier();
update.setAFI(afi);//set afi for grpc msg
InetAddress nextHop=((MP_Reach_Attribute)att).getNextHop();
update.setNextHop(nextHop);//set for grpc msg
if (afi == AFICodes.AFI_BGP_LS){
LinkStateNLRI nlri = (LinkStateNLRI) ((BGP_LS_MP_Reach_Attribute)att).getLsNLRI();
int nlriType = nlri.getNLRIType();
switch (nlriType){
case NLRITypes.Link_NLRI:
// if(((BGP_LS_MP_Reach_Attribute)att).getLsNLRIList().size()<1){
// log.info("Link_NLRI");
// LinkNLRIMsg LnlriMsg = new LinkNLRIMsg((LinkNLRI)nlri,learntFrom);
// log.info("Link info: " + LnlriMsg.toString());
// updateMsgList.addLinkToJson(LnlriMsg);
// update.setLink(LnlriMsg);//set for grpc msg , to be deprecated
// update.addLink(LnlriMsg);//set for grpc msg
// }else{
for(LinkStateNLRI linkstateNLRI : (List<LinkStateNLRI>) ((BGP_LS_MP_Reach_Attribute)att).getLsNLRIList()){
log.info("Link_NLRI");
LinkNLRIMsg LnlriMsg = new LinkNLRIMsg((LinkNLRI)linkstateNLRI,learntFrom);
log.info("Link info: " + LnlriMsg.toString());
updateMsgList.addLinkToJson(LnlriMsg);
update.addLink(LnlriMsg);//set for grpc msg
}
// }
continue;
case NLRITypes.Node_NLRI:
// NodeNLRIMsg NnlriMsg = new NodeNLRIMsg((NodeNLRI)nlri,learntFrom,currentName);
// log.info("Node_NLRI");
// log.info("Node info: " + NnlriMsg.toString());
// updateMsgList.addNodeToJson(NnlriMsg,currentName);
// update.setNode(NnlriMsg);//set for grpc msg
// currentName=null;
for(LinkStateNLRI linkstateNLRI : (List<LinkStateNLRI>) ((BGP_LS_MP_Reach_Attribute)att).getLsNLRIList()){
log.info("Node_NLRI");
NodeNLRIMsg NnlriMsg = new NodeNLRIMsg((NodeNLRI)linkstateNLRI,learntFrom,currentName);
log.info("Node info: " + NnlriMsg.toString());
updateMsgList.addNodeToJson(NnlriMsg,currentName);
update.addNode(NnlriMsg);//set for grpc msg
}
currentName=null;
continue;
case NLRITypes.Prefix_v4_NLRI://POR HACER...
log.info("Prefix_v4_NLRI");
continue;
case NLRITypes.IT_Node_NLRI:
log.info("IT_Node_NLRI");
continue;
default:
log.debug("Attribute Code unknown");
}
}
continue;
default:
log.debug("Attribute Code unknown");
}
}//fin for
try {m.writeFile(updateMsgList);} catch (IOException e) {e.printStackTrace();}
}
//
log.warn("\n");
// System.out.println(update.toString());
//cambiar clase?
log.info("--->Sending to grpc manager");
try {
grpcClient.sendGrpcUpdateMsg(update);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//fin guille
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
j++;
}//fin while
// try {
// channel.shutdown().awaitTermination(5, TimeUnit.SECONDS);
// } catch (InterruptedException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
System.exit(0);
}
/**
* Function which process the attribute link State. It updates the fields passed by argument.
*/
private void processAttributeLinkState(LinkStateAttribute lsAtt){
if (lsAtt.getMaximumLinkBandwidthTLV() != null){
maximumLinkBandwidthTLV = lsAtt.getMaximumLinkBandwidthTLV();
}
if (lsAtt.getMaxReservableBandwidthTLV() != null){
maxReservableBandwidthTLV = lsAtt.getMaxReservableBandwidthTLV();
}
if (lsAtt.getUnreservedBandwidthTLV() != null){
unreservedBandwidthTLV = lsAtt.getUnreservedBandwidthTLV();
}
if(lsAtt.getAdministrativeGroupTLV() != null){
administrativeGroupTLV = lsAtt.getAdministrativeGroupTLV();
}
if(lsAtt.getLinkProtectionTLV() != null){
linkProtectionTLV = lsAtt.getLinkProtectionTLV();
}
if(lsAtt.getIPv4RouterIDLocalNodeLATLV()!= null){
iPv4RouterIDLocalNodeLATLV = lsAtt.getIPv4RouterIDLocalNodeLATLV();
}
if(lsAtt.getIPv4RouterIDRemoteNodeLATLV()!=null){
iPv4RouterIDRemoteNodeLATLV = lsAtt.getIPv4RouterIDRemoteNodeLATLV();
}
if(lsAtt.getMetricTLV() != null){
metricTLV = lsAtt.getMetricTLV();
}
if(lsAtt.getTEMetricTLV()!=null){
TEMetricTLV = lsAtt.getTEMetricTLV();
}
if(lsAtt.getNodeFlagBitsTLV()!= null){
nodeFlagBitsTLV = lsAtt.getNodeFlagBitsTLV();
}
if(lsAtt.getNodeNameTLV() != null){
nodeNameTLV = lsAtt.getNodeNameTLV();
}
if(lsAtt.getAreaIDTLV() != null){
areaIDTLV = lsAtt.getAreaIDTLV();
}
if(lsAtt.getIgpFlagBitsTLV() != null){
igpFlagBitsTLV= lsAtt.getIgpFlagBitsTLV();
}
if(lsAtt.getRouteTagTLV() != null){
routeTagTLV = lsAtt.getRouteTagTLV();
}
if(lsAtt.getOSPFForwardingAddrTLV() != null){
OSPFForwardingAddrTLV = lsAtt.getOSPFForwardingAddrTLV();
}
if(lsAtt.getSidLabelTLV()!=null){
sidTLV = lsAtt.getSidLabelTLV();
}
if (lsAtt.getAvailableLabels() != null){
this.availableLabels =lsAtt.getAvailableLabels();
}
if (lsAtt.getMF_OTP_ATLV() != null){
this.mF_OTP_ATLV =lsAtt.getMF_OTP_ATLV();
}
if (lsAtt.getTransceiverClassAndAppATLV() != null){
this.transceiverClassAndAppATLV =lsAtt.getTransceiverClassAndAppATLV();
}
}
/**
* Function which process the link NLRI. It updates the fields passed by argument.
* @param linkNLRI
* @param maximumLinkBandwidthTLV
* @param maxReservableBandwidthTLV
* @param unreservedBandwidthTLV
* @param availableLabels
*/
/** Procesar un link significa:
* crear los vertices si no existen ya
* crear la edge si no existe ya
* crear la te_info o actualizarla
* @param linkNLRI
* @param learntFrom
*/
private void clearAttributes(){
maximumLinkBandwidthTLV= null;
maxReservableBandwidthTLV= null;
unreservedBandwidthTLV= null;
administrativeGroupTLV = null;
linkProtectionTLV =null;
metricTLV = null;
iPv4RouterIDLocalNodeLATLV = null;
iPv4RouterIDRemoteNodeLATLV = null;
TEMetricTLV = null;
transceiverClassAndAppATLV = null;
mF_OTP_ATLV = null;
availableLabels=null;
linkDelay=0;
linkDelayVar=0;
minDelay=0;
maxDelay=0;
linkLoss=0;
residualBw=0;
availableBw=0;
utilizedBw=0;
}
}
// Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package eu.teraflow.tid.bgp4Peer.updateTEDB;
import java.util.LinkedList;
import java.util.concurrent.LinkedBlockingQueue;
import redis.clients.jedis.Jedis;
import es.tid.ospf.ospfv2.OSPFv2LinkStateUpdatePacket;
import es.tid.ospf.ospfv2.lsa.LSA;
import es.tid.ospf.ospfv2.lsa.LSATypes;
import es.tid.ospf.ospfv2.lsa.OSPFTEv2LSA;
import eu.teraflow.tid.tedb.DatabaseControlSimplifiedLSA;
public class UpdaterThreadRedisTED extends Thread{
//FIXME: Configure from file
private Jedis jedis;
private String host="localhost";
private int port=6379;
private LinkedBlockingQueue<OSPFv2LinkStateUpdatePacket> redisOspfv2PacketQueue;
public UpdaterThreadRedisTED(LinkedBlockingQueue<OSPFv2LinkStateUpdatePacket> redisOspfv2PacketQueue) {
// TODO Auto-generated constructor stub
this.redisOspfv2PacketQueue = redisOspfv2PacketQueue;
jedis = new Jedis(host,port);
}
public void run() {
LinkedList<LSA> lsaList;
OSPFTEv2LSA lsa;
OSPFv2LinkStateUpdatePacket ospfv2Packet;
jedis.connect();
//FIXE: Add disconnect
while(true){
try {
ospfv2Packet = redisOspfv2PacketQueue.take();
lsaList = ((OSPFv2LinkStateUpdatePacket)ospfv2Packet).getLSAlist();
for (int i =0;i< lsaList.size();i++){
if (lsaList.get(i).getLStype() == LSATypes.TYPE_10_OPAQUE_LSA){
lsa=(OSPFTEv2LSA)lsaList.get(i);
DatabaseControlSimplifiedLSA dcsl = new DatabaseControlSimplifiedLSA();
dcsl.fillSimplifiedLsa(lsa);
String jsonLSA = dcsl.logJsonSimplifiedLSA();
//RedisDatabaseHandler rdh = new RedisDatabaseHandler();
String key="LSA:"+dcsl.getAdvertisingRouter().getHostAddress()+":"+dcsl.getLinkId().getHostAddress();
String ret = jedis.set(key, jsonLSA);
jedis.sadd("TEDB",key);
}
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
\ No newline at end of file
// Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package eu.teraflow.tid.tedb;
import java.net.Inet4Address;
import com.google.gson.Gson;
import es.tid.ospf.ospfv2.lsa.OSPFTEv2LSA;
import es.tid.ospf.ospfv2.lsa.tlv.subtlv.AvailableLabels;
import es.tid.ospf.ospfv2.lsa.tlv.subtlv.complexFields.BitmapLabelSet;
/**
*
* Class for simplified database write of LSAs
*
* @author Fernando Mu�oz del Nuevo
*
*
*
*/
public class DatabaseControlSimplifiedLSA {
public Inet4Address advertisingRouter;
public Inet4Address linkId;
public long linkLocalIdentifier;
public long linkRemoteIdentifier;
public String bitmapLabelSet;
public float maximumBandwidth;
public float unreservedBandwidth;
public float maximumReservableBandwidth;
//protected LinkedList<Inet4Address> labelSet;
public Inet4Address getAdvertisingRouter() {
return advertisingRouter;
}
public void setAdvertisingRouter(Inet4Address advertisingRouter) {
this.advertisingRouter = advertisingRouter;
}
public Inet4Address getLinkId() {
return linkId;
}
public void setLinkId(Inet4Address linkId) {
this.linkId = linkId;
}
public long getLinkLocalIdentifier() {
return linkLocalIdentifier;
}
public void setLinkLocalIdentifier(long linkLocalIdentifier) {
this.linkLocalIdentifier = linkLocalIdentifier;
}
public long getLinkRemoteIdentifier() {
return linkRemoteIdentifier;
}
public void setLinkRemoteIdentifier(long linkRemoteIdentifier) {
this.linkRemoteIdentifier = linkRemoteIdentifier;
}
public String getBitmapLabelSet() {
return bitmapLabelSet;
}
public void setBitmapLabelSet(String bitmapLabelSet) {
this.bitmapLabelSet = bitmapLabelSet;
}
public float getMaximumBandwidth() {
return maximumBandwidth;
}
public void setMaximumBandwidth(float maximumBandwidth) {
this.maximumBandwidth = maximumBandwidth;
}
public float getUnreservedBandwidth() {
return unreservedBandwidth;
}
public void setUnreservedBandwidth(float unreservedBandwidth) {
this.unreservedBandwidth = unreservedBandwidth;
}
public float getMaximumReservableBandwidth() {
return maximumReservableBandwidth;
}
public void setMaximumReservableBandwidth(float maximumReservableBandwidth) {
this.maximumReservableBandwidth = maximumReservableBandwidth;
}
public void fillBitmap(AvailableLabels availableLabels){
int num_wavelength = 0;
bitmapLabelSet = "";
while(num_wavelength < availableLabels.getLabelSet().getNumLabels()){
int num_byte=num_wavelength/8;
boolean isFree = ((((BitmapLabelSet)availableLabels.getLabelSet()).getBytesBitMap()[num_byte]&(0x80>>>(num_wavelength%8)))==0);
if(isFree){
bitmapLabelSet = bitmapLabelSet + "0";
}else{
bitmapLabelSet = bitmapLabelSet + "1";
}
num_wavelength++;
}
}
public void fillSimplifiedLsa(OSPFTEv2LSA lsa){
if (lsa.getAdvertisingRouter()!=null)
this.setAdvertisingRouter(lsa.getAdvertisingRouter());
if (lsa.getLinkTLV().getLinkID().getLinkID()!=null)
this.setLinkId(lsa.getLinkTLV().getLinkID().getLinkID());
if (lsa.getLinkTLV().getLinkLocalRemoteIdentifiers()!=null){
this.setLinkLocalIdentifier(lsa.getLinkTLV().getLinkLocalRemoteIdentifiers().getLinkLocalIdentifier());
this.setLinkRemoteIdentifier(lsa.getLinkTLV().getLinkLocalRemoteIdentifiers().getLinkRemoteIdentifier());
}
if (lsa.getLinkTLV().getMaximumBandwidth()!=null)
this.setMaximumBandwidth(lsa.getLinkTLV().getMaximumBandwidth().getMaximumBandwidth());
if (lsa.getLinkTLV().getUnreservedBandwidth()!=null){
this.setMaximumBandwidth(lsa.getLinkTLV().getUnreservedBandwidth().unreservedBandwidth[0]);
} if (lsa.getLinkTLV().getMaximumReservableBandwidth()!=null){
this.setMaximumReservableBandwidth(lsa.getLinkTLV().getMaximumReservableBandwidth().maximumReservableBandwidth);
}
if (lsa.getLinkTLV().getAvailableLabels()!=null){
this.fillBitmap(lsa.getLinkTLV().getAvailableLabels());
}
}
public String logJsonSimplifiedLSA(){
Gson gson = new Gson();
String json = gson.toJson(this);
return json;
//IPInterfaceTrafficRequest iitr2 = gson.fromJson(json, DatabaseControlSimplifiedLSA.class);
}
}
// Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package eu.teraflow.tid.tedb;
import java.net.Inet4Address;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.Set;
import es.tid.ospf.ospfv2.lsa.tlv.subtlv.complexFields.BitmapLabelSet;
public interface DomainTEDB extends TEDB {
public Inet4Address getDomainID();
public boolean belongsToDomain(Object addr);
//public Object getDomainId();
public ReachabilityEntry getReachabilityEntry();
//public byte[] getDomainReachabilityIPv4Prefix();
public LinkedList<InterDomainEdge> getInterDomainLinks();
public Set<IntraDomainEdge> getIntraDomainLinks();
public String printInterDomainLinks();
public boolean containsVertex(Object vertex);
public WSONInformation getWSONinfo();
public void setWSONinfo(WSONInformation wSONinfo);
public SSONInformation getSSONinfo();
public void setSSONinfo(SSONInformation sSONinfo);
public void notifyWavelengthReservation(LinkedList<Object> sourceVertexList, LinkedList<Object> targetVertexList, int wavelength, boolean bidirectional);
public void notifyWavelengthReservationSSON (LinkedList<Object> sourceVertexList, LinkedList<Object> targetVertexList, int wavelength, boolean bidirectional, int m);
public void notifyWavelengthEndReservation(LinkedList<Object> sourceVertexList, LinkedList<Object> targetVertexList, int wavelength, boolean bidirectional);
public void notifyWavelengthChange(Object localInterfaceIPAddress,Object remoteInterfaceIPAddress,BitmapLabelSet previousBitmapLabelSet,BitmapLabelSet newBitmapLabelSet );
public void notifyNewEdgeIP(Object source, Object destination, TE_Information informationTEDB);
public void register(TEDListener compAlgPreComp);
public void registerSSON(SSONListener compAlgPreComp);
public void notifyNewVertex(Object vertex);
public void notifyNewEdge (Object source, Object destination);
public void clearAllReservations();
public void notifyWavelengthEndReservationSSON(
LinkedList<Object> sourceVertexList,
LinkedList<Object> targetVertexList, int wavelength,
boolean bidirectional, int m);
public void notifyWavelengthReservationWLAN(
LinkedList<Object> sourceVertexList,
LinkedList<Object> targetVertexList, LinkedList<Integer> wlans,
boolean bidirectional);
public void createGraph();
public Set<Object> getIntraDomainLinksvertexSet();
public Hashtable<Object, Node_Info> getNodeTable();
public IT_Resources getItResources();
public void setItResources(IT_Resources itResources);
}
// Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package eu.teraflow.tid.tedb;
import java.net.Inet4Address;
import es.tid.of.DataPathID;
public class EdgeUtils {
public static Object getEdge(String edge){
Object router_id_addr;
try { //Router_type: IPv4
router_id_addr = (Inet4Address) Inet4Address.getByName(edge);
} catch (Exception e) { //Router_type: DatapathID
router_id_addr = (DataPathID) DataPathID.getByName(edge);
//FIXME: See what to do if it is not IPv4 or DatapahID
}
return router_id_addr;
}
}
// Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package eu.teraflow.tid.tedb;
import es.tid.bgp.bgp4.update.tlv.linkstate_attribute_tlvs.DefaultTEMetricLinkAttribTLV;
import es.tid.bgp.bgp4.update.tlv.node_link_prefix_descriptor_subTLVs.*;
import es.tid.of.DataPathID;
import es.tid.ospf.ospfv2.lsa.tlv.subtlv.AvailableLabels;
import es.tid.ospf.ospfv2.lsa.tlv.subtlv.MaximumBandwidth;
import es.tid.ospf.ospfv2.lsa.tlv.subtlv.UnreservedBandwidth;
import es.tid.ospf.ospfv2.lsa.tlv.subtlv.complexFields.BitmapLabelSet;
import es.tid.rsvp.constructs.gmpls.DWDMWavelengthLabel;
import es.tid.rsvp.objects.subobjects.IPv4prefixEROSubobject;
import org.jgrapht.graph.DirectedWeightedMultigraph;
import org.jgrapht.graph.SimpleDirectedWeightedGraph;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.*;
import org.w3c.dom.CharacterData;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File;
import java.net.Inet4Address;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.LinkedList;
/**
* Convenience class to read Traffic Engineering Databases from XML files.
*
* @author ogondio
*
*/
public class FileTEDBUpdater {
/**
* Read a full network (no specific layer)
* @param fileName Name of the XML file
* @return Graph of the Network
*/
public static SimpleDirectedWeightedGraph<Object, IntraDomainEdge> readNetwork(String fileName){
return FileTEDBUpdater.readNetwork(fileName,null,false,0,Integer.MAX_VALUE);
}
/**
* Reads a specific layer from a Network XML file
* @param fileName Name of the XML file
* @param layer Layer
* @return Graph of the network
*/
public static SimpleDirectedWeightedGraph<Object, IntraDomainEdge> readNetwork(String fileName,String layer){
return FileTEDBUpdater.readNetwork(fileName,layer,false,0,Integer.MAX_VALUE, false);
}
/**
* Reads a specific layer from a Network XML file
* It can treat all domains as a single domain
* @param fileName Name of the XML file
* @param layer Layer
* @param allDomains if all domains are read or not
* @return Graph of the network
*/
public static SimpleDirectedWeightedGraph<Object, IntraDomainEdge> readNetwork(String fileName,String layer,boolean allDomains){
return FileTEDBUpdater.readNetwork(fileName,layer,allDomains,0,Integer.MAX_VALUE, false);
}
/**
* Reads a specific layer from a Network XML file
* It can treat all domains as a single domain
* @param fileName Name of the XML file
* @param layer Layer
* @param allDomains if all domains are read or not
* @param lambdaIni first lambda (n)
* @param lambdaEnd last lamnda (n)
* @return Graph of the network
*/
public static SimpleDirectedWeightedGraph<Object, IntraDomainEdge> readNetwork(String fileName, String layer,boolean allDomains,int lambdaIni, int lambdaEnd) {
return FileTEDBUpdater.readNetwork(fileName,layer,allDomains,0,Integer.MAX_VALUE, false);
}
/**
* Reads a specific layer from a Network XML file.
* It can treat all domains as a single domain.
*
* @param fileName Name of the XML file
* @param layer Layer
* @param allDomains if all domains are read or not
* @param lambdaIni first lambda (n)
* @param lambdaEnd last lamnda (n)
* @param isSSONnetwork If the network supports Flexi Grid
* @return Graph of the network.
*/
public static SimpleDirectedWeightedGraph<Object, IntraDomainEdge> readNetwork(String fileName, String layer,boolean allDomains,int lambdaIni, int lambdaEnd, boolean isSSONnetwork) {
Logger log = LoggerFactory.getLogger("BGP4Peer");
Object router_id_addr = null;
Object s_router_id_addr = null;
Object d_router_id_addr = null;
Object src_Numif_id = null;
Object dst_Numif_id = null;
//First, create the graph
SimpleDirectedWeightedGraph<Object, IntraDomainEdge> graph = new SimpleDirectedWeightedGraph<Object, IntraDomainEdge>(IntraDomainEdge.class);
log.debug("1. SimpleDirectedWeightedGraph");
File file = new File(fileName);
try {
String domain_id = "";
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(file);
HashMap<Inet4Address, Integer >SIDS = new HashMap<Inet4Address,Integer>();
HashMap<DataPathID, Integer >SIDSDP = new HashMap<DataPathID,Integer>();
NodeList nodes_domains = doc.getElementsByTagName("domain");
if (layer!=null){
log.debug("Reading topology, looking for layer "+ layer);
}
//First pass to get all the nodes
//If we need to read all the domains
for (int j = 0; j < nodes_domains.getLength(); j++) {
boolean readNetwork=false;
Element element1 = (Element) nodes_domains.item(j);
if (layer!=null){
NodeList domain_layer = element1.getElementsByTagName("layer");
if (domain_layer.getLength()==1){
Element layer_type = (Element) domain_layer.item(0);
log.debug("Layer: " + layer_type.getAttributeNode("type").getValue());
log.debug("Reading network topology");
if (layer_type.getAttributeNode("type").getValue().equals(layer)){
readNetwork = true;
}
if (layer.equals("interlayer")){
readNetwork = true;
}
}
}else {
readNetwork=true;
}
if (readNetwork){
Element element_domain = (Element) nodes_domains.item(j);
NodeList nodes_domain_id = element_domain.getElementsByTagName("domain_id");
for (int k = 0; k < nodes_domain_id.getLength(); k++) {
Element domain_id_e = (Element) nodes_domain_id.item(0);
domain_id = getCharacterDataFromElement(domain_id_e);
log.debug("Loading nodes for domain: " + domain_id);
log.info("Loading topology from domain " + domain_id);
}
NodeList nodes = element1.getElementsByTagName("node");
for (int i = 0; i < nodes.getLength(); i++) {
Element element = (Element) nodes.item(i);
NodeList router_id_node = element.getElementsByTagName("router_id");
Element router_id_e = (Element) router_id_node.item(0);
String router_id = getCharacterDataFromElement(router_id_e);
log.info("Adding node " + router_id);
router_id_addr = EdgeUtils.getEdge(router_id);
graph.addVertex(router_id_addr);
log.debug("About to look for SID");
NodeList SID_aux = element.getElementsByTagName("sid");
Element SID_e = (Element) SID_aux.item(0);
if (SID_e!=null)
{
log.debug("SID exist");
int SID = Integer.parseInt(getCharacterDataFromElement(SID_e));
try { //Router_type: DatapathID
SIDS.put((Inet4Address) router_id_addr,SID);
log.debug("SID of node Inet4Address: "+SID);
} catch (Exception e) { //Router_type: DatapathID
SIDSDP.put((DataPathID)router_id_addr, SID);
log.debug("SID of node DataPathID: "+SID);
}
}
else
{
log.debug("SID not found");
}
}
}
}
//Next pass to get all the links
for (int j = 0; j < nodes_domains.getLength(); j++) {
boolean readNetwork=false;
Element element1 = (Element) nodes_domains.item(j);
if (layer!=null){
NodeList domain_layer = element1.getElementsByTagName("layer");
if (domain_layer.getLength()==1){
Element layer_type = (Element) domain_layer.item(0);
log.debug("Layer: " + layer_type.getAttributeNode("type").getValue());
log.debug("Reading Topology");
if (layer_type.getAttributeNode("type").getValue().equals(layer)){
readNetwork = true;
}
}
}else {
readNetwork=true;
}
log.debug("Read network = "+readNetwork);
if (readNetwork){
Element element_domain = (Element) nodes_domains.item(j);
NodeList nodes_domain_id = element_domain.getElementsByTagName("domain_id");
for (int k = 0; k < nodes_domain_id.getLength(); k++) {
Element domain_id_e = (Element) nodes_domain_id.item(0);
domain_id = getCharacterDataFromElement(domain_id_e);
log.debug("Looking for links in domain: " + domain_id);
}
int numLabels=0;
Boolean commonBitmapLabelSet = false;
NodeList edgeCommon = doc.getElementsByTagName("edgeCommon");
int grid=0;
int cs=0;
int n=0;
for (int i = 0; i < edgeCommon.getLength(); i++) {
Element edgeCommonElement = (Element) edgeCommon.item(i);
NodeList availableLabels_node = edgeCommonElement.getElementsByTagName("AvailableLabels");
for (int k = 0; k < availableLabels_node.getLength(); k++) {
Element availableLabels_e = (Element) availableLabels_node.item(k);
NodeList labelSetField_node = availableLabels_e.getElementsByTagName("LabelSetField");
Element labelSetField_el = (Element) labelSetField_node.item(0);
if (labelSetField_el.getAttributeNode("type").getValue().equals("4")){//Tengo BitMapSet
//Crear un BitMapSet
NodeList numbLabels_node = labelSetField_el.getElementsByTagName("numLabels");
Element numbLabels_e = (Element) numbLabels_node.item(0);
String numbLabels_s = getCharacterDataFromElement(numbLabels_e);
numLabels=Integer.parseInt(numbLabels_s);
NodeList baseLabel_node = labelSetField_el.getElementsByTagName("baseLabel");
Element baseLabel_e = (Element) baseLabel_node.item(0);
float min_frequency;
grid= Integer.parseInt(baseLabel_e.getAttributeNode("grid").getValue());
cs = Integer.parseInt(baseLabel_e.getAttributeNode("cs").getValue());
boolean n_frequency_included=false;
if (baseLabel_e.getAttributeNode("n") != null ){
n = Integer.parseInt(baseLabel_e.getAttributeNode("n").getValue());
n_frequency_included = true;
}
else if (baseLabel_e.getAttributeNode("min_frequency") != null){
String s_min_frequency = labelSetField_el.getAttributeNode("min_frequency").getValue();
min_frequency=Float.parseFloat(s_min_frequency);
n = ((int)min_frequency - 1471)/20;
n_frequency_included=true;
}
if (n_frequency_included){
commonBitmapLabelSet = true;
}else{
log.error("ERROR reading the xml file of the topology, you should enter <baseLabel grid=\"1\" cs=\"2\" n=\"-11\"></baseLabel> ");
}
}
}
}
/*if(isSSONnetwork ==true){
if(cs==4){
numLabels=numLabels*4;
}
else if (cs==5){
numLabels=numLabels*8;
}
}*/
NodeList edges = element_domain.getElementsByTagName("edge");
for (int i = 0; i < edges.getLength(); i++) {
log.info("New Edge");
Element element = (Element) edges.item(i);
//By default, all nodes are intradomain
String type;
Attr attr_type=element.getAttributeNode("type");
if (attr_type==null){
type="intradomain";
}else {
type=attr_type.getValue();
if (allDomains){
if (type.equals("interdomain")){
type="intradomain";
}
}
else if (type.equals("interlayer")){
if (layer.equals("interlayer")){
type="intradomain";
}
}
}
log.debug("type::"+type);
if (type.equals("intradomain")) {
IntraDomainEdge edge = new IntraDomainEdge();
log.info("New Intradomain Edge");
NodeList source = element.getElementsByTagName("source");
Element source_router_el = (Element) source.item(0);
NodeList source_router_id = source_router_el.getElementsByTagName("router_id");
Element source_router_id_el = (Element) source_router_id.item(0);
String s_r_id = getCharacterDataFromElement(source_router_id_el);
s_router_id_addr= EdgeUtils.getEdge(s_r_id);
NodeList source_if_id_nl = source_router_el.getElementsByTagName("if_id");
Element source_if_id_el = (Element) source_if_id_nl.item(0);
String s_source_if_id;
int src_if_id = -1;
if (source_if_id_el!=null){
s_source_if_id = getCharacterDataFromElement(source_if_id_el);
src_if_id = Integer.parseInt(s_source_if_id);
}
if (src_if_id!=-1) {
log.debug("SRC if id: "+src_if_id);
}
NodeList source_Numif_id_nl = source_router_el.getElementsByTagName("NumIf_id");
Element source_Numif_id_el = (Element) source_Numif_id_nl.item(0);
String s_source_Numif_id=null;
if (source_Numif_id_el!=null){
s_source_Numif_id = getCharacterDataFromElement(source_Numif_id_el);
try { // src_Numif_id type : Inet4Address
src_Numif_id = (Inet4Address) Inet4Address.getByName(s_source_Numif_id);
} catch (Exception e) { // src_Numif_id type : DataPathID
src_Numif_id = DataPathID.getByName(s_source_Numif_id);
}
}
if (s_source_Numif_id!=null) {
log.debug("NumIf_id id: "+src_Numif_id);
}
NodeList dest_nl = element.getElementsByTagName("destination");
Element dest_el = (Element) dest_nl.item(0);
NodeList dest_router_id_nl = dest_el.getElementsByTagName("router_id");
Element dest_router_id_el = (Element) dest_router_id_nl.item(0);
String d_r_id = getCharacterDataFromElement(dest_router_id_el);
d_router_id_addr= EdgeUtils.getEdge(d_r_id);
//Anyadimos los SID
if (SIDS.get(s_router_id_addr)!=null && SIDS.get(d_router_id_addr)!=null)
{
log.debug("setting SIDS src: "+SIDS.get(s_router_id_addr)+" dst: "+SIDS.get(d_router_id_addr));
edge.setSrc_sid(SIDS.get(s_router_id_addr));
edge.setDst_sid(SIDS.get(d_router_id_addr));
log.debug("edge.getSrc_sid(): "+edge.getSrc_sid());
log.debug("edge.getDst_sid(): "+edge.getDst_sid());
}
else if (SIDSDP.get(s_router_id_addr)!=null && SIDSDP.get(d_router_id_addr)!=null)
{
log.debug("setting SIDSDP src: "+SIDSDP.get(s_router_id_addr)+" dst: "+SIDSDP.get(d_router_id_addr));
edge.setSrc_sid(SIDSDP.get(s_router_id_addr));
edge.setDst_sid(SIDSDP.get(d_router_id_addr));
log.debug("edge.getSrc_sid(): "+edge.getSrc_sid());
log.debug("edge.getDst_sid(): "+edge.getDst_sid());
}
NodeList dest_if_id_nl = dest_el.getElementsByTagName("if_id");
Element dest_if_id_el= (Element) dest_if_id_nl.item(0);
String s_dest_if_id;
int dst_if_id = -1;
if (dest_if_id_el!=null){
s_dest_if_id = getCharacterDataFromElement(dest_if_id_el);
dst_if_id = Integer.parseInt(s_dest_if_id);
}
if (dst_if_id!=-1) {
log.debug("DST if id: "+dst_if_id);
}
NodeList dest_Numif_id_nl = dest_el.getElementsByTagName("NumIf_id");
Element dest_Numif_id_el = (Element) dest_Numif_id_nl.item(0);
String s_dest_Numif_id=null;
if (source_Numif_id_el!=null){
s_dest_Numif_id = getCharacterDataFromElement(dest_Numif_id_el);
try { // s_dest_Numif_id type : Inet4Address
dst_Numif_id = (Inet4Address) Inet4Address.getByName(s_dest_Numif_id);
} catch (Exception e) { // s_dest_Numif_id type : DataPathID
dst_Numif_id = DataPathID.getByName(s_dest_Numif_id);
}
}
if (s_dest_Numif_id!=null) {
log.debug("DST NumIf_id id: "+dst_Numif_id);
}
// Añadimos interfaces Numeradas
if (src_Numif_id!=null){
edge.setSrc_Numif_id(src_Numif_id);
}if (dst_Numif_id!=null){
edge.setDst_Numif_id(dst_Numif_id);
}else{
if (src_if_id != -1){
edge.setSrc_if_id(src_if_id);
}
if (dst_if_id != -1){
edge.setDst_if_id(dst_if_id);
}
}
//DELAY, IF IT COMES..
NodeList delay_ms_nl = element.getElementsByTagName("delay");
if (delay_ms_nl.getLength()>0){
Element delay_ms_el = (Element)delay_ms_nl.item(0);
String s_delay_ms=getCharacterDataFromElement(delay_ms_el);
double delay_ms=Double.parseDouble(s_delay_ms);
edge.setDelay_ms(delay_ms);
}
//TE Link information
NodeList maximum_bandwidth_nl = element.getElementsByTagName("maximum_bandwidth");
if (maximum_bandwidth_nl!=null){
if (maximum_bandwidth_nl.getLength()>0){
if(edge.getTE_info()==null){
TE_Information tE_info= new TE_Information();
if (commonBitmapLabelSet){
if(lambdaEnd!=Integer.MAX_VALUE){
tE_info.createBitmapLabelSet(numLabels, grid, cs, n,lambdaIni,lambdaEnd);
}
else
tE_info.createBitmapLabelSet(numLabels, grid, cs, n);
}
//tid.util.FuncionesUtiles.printByte(((BitmapLabelSet)tE_info.getAvailableLabels().getLabelSet()).getBytesBitmapReserved(),"getBytesBitmapReserved1:");
edge.setTE_info(tE_info);
} else {
TE_Information te_info = edge.getTE_info();
if (commonBitmapLabelSet){
// if(lambdaEnd!=Integer.MAX_VALUE){
// te_info.createBitmapLabelSet(numLabels, grid, cs, n,lambdaIni,lambdaEnd);
// }
// else
te_info.createBitmapLabelSet(numLabels, grid, cs, n);
}
//tid.util.FuncionesUtiles.printByte(((BitmapLabelSet)tE_info.getAvailableLabels().getLabelSet()).getBytesBitmapReserved(),"getBytesBitmapReserved1:");
edge.setTE_info(te_info);
}
Element maximum_bandwidth_el = (Element) maximum_bandwidth_nl.item(0);
String s_maximum_bandwidth = getCharacterDataFromElement(maximum_bandwidth_el);
float maximum_bandwidth=Float.parseFloat(s_maximum_bandwidth);
MaximumBandwidth maximumBandwidth =new MaximumBandwidth();
maximumBandwidth.setMaximumBandwidth(maximum_bandwidth);
(edge.getTE_info()).setMaximumBandwidth(maximumBandwidth);
}
}
/**
* NodeList SID_aux = element.getElementsByTagName("sid");
Element SID_e = (Element) SID_aux.item(0);
if (SID_e!=null)
{
log.info("SID existe");
int SID = Integer.parseInt(getCharacterDataFromElement(SID_e));
SIDS.put(router_id_addr,SID);
log.info("SID of node: "+SID);
}
else
{
log.info("SID not found");
}
*/
NodeList defaultmetric = element.getElementsByTagName("default_te_metric");
Element metric_aux = (Element) defaultmetric.item(0);
if (metric_aux != null){
String s_metric_aux = getCharacterDataFromElement(metric_aux);
TE_Information tE_info;
int metric = Integer.parseInt(s_metric_aux);
DefaultTEMetricLinkAttribTLV defaultTeMetric= new DefaultTEMetricLinkAttribTLV();
if(edge.getTE_info()==null){
tE_info= new TE_Information();
}
else{
tE_info = edge.getTE_info();
}
defaultTeMetric.setLinkMetric((long)metric);
tE_info.setDefaultTEMetric(defaultTeMetric);
edge.setTE_info(tE_info);
}
NodeList unreserved_bandwidth_nl = element.getElementsByTagName("unreserved_bandwidth");
if (unreserved_bandwidth_nl!=null){
int num_u_b=unreserved_bandwidth_nl.getLength();
UnreservedBandwidth unreservedBandwidth;
if (num_u_b>0){
if(edge.getTE_info()==null){
TE_Information tE_info= new TE_Information();
if (commonBitmapLabelSet){
if(lambdaEnd!=Integer.MAX_VALUE)
tE_info.createBitmapLabelSet(numLabels, grid, cs, n,lambdaIni,lambdaEnd);
else
tE_info.createBitmapLabelSet(numLabels, grid, cs, n);
}
edge.setTE_info(tE_info);
}
unreservedBandwidth =new UnreservedBandwidth();
(edge.getTE_info()).setUnreservedBandwidth(unreservedBandwidth);
for(int k=0;k<num_u_b;++k){
Element unreserved_bandwidth_el = (Element) unreserved_bandwidth_nl.item(k);
String s_unreserved_bandwidth = getCharacterDataFromElement(unreserved_bandwidth_el);
String s_priority=unreserved_bandwidth_el.getAttributeNode("priority").getValue();
Integer priority = Integer.valueOf(s_priority);
float unreserved_bandwidth=Float.parseFloat(s_unreserved_bandwidth);
(unreservedBandwidth.getUnreservedBandwidth())[priority]=unreserved_bandwidth;
}
}
}
NodeList maximum_wlans_nl = element.getElementsByTagName("number_wlans");
if (maximum_wlans_nl!=null){
if (maximum_wlans_nl.getLength()>0){
if(edge.getTE_info()==null){
TE_Information tE_info= new TE_Information();
if (commonBitmapLabelSet){
if(lambdaEnd!=Integer.MAX_VALUE){
tE_info.createBitmapLabelSet(numLabels, grid, cs, n,lambdaIni,lambdaEnd);
}
else
tE_info.createBitmapLabelSet(numLabels, grid, cs, n);
}
//tid.util.FuncionesUtiles.printByte(((BitmapLabelSet)tE_info.getAvailableLabels().getLabelSet()).getBytesBitmapReserved(),"getBytesBitmapReserved1:");
edge.setTE_info(tE_info);
}
Element number_wlan_el = (Element) maximum_wlans_nl.item(0);
String s_number_wlans = getCharacterDataFromElement(number_wlan_el);
int number_wlans=Integer.parseInt(s_number_wlans.replace("\n", "").replaceAll("\\s",""));
(edge.getTE_info()).setNumberWLANs(number_wlans);
(edge.getTE_info()).initWLANs();
}
}
if(edge.getTE_info()==null){
TE_Information tE_info= new TE_Information();
edge.setTE_info(tE_info);
}
if (commonBitmapLabelSet){
if(lambdaEnd!=Integer.MAX_VALUE)
edge.getTE_info().createBitmapLabelSet(numLabels, grid, cs, n,lambdaIni,lambdaEnd);
else
edge.getTE_info().createBitmapLabelSet(numLabels, grid, cs, n);
}
NodeList availableLabels_node = element.getElementsByTagName("AvailableLabels");
if ( availableLabels_node != null){
for (int k = 0; k < availableLabels_node.getLength(); k++) {
Element availableLabels_e = (Element) availableLabels_node.item(k);
NodeList labelSetField_node = availableLabels_e.getElementsByTagName("LabelSetField");
Element labelSetField_el = (Element) labelSetField_node.item(0);
if (labelSetField_el.getAttributeNode("type").getValue().equals("4")){//Tengo BitMapSet
NodeList numbLabels_node = labelSetField_el.getElementsByTagName("numLabels");
Element numbLabels_e = (Element) numbLabels_node.item(0);
String numbLabels_s = getCharacterDataFromElement(numbLabels_e);
numLabels=Integer.parseInt(numbLabels_s);
NodeList baseLabel_node = labelSetField_el.getElementsByTagName("baseLabel");
Element baseLabel_e = (Element) baseLabel_node.item(0);
byte[] bitmap=new byte[1];
NodeList bitmap_node = labelSetField_el.getElementsByTagName("bitmap");
int result=0;
Element bitmap_e = (Element) bitmap_node.item(0);
if (bitmap_e!=null){
String bitmap_string=getCharacterDataFromElement(bitmap_e);
log.debug("Bitmap read: "+bitmap_string);
for (int p =0; p<bitmap_string.length(); p++)
result= (int) (result+Math.pow(2, bitmap_string.length()-p-1)*(bitmap_string.charAt(p)-48));
bitmap[0]=(byte) result;
((BitmapLabelSet)edge.getTE_info().getAvailableLabels().getLabelSet()).setBytesBitmap(bitmap);
}
float min_frequency;
grid= Integer.parseInt(baseLabel_e.getAttributeNode("grid").getValue());
cs = Integer.parseInt(baseLabel_e.getAttributeNode("cs").getValue());
boolean n_frequency_included=false;
if (baseLabel_e.getAttributeNode("n") != null ){
n = Integer.parseInt(baseLabel_e.getAttributeNode("n").getValue());
n_frequency_included = true;
}
else if (baseLabel_e.getAttributeNode("min_frequency") != null){
String s_min_frequency = labelSetField_el.getAttributeNode("min_frequency").getValue();
min_frequency=Float.parseFloat(s_min_frequency);
n = ((int)min_frequency - 1471)/20;
n_frequency_included=true;
}
if (n_frequency_included){/*Modify availableLabels*/
((BitmapLabelSet)edge.getTE_info().getAvailableLabels().getLabelSet()).setNumLabels(numLabels);
((BitmapLabelSet)edge.getTE_info().getAvailableLabels().getLabelSet()).getDwdmWavelengthLabel().setGrid(grid);
((BitmapLabelSet)edge.getTE_info().getAvailableLabels().getLabelSet()).getDwdmWavelengthLabel().setChannelSpacing(cs);
((BitmapLabelSet)edge.getTE_info().getAvailableLabels().getLabelSet()).getDwdmWavelengthLabel().setN(n);
}
else{
log.error("ERROR reading the xml file of the topology, you should enter <baseLabel grid=\"1\" cs=\"2\" n=\"-11\"></baseLabel> ");
}
}
}
}
log.debug("Preparing to add edge");
try{
if(graph.containsEdge(s_router_id_addr, d_router_id_addr)){
graph.getEdge(s_router_id_addr, d_router_id_addr).setNumberFibers(graph.getEdge(s_router_id_addr, d_router_id_addr).getNumberFibers()+1);
}else{
log.debug("s_router_id_addr: "+s_router_id_addr.toString()+"; d_router_id_addr: "+d_router_id_addr.toString()+"; edge: "+edge);
graph.addEdge(s_router_id_addr, d_router_id_addr, edge);
graph.getEdge(s_router_id_addr, d_router_id_addr).setNumberFibers(1);
}
log.info("Adding edge from "+s_router_id_addr.toString()+" to "+d_router_id_addr.toString()+"; \n "+edge);
}catch(Exception e){
log.error("Problem with source "+s_router_id_addr+" destination "+d_router_id_addr);
e.printStackTrace();
System.exit(-1);
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
log.debug("Info graph edge :: "+graph.edgeSet());
return graph;
}
/*private static SimpleDirectedWeightedGraph<Object, IntraDomainEdge> readGraphIntraDomain(Element element1, String layer, Logger log){
Object router_id_addr = null;
HashMap<Inet4Address, Integer >SIDS = new HashMap<Inet4Address,Integer>();
HashMap<DataPathID, Integer >SIDSDP = new HashMap<DataPathID,Integer>();
SimpleDirectedWeightedGraph<Object, IntraDomainEdge> graph = new SimpleDirectedWeightedGraph<Object, IntraDomainEdge>(IntraDomainEdge.class);
//NodeList nodes_domains = doc.getElementsByTagName("domain");
boolean readNetwork=false;
//Element element1 = (Element) nodes_domains.item(j);
String domain_id = "";
if (layer!=null){
NodeList domain_layer = element1.getElementsByTagName("layer");
if (domain_layer.getLength()==1){
Element layer_type = (Element) domain_layer.item(0);
log.info("Layer: " + layer_type.getAttributeNode("type").getValue());
log.info("Reading network topology");
if (layer_type.getAttributeNode("type").getValue().equals(layer)){
readNetwork = true;
}
if (layer.equals("interlayer")){
readNetwork = true;
}
}
}else {
readNetwork=true;
}
if (readNetwork){
Element element_domain = element1;
NodeList nodes_domain_id = element_domain.getElementsByTagName("domain_id");
for (int k = 0; k < nodes_domain_id.getLength(); k++) {
Element domain_id_e = (Element) nodes_domain_id.item(0);
domain_id = getCharacterDataFromElement(domain_id_e);
//log.info("Looking for nodes in domain: " + domain_id);
}
NodeList nodes = element1.getElementsByTagName("node");
for (int i = 0; i < nodes.getLength(); i++) {
Element element = (Element) nodes.item(i);
NodeList router_id_node = element.getElementsByTagName("router_id");
Element router_id_e = (Element) router_id_node.item(0);
String router_id = getCharacterDataFromElement(router_id_e);
//log.info("Adding router_id " + router_id);
router_id_addr = EdgeUtils.getEdge(router_id);
graph.addVertex(router_id_addr);
//log.info("About to look for SID");
NodeList SID_aux = element.getElementsByTagName("sid");
Element SID_e = (Element) SID_aux.item(0);
if (SID_e!=null)
{
//log.info("SID existe");
int SID = Integer.parseInt(getCharacterDataFromElement(SID_e));
try { //Router_type: DatapathID
SIDS.put((Inet4Address) router_id_addr,SID);
//log.info("SID of node Inet4Address: "+SID);
} catch (Exception e) { //Router_type: DatapathID
SIDSDP.put((DataPathID)router_id_addr, SID);
//log.info("SID of node DataPathID: "+SID);
}
}
else
{
//log.info("SID not found");
}
}
}
return graph;
}*/
public static Hashtable<String,TEDB> readMultipleDomainSimpleNetworks(String fileName, String layer,boolean allDomains,int lambdaIni, int lambdaEnd, boolean isSSONnetwork) {
Logger log = LoggerFactory.getLogger("BGP4Peer");
Object router_id_addr = null;
Object s_router_id_addr = null;
Object d_router_id_addr = null;
Object src_Numif_id = null;
Object dst_Numif_id = null;
Hashtable<String,TEDB> TEDBs = new Hashtable<String,TEDB>();
//First, create the graph
log.debug("1. SimpleDirectedWeightedGraph");
File file = new File(fileName);
try {
String domain_id = "";
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(file);
HashMap<Inet4Address, Integer >SIDS = new HashMap<Inet4Address,Integer>();
HashMap<DataPathID, Integer >SIDSDP = new HashMap<DataPathID,Integer>();
NodeList nodes_domains = doc.getElementsByTagName("domain");
if (layer!=null){
log.debug("Reading topology, looking for layer "+ layer);
}
//First pass to get all the nodes
//If we need to read all the domains
for (int j = 0; j < nodes_domains.getLength(); j++) {
boolean readNetwork=false;
Element element1 = (Element) nodes_domains.item(j);
SimpleTEDB tedb = new SimpleTEDB();
SimpleDirectedWeightedGraph<Object, IntraDomainEdge> graph = new SimpleDirectedWeightedGraph<Object, IntraDomainEdge>(IntraDomainEdge.class);
if (layer!=null){
NodeList domain_layer = element1.getElementsByTagName("layer");
if (domain_layer.getLength()==1){
Element layer_type = (Element) domain_layer.item(0);
log.debug("Layer: " + layer_type.getAttributeNode("type").getValue());
log.debug("Reading network topology");
if (layer_type.getAttributeNode("type").getValue().equals(layer)){
readNetwork = true;
}
if (layer.equals("interlayer")){
readNetwork = true;
}
}
}else {
readNetwork=true;
}
if (readNetwork){
Element element_domain = (Element) nodes_domains.item(j);
NodeList nodes_domain_id = element_domain.getElementsByTagName("domain_id");
for (int k = 0; k < nodes_domain_id.getLength(); k++) {
Element domain_id_e = (Element) nodes_domain_id.item(0);
domain_id = getCharacterDataFromElement(domain_id_e);
log.debug("Looking for nodes in domain: " + domain_id);
log.info("Loading topology from domain " + domain_id);
}
NodeList itResourcesElement = element1.getElementsByTagName("it_resources");
for (int i = 0; i < itResourcesElement.getLength(); i++) {
Element element = (Element) itResourcesElement.item(i);
NodeList itResourcesControllerITList = element.getElementsByTagName("controller_it");
Element itResourcesControllerITElement = (Element) itResourcesControllerITList.item(0);
String itResourcesControllerIT = getCharacterDataFromElement(itResourcesControllerITElement);
NodeList itResourcesCpuList = element.getElementsByTagName("cpu");
Element itResourcesCpuElement = (Element) itResourcesCpuList.item(0);
String itResourcesCpu = getCharacterDataFromElement(itResourcesCpuElement);
NodeList itResourcesMemList = element.getElementsByTagName("mem");
Element itResourcesMemElement = (Element) itResourcesMemList.item(0);
String itResourcesMem = getCharacterDataFromElement(itResourcesMemElement);
NodeList itResourcesStorageList = element.getElementsByTagName("storage");
Element itResourcesStorageElement = (Element) itResourcesStorageList.item(0);
String itResourcesStorage = getCharacterDataFromElement(itResourcesStorageElement);
IT_Resources itResources = new IT_Resources();
if (itResourcesControllerIT!=null) itResources.setControllerIT(itResourcesControllerIT);
if (itResourcesCpu!=null) itResources.setCpu(itResourcesCpu);
if (itResourcesMem!=null) itResources.setMem(itResourcesMem);
if (itResourcesStorage!=null) itResources.setStorage(itResourcesStorage);
tedb.setItResources(itResources);
}
NodeList nodes = element1.getElementsByTagName("node");
for (int i = 0; i < nodes.getLength(); i++) {
Element element = (Element) nodes.item(i);
NodeList router_id_node = element.getElementsByTagName("router_id");
Element router_id_e = (Element) router_id_node.item(0);
String router_id = getCharacterDataFromElement(router_id_e);
log.info("Adding node " + router_id);
router_id_addr = EdgeUtils.getEdge(router_id);
graph.addVertex(router_id_addr);
log.debug("About to look for SID");
NodeList SID_aux = element.getElementsByTagName("sid");
Element SID_e = (Element) SID_aux.item(0);
if (SID_e!=null)
{
log.debug("SID exist");
int SID = Integer.parseInt(getCharacterDataFromElement(SID_e));
try { //Router_type: DatapathID
SIDS.put((Inet4Address) router_id_addr,SID);
log.debug("SID of node Inet4Address: "+SID);
} catch (Exception e) { //Router_type: DatapathID
SIDSDP.put((DataPathID)router_id_addr, SID);
log.debug("SID of node DataPathID: "+SID);
}
}
else
{
log.debug("SID not found");
}
}
}
tedb.setNetworkGraph(graph);
tedb.setDomainID((Inet4Address) Inet4Address.getByName(domain_id));
TEDBs.put(domain_id,tedb);
}
//Next pass to get all the links
for (int j = 0; j < nodes_domains.getLength(); j++) {
SimpleDirectedWeightedGraph<Object, IntraDomainEdge> graph=null;
boolean readNetwork=false;
Element element1 = (Element) nodes_domains.item(j);
if (layer!=null){
NodeList domain_layer = element1.getElementsByTagName("layer");
if (domain_layer.getLength()==1){
Element layer_type = (Element) domain_layer.item(0);
log.debug("Layer: " + layer_type.getAttributeNode("type").getValue());
log.debug("Reading Topology");
if (layer_type.getAttributeNode("type").getValue().equals(layer)){
readNetwork = true;
}
}
}else {
readNetwork=true;
}
log.debug("Read network = "+readNetwork);
if (readNetwork){
Element element_domain = (Element) nodes_domains.item(j);
NodeList nodes_domain_id = element_domain.getElementsByTagName("domain_id");
for (int k = 0; k < nodes_domain_id.getLength(); k++) {
Element domain_id_e = (Element) nodes_domain_id.item(0);
domain_id = getCharacterDataFromElement(domain_id_e);
log.debug("Looking for links in domain: " + domain_id);
}
//System.out.println("VVV debug domain id:"+domain_id);
SimpleTEDB domainTEDB = (SimpleTEDB)TEDBs.get( domain_id);
graph = domainTEDB.getNetworkGraph();
int numLabels=0;
TE_Information tE_info_common=null;
Boolean commonBitmapLabelSet = false;
NodeList edgeCommon = element1.getElementsByTagName("edgeCommon");
int grid=0;
int cs=0;
int n=0;
for (int i = 0; i < edgeCommon.getLength(); i++) {
Element edgeCommonElement = (Element) edgeCommon.item(i);
tE_info_common =readTE_INFOfromXml(tE_info_common,edgeCommonElement, false,numLabels, grid, cs, n, 0, Integer.MAX_VALUE);
NodeList availableLabels_node = edgeCommonElement.getElementsByTagName("AvailableLabels");
for (int k = 0; k < availableLabels_node.getLength(); k++) {
Element availableLabels_e = (Element) availableLabels_node.item(k);
NodeList labelSetField_node = availableLabels_e.getElementsByTagName("LabelSetField");
Element labelSetField_el = (Element) labelSetField_node.item(0);
if (labelSetField_el.getAttributeNode("type").getValue().equals("4")){//Tengo BitMapSet
//Crear un BitMapSet
NodeList numbLabels_node = labelSetField_el.getElementsByTagName("numLabels");
Element numbLabels_e = (Element) numbLabels_node.item(0);
String numbLabels_s = getCharacterDataFromElement(numbLabels_e);
numLabels=Integer.parseInt(numbLabels_s);
NodeList baseLabel_node = labelSetField_el.getElementsByTagName("baseLabel");
Element baseLabel_e = (Element) baseLabel_node.item(0);
float min_frequency;
grid= Integer.parseInt(baseLabel_e.getAttributeNode("grid").getValue());
cs = Integer.parseInt(baseLabel_e.getAttributeNode("cs").getValue());
boolean n_frequency_included=false;
if (baseLabel_e.getAttributeNode("n") != null ){
n = Integer.parseInt(baseLabel_e.getAttributeNode("n").getValue());
n_frequency_included = true;
}
else if (baseLabel_e.getAttributeNode("min_frequency") != null){
String s_min_frequency = labelSetField_el.getAttributeNode("min_frequency").getValue();
min_frequency=Float.parseFloat(s_min_frequency);
n = ((int)min_frequency - 1471)/20;
n_frequency_included=true;
}
if (n_frequency_included){
commonBitmapLabelSet = true;
}else{
log.error("ERROR reading the xml file of the topology, you should enter <baseLabel grid=\"1\" cs=\"2\" n=\"-11\"></baseLabel> ");
}
}
}
}
/*if(isSSONnetwork ==true){
if(cs==4){
numLabels=numLabels*4;
}
else if (cs==5){
numLabels=numLabels*8;
}
}*/
NodeList edges = element_domain.getElementsByTagName("edge");
for (int i = 0; i < edges.getLength(); i++) {
log.debug("New Link");
Element element = (Element) edges.item(i);
//By default, all nodes are intradomain
String type;
Attr attr_type=element.getAttributeNode("type");
if (attr_type==null){
type="intradomain";
}else {
type=attr_type.getValue();
/*if (allDomains){
if (type.equals("interdomain")){
type="intradomain";
}
}*/
//else if (type.equals("interlayer")){
if (layer!=null && layer.equals("interlayer")){
type="intradomain";
}
//}
}
log.debug("type::"+type);
if (type.equals("intradomain")) {
IntraDomainEdge edge = new IntraDomainEdge();
NodeList source = element.getElementsByTagName("source");
Element source_router_el = (Element) source.item(0);
NodeList source_router_id = source_router_el.getElementsByTagName("router_id");
Element source_router_id_el = (Element) source_router_id.item(0);
String s_r_id = getCharacterDataFromElement(source_router_id_el);
s_router_id_addr= EdgeUtils.getEdge(s_r_id);
NodeList source_if_id_nl = source_router_el.getElementsByTagName("if_id");
Element source_if_id_el = (Element) source_if_id_nl.item(0);
String s_source_if_id;
int src_if_id = -1;
if (source_if_id_el!=null){
s_source_if_id = getCharacterDataFromElement(source_if_id_el);
src_if_id = Integer.parseInt(s_source_if_id);
}
log.debug("SRC if id: "+src_if_id);
NodeList source_Numif_id_nl = source_router_el.getElementsByTagName("NumIf_id");
Element source_Numif_id_el = (Element) source_Numif_id_nl.item(0);
String s_source_Numif_id;
if (source_Numif_id_el!=null){
s_source_Numif_id = getCharacterDataFromElement(source_Numif_id_el);
try { // src_Numif_id type : Inet4Address
src_Numif_id = (Inet4Address) Inet4Address.getByName(s_source_Numif_id);
} catch (Exception e) { // src_Numif_id type : DataPathID
src_Numif_id = DataPathID.getByName(s_source_Numif_id);
}
}
NodeList dest_nl = element.getElementsByTagName("destination");
Element dest_el = (Element) dest_nl.item(0);
NodeList dest_router_id_nl = dest_el.getElementsByTagName("router_id");
Element dest_router_id_el = (Element) dest_router_id_nl.item(0);
String d_r_id = getCharacterDataFromElement(dest_router_id_el);
d_router_id_addr= EdgeUtils.getEdge(d_r_id);
//Anyadimos los SID
if (SIDS.get(s_router_id_addr)!=null && SIDS.get(d_router_id_addr)!=null)
{
log.debug("setting SIDS src: "+SIDS.get(s_router_id_addr)+" dst: "+SIDS.get(d_router_id_addr));
edge.setSrc_sid(SIDS.get(s_router_id_addr));
edge.setDst_sid(SIDS.get(d_router_id_addr));
log.debug("edge.getSrc_sid(): "+edge.getSrc_sid());
log.debug("edge.getDst_sid(): "+edge.getDst_sid());
}
else if (SIDSDP.get(s_router_id_addr)!=null && SIDSDP.get(d_router_id_addr)!=null)
{
log.debug("setting SIDSDP src: "+SIDSDP.get(s_router_id_addr)+" dst: "+SIDSDP.get(d_router_id_addr));
edge.setSrc_sid(SIDSDP.get(s_router_id_addr));
edge.setDst_sid(SIDSDP.get(d_router_id_addr));
log.debug("edge.getSrc_sid(): "+edge.getSrc_sid());
log.debug("edge.getDst_sid(): "+edge.getDst_sid());
}
NodeList dest_if_id_nl = dest_el.getElementsByTagName("if_id");
Element dest_if_id_el= (Element) dest_if_id_nl.item(0);
String s_dest_if_id;
int dst_if_id = -1;
if (dest_if_id_el!=null){
s_dest_if_id = getCharacterDataFromElement(dest_if_id_el);
dst_if_id = Integer.parseInt(s_dest_if_id);
}
log.debug("DST if id: "+dst_if_id);
NodeList dest_Numif_id_nl = dest_el.getElementsByTagName("NumIf_id");
Element dest_Numif_id_el = (Element) dest_Numif_id_nl.item(0);
String s_dest_Numif_id;
if (source_Numif_id_el!=null){
s_dest_Numif_id = getCharacterDataFromElement(dest_Numif_id_el);
try { // s_dest_Numif_id type : Inet4Address
dst_Numif_id = (Inet4Address) Inet4Address.getByName(s_dest_Numif_id);
} catch (Exception e) { // s_dest_Numif_id type : DataPathID
dst_Numif_id = DataPathID.getByName(s_dest_Numif_id);
}
}
// Añadimos interfaces Numeradas
if (src_Numif_id!=null){
edge.setSrc_Numif_id(src_Numif_id);
}if (dst_Numif_id!=null){
edge.setDst_Numif_id(dst_Numif_id);
}else{
if (src_if_id != -1){
edge.setSrc_if_id(src_if_id);
}
if (dst_if_id != -1){
edge.setDst_if_id(dst_if_id);
}
}
//DELAY, IF IT COMES..
NodeList delay_ms_nl = element.getElementsByTagName("delay");
if (delay_ms_nl.getLength()>0){
Element delay_ms_el = (Element)delay_ms_nl.item(0);
String s_delay_ms=getCharacterDataFromElement(delay_ms_el);
double delay_ms=Double.parseDouble(s_delay_ms);
edge.setDelay_ms(delay_ms);
}
//TE Link information
edge.setTE_info(readTE_INFOfromXml(tE_info_common, element, commonBitmapLabelSet,numLabels, grid, cs, n,lambdaIni,lambdaEnd));
NodeList availableLabels_node = element.getElementsByTagName("AvailableLabels");
if ( availableLabels_node != null){
for (int k = 0; k < availableLabels_node.getLength(); k++) {
Element availableLabels_e = (Element) availableLabels_node.item(k);
NodeList labelSetField_node = availableLabels_e.getElementsByTagName("LabelSetField");
Element labelSetField_el = (Element) labelSetField_node.item(0);
if (labelSetField_el.getAttributeNode("type").getValue().equals("4")){//Tengo BitMapSet
NodeList numbLabels_node = labelSetField_el.getElementsByTagName("numLabels");
Element numbLabels_e = (Element) numbLabels_node.item(0);
String numbLabels_s = getCharacterDataFromElement(numbLabels_e);
numLabels=Integer.parseInt(numbLabels_s);
NodeList baseLabel_node = labelSetField_el.getElementsByTagName("baseLabel");
Element baseLabel_e = (Element) baseLabel_node.item(0);
byte[] bitmap=new byte[1];
NodeList bitmap_node = labelSetField_el.getElementsByTagName("bitmap");
int result=0;
Element bitmap_e = (Element) bitmap_node.item(0);
if (bitmap_e!=null){
String bitmap_string=getCharacterDataFromElement(bitmap_e);
System.out.println("Bitmap read: "+bitmap_string);
for (int p =0; p<bitmap_string.length(); p++)
result= (int) (result+Math.pow(2, bitmap_string.length()-p-1)*(bitmap_string.charAt(p)-48));
bitmap[0]=(byte) result;
((BitmapLabelSet)edge.getTE_info().getAvailableLabels().getLabelSet()).setBytesBitmap(bitmap);
}
float min_frequency;
grid= Integer.parseInt(baseLabel_e.getAttributeNode("grid").getValue());
cs = Integer.parseInt(baseLabel_e.getAttributeNode("cs").getValue());
boolean n_frequency_included=false;
if (baseLabel_e.getAttributeNode("n") != null ){
n = Integer.parseInt(baseLabel_e.getAttributeNode("n").getValue());
n_frequency_included = true;
}
else if (baseLabel_e.getAttributeNode("min_frequency") != null){
String s_min_frequency = labelSetField_el.getAttributeNode("min_frequency").getValue();
min_frequency=Float.parseFloat(s_min_frequency);
n = ((int)min_frequency - 1471)/20;
n_frequency_included=true;
}
if (n_frequency_included){/*Modify availableLabels*/
((BitmapLabelSet)edge.getTE_info().getAvailableLabels().getLabelSet()).setNumLabels(numLabels);
((BitmapLabelSet)edge.getTE_info().getAvailableLabels().getLabelSet()).getDwdmWavelengthLabel().setGrid(grid);
((BitmapLabelSet)edge.getTE_info().getAvailableLabels().getLabelSet()).getDwdmWavelengthLabel().setChannelSpacing(cs);
((BitmapLabelSet)edge.getTE_info().getAvailableLabels().getLabelSet()).getDwdmWavelengthLabel().setN(n);
}
else{
log.error("ERROR reading the xml file of the topology, you should enter <baseLabel grid=\"1\" cs=\"2\" n=\"-11\"></baseLabel> ");
}
}
}
}
log.debug("Preparing to add edge");
log.debug("NODES IN GRAPH:: "+graph.vertexSet());
try{
if(graph.containsEdge(s_router_id_addr, d_router_id_addr)){
log.debug("New Intradomain Edge");
graph.getEdge(s_router_id_addr, d_router_id_addr).setNumberFibers(graph.getEdge(s_router_id_addr, d_router_id_addr).getNumberFibers()+1);
log.debug("s_router_id_addr: "+s_router_id_addr.toString()+"; d_router_id_addr: "+d_router_id_addr.toString()+"; edge: "+edge);
log.info("New intradomain link: "+s_router_id_addr.toString()+" --> "+d_router_id_addr.toString());//+" \n "+edge);
}else{
log.debug("s_router_id_addr: "+s_router_id_addr.toString()+"; d_router_id_addr: "+d_router_id_addr.toString()+"; edge: "+edge);
if(graph.containsVertex(d_router_id_addr)==false){
//interDomain edge
//TODO
type="interdomain";
}else{
graph.addEdge(s_router_id_addr, d_router_id_addr, edge);
graph.getEdge(s_router_id_addr, d_router_id_addr).setNumberFibers(1);
log.debug("New Intradomain Edge");
log.info("New intradomain link: "+s_router_id_addr.toString()+" --> "+d_router_id_addr.toString());//+" \n "+edge);
}
}
}catch(Exception e){
log.error("Problem with source "+s_router_id_addr+" destination "+d_router_id_addr);
e.printStackTrace();
System.exit(-1);
}
}
if(type.equals("interdomain")){
log.debug("New Interdomain Edge");
InterDomainEdge edge = new InterDomainEdge();
TE_Information tE_info=readTE_INFOfromXml(tE_info_common,element, false,numLabels, grid, cs, n, 0, Integer.MAX_VALUE);
edge.setTE_info(tE_info);
NodeList source = element.getElementsByTagName("source");
Element source_router_el = (Element) source.item(0);
NodeList source_router_id = source_router_el
.getElementsByTagName("router_id");
Element source_router_id_el = (Element) source_router_id
.item(0);
String s_r_id = getCharacterDataFromElement(source_router_id_el);
log.debug("Edge Source router_id: " + s_r_id);
try { // s_router_id_addr type: Inet4Address
s_router_id_addr = (Inet4Address) Inet4Address.getByName(s_r_id);
} catch (Exception e) {// s_router_id_addr type: DataPathID
s_router_id_addr = DataPathID.getByName(s_r_id);
}
Inet4Address source_domain_id = (Inet4Address) Inet4Address.getByName(domain_id);
log.debug("Edge Source domain_id: " + source_domain_id);
NodeList source_if_id_nl = source_router_el
.getElementsByTagName("if_id");
Element source_if_id_el = (Element) source_if_id_nl.item(0);
String s_source_if_id = getCharacterDataFromElement(source_if_id_el);
log.debug("Edge Source if_id: " + s_source_if_id);
int src_if_id = Integer.parseInt(s_source_if_id);
NodeList dest_nl = element.getElementsByTagName("destination");
Element dest_el = (Element) dest_nl.item(0);
NodeList dest_router_id_nl = dest_el
.getElementsByTagName("router_id");
Element dest_router_id_el = (Element) dest_router_id_nl.item(0);
String d_r_id = getCharacterDataFromElement(dest_router_id_el);
log.debug("Edge Destination router_id: " + d_r_id);
try { // d_router_id_addr type: Inet4Address
d_router_id_addr = (Inet4Address) Inet4Address.getByName(d_r_id);
} catch (Exception e) { // d_router_id_addr type: DataPathID
d_router_id_addr = DataPathID.getByName(d_r_id);
}
//Inet4Address dest_domain_id = router_id_domain_ed.get(d_router_id_addr);
log.debug("Destination domain_id: <Unknown>");
NodeList dest_if_id_nl = dest_el.getElementsByTagName("if_id");
Element dest_if_id_el = (Element) dest_if_id_nl.item(0);
String s_dest_if_id = getCharacterDataFromElement(dest_if_id_el);
log.debug("Edge Dest if_id: " + s_dest_if_id);
int dst_if_id = Integer.parseInt(s_dest_if_id);
//router_id_domain_ed
//edge.setDomain_src_router(source_domain_id);
edge.setSrc_if_id(src_if_id);
edge.setDst_if_id(dst_if_id);
edge.setDomain_src_router(source_domain_id);
//edge.setDomain_dst_router(dest_domain_id);
edge.setSrc_router_id(s_router_id_addr);
edge.setDst_router_id(d_router_id_addr);
if(domainTEDB.getInterDomainLinks()==null){
LinkedList<InterDomainEdge> interDomainLinks= new LinkedList<InterDomainEdge>();
interDomainLinks.add(edge);
domainTEDB.setInterDomainLinks(interDomainLinks);
log.info("New interdomain link: "+s_router_id_addr.toString()+" --> "+d_router_id_addr.toString());//+"; \n "+edge);
}else{
domainTEDB.getInterDomainLinks().add(edge);
log.info("New interdomain link: "+s_router_id_addr.toString()+" --> "+d_router_id_addr.toString());//+"; \n "+edge);
}
}
}
}
log.debug("Info graph edge :: "+graph.edgeSet());
}
} catch (Exception e) {
e.printStackTrace();
}
return TEDBs;
}
public static Hashtable<String,TEDB> readMultipleDomainSimpleNetworks(String fileName, String layer,boolean allDomains,int lambdaIni, int lambdaEnd, boolean isSSONnetwork, String learntFrom) {
Logger log = LoggerFactory.getLogger("BGP4Peer");
Object router_id_addr = null;
Object s_router_id_addr = null;
Object d_router_id_addr = null;
Object src_Numif_id = null;
Object dst_Numif_id = null;
Hashtable<String,TEDB> TEDBs = new Hashtable<String,TEDB>();
//First, create the graph
log.debug("1. SimpleDirectedWeightedGraph");
File file = new File(fileName);
try {
String domain_id = "";
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(file);
HashMap<Inet4Address, Integer >SIDS = new HashMap<Inet4Address,Integer>();
HashMap<DataPathID, Integer >SIDSDP = new HashMap<DataPathID,Integer>();
NodeList nodes_domains = doc.getElementsByTagName("domain");
if (layer!=null){
log.debug("Reading topology, looking for layer "+ layer);
}
//First pass to get all the nodes
//If we need to read all the domains
for (int j = 0; j < nodes_domains.getLength(); j++) {
boolean readNetwork=false;
Element element1 = (Element) nodes_domains.item(j);
SimpleTEDB tedb = new SimpleTEDB();
SimpleDirectedWeightedGraph<Object, IntraDomainEdge> graph = new SimpleDirectedWeightedGraph<Object, IntraDomainEdge>(IntraDomainEdge.class);
if (layer!=null){
NodeList domain_layer = element1.getElementsByTagName("layer");
if (domain_layer.getLength()==1){
Element layer_type = (Element) domain_layer.item(0);
log.debug("Layer: " + layer_type.getAttributeNode("type").getValue());
log.debug("Reading network topology");
if (layer_type.getAttributeNode("type").getValue().equals(layer)){
readNetwork = true;
}
if (layer.equals("interlayer")){
readNetwork = true;
}
}
}else {
readNetwork=true;
}
if (readNetwork){
Element element_domain = (Element) nodes_domains.item(j);
NodeList nodes_domain_id = element_domain.getElementsByTagName("domain_id");
for (int k = 0; k < nodes_domain_id.getLength(); k++) {
Element domain_id_e = (Element) nodes_domain_id.item(0);
domain_id = getCharacterDataFromElement(domain_id_e);
log.debug("Looking for nodes in domain: " + domain_id);
log.info("Loading topology from domain " + domain_id);
}
NodeList itResourcesElement = element1.getElementsByTagName("it_resources");
for (int i = 0; i < itResourcesElement.getLength(); i++) {
Element element = (Element) itResourcesElement.item(i);
NodeList itResourcesControllerITList = element.getElementsByTagName("controller_it");
Element itResourcesControllerITElement = (Element) itResourcesControllerITList.item(0);
String itResourcesControllerIT = getCharacterDataFromElement(itResourcesControllerITElement);
NodeList itResourcesCpuList = element.getElementsByTagName("cpu");
Element itResourcesCpuElement = (Element) itResourcesCpuList.item(0);
String itResourcesCpu = getCharacterDataFromElement(itResourcesCpuElement);
NodeList itResourcesMemList = element.getElementsByTagName("mem");
Element itResourcesMemElement = (Element) itResourcesMemList.item(0);
String itResourcesMem = getCharacterDataFromElement(itResourcesMemElement);
NodeList itResourcesStorageList = element.getElementsByTagName("storage");
Element itResourcesStorageElement = (Element) itResourcesStorageList.item(0);
String itResourcesStorage = getCharacterDataFromElement(itResourcesStorageElement);
IT_Resources itResources = new IT_Resources();
if (itResourcesControllerIT!=null){
itResources.setControllerIT(itResourcesControllerIT);
itResources.setLearntFrom(learntFrom);
}
if (itResourcesCpu!=null) itResources.setCpu(itResourcesCpu);
if (itResourcesMem!=null) itResources.setMem(itResourcesMem);
if (itResourcesStorage!=null) {
itResources.setStorage(itResourcesStorage);
log.info("set learn from for it resources "+ itResources.toString());
}
tedb.setItResources(itResources);
}
NodeList nodes = element1.getElementsByTagName("node");
for (int i = 0; i < nodes.getLength(); i++) {
Element element = (Element) nodes.item(i);
NodeList router_id_node = element.getElementsByTagName("router_id");
Element router_id_e = (Element) router_id_node.item(0);
String router_id = getCharacterDataFromElement(router_id_e);
log.info("Adding node " + router_id);
router_id_addr = EdgeUtils.getEdge(router_id);
graph.addVertex(router_id_addr);
log.debug("About to look for SID");
NodeList SID_aux = element.getElementsByTagName("sid");
Element SID_e = (Element) SID_aux.item(0);
if (SID_e!=null)
{
log.debug("SID exist");
int SID = Integer.parseInt(getCharacterDataFromElement(SID_e));
try { //Router_type: DatapathID
SIDS.put((Inet4Address) router_id_addr,SID);
log.debug("SID of node Inet4Address: "+SID);
} catch (Exception e) { //Router_type: DatapathID
SIDSDP.put((DataPathID)router_id_addr, SID);
log.debug("SID of node DataPathID: "+SID);
}
}
else
{
log.debug("SID not found");
}
}
}
tedb.setNetworkGraph(graph);
tedb.setDomainID((Inet4Address) Inet4Address.getByName(domain_id));
TEDBs.put(domain_id,tedb);
}
//Next pass to get all the links
for (int j = 0; j < nodes_domains.getLength(); j++) {
SimpleDirectedWeightedGraph<Object, IntraDomainEdge> graph=null;
boolean readNetwork=false;
Element element1 = (Element) nodes_domains.item(j);
if (layer!=null){
NodeList domain_layer = element1.getElementsByTagName("layer");
if (domain_layer.getLength()==1){
Element layer_type = (Element) domain_layer.item(0);
log.debug("Layer: " + layer_type.getAttributeNode("type").getValue());
log.debug("Reading Topology");
if (layer_type.getAttributeNode("type").getValue().equals(layer)){
readNetwork = true;
}
}
}else {
readNetwork=true;
}
log.debug("Read network = "+readNetwork);
if (readNetwork){
Element element_domain = (Element) nodes_domains.item(j);
NodeList nodes_domain_id = element_domain.getElementsByTagName("domain_id");
for (int k = 0; k < nodes_domain_id.getLength(); k++) {
Element domain_id_e = (Element) nodes_domain_id.item(0);
domain_id = getCharacterDataFromElement(domain_id_e);
log.debug("Looking for links in domain: " + domain_id);
}
//System.out.println("VVV debug domain id:"+domain_id);
SimpleTEDB domainTEDB = (SimpleTEDB)TEDBs.get( domain_id);
graph = domainTEDB.getNetworkGraph();
int numLabels=0;
TE_Information tE_info_common=null;
Boolean commonBitmapLabelSet = false;
NodeList edgeCommon = element1.getElementsByTagName("edgeCommon");
int grid=0;
int cs=0;
int n=0;
for (int i = 0; i < edgeCommon.getLength(); i++) {
Element edgeCommonElement = (Element) edgeCommon.item(i);
tE_info_common =readTE_INFOfromXml(tE_info_common,edgeCommonElement, false,numLabels, grid, cs, n, 0, Integer.MAX_VALUE);
NodeList availableLabels_node = edgeCommonElement.getElementsByTagName("AvailableLabels");
for (int k = 0; k < availableLabels_node.getLength(); k++) {
Element availableLabels_e = (Element) availableLabels_node.item(k);
NodeList labelSetField_node = availableLabels_e.getElementsByTagName("LabelSetField");
Element labelSetField_el = (Element) labelSetField_node.item(0);
if (labelSetField_el.getAttributeNode("type").getValue().equals("4")){//Tengo BitMapSet
//Crear un BitMapSet
NodeList numbLabels_node = labelSetField_el.getElementsByTagName("numLabels");
Element numbLabels_e = (Element) numbLabels_node.item(0);
String numbLabels_s = getCharacterDataFromElement(numbLabels_e);
numLabels=Integer.parseInt(numbLabels_s);
NodeList baseLabel_node = labelSetField_el.getElementsByTagName("baseLabel");
Element baseLabel_e = (Element) baseLabel_node.item(0);
float min_frequency;
grid= Integer.parseInt(baseLabel_e.getAttributeNode("grid").getValue());
cs = Integer.parseInt(baseLabel_e.getAttributeNode("cs").getValue());
boolean n_frequency_included=false;
if (baseLabel_e.getAttributeNode("n") != null ){
n = Integer.parseInt(baseLabel_e.getAttributeNode("n").getValue());
n_frequency_included = true;
}
else if (baseLabel_e.getAttributeNode("min_frequency") != null){
String s_min_frequency = labelSetField_el.getAttributeNode("min_frequency").getValue();
min_frequency=Float.parseFloat(s_min_frequency);
n = ((int)min_frequency - 1471)/20;
n_frequency_included=true;
}
if (n_frequency_included){
commonBitmapLabelSet = true;
}else{
log.error("ERROR reading the xml file of the topology, you should enter <baseLabel grid=\"1\" cs=\"2\" n=\"-11\"></baseLabel> ");
}
}
}
}
/*if(isSSONnetwork ==true){
if(cs==4){
numLabels=numLabels*4;
}
else if (cs==5){
numLabels=numLabels*8;
}
}*/
NodeList edges = element_domain.getElementsByTagName("edge");
for (int i = 0; i < edges.getLength(); i++) {
log.debug("New Link");
Element element = (Element) edges.item(i);
//By default, all nodes are intradomain
String type;
Attr attr_type=element.getAttributeNode("type");
if (attr_type==null){
type="intradomain";
}else {
type=attr_type.getValue();
/*if (allDomains){
if (type.equals("interdomain")){
type="intradomain";
}
}*/
//else if (type.equals("interlayer")){
if (layer!=null && layer.equals("interlayer")){
type="intradomain";
}
//}
}
log.debug("type::"+type);
if (type.equals("intradomain")) {
IntraDomainEdge edge = new IntraDomainEdge();
NodeList source = element.getElementsByTagName("source");
Element source_router_el = (Element) source.item(0);
edge.setLearntFrom(learntFrom);
NodeList source_router_id = source_router_el.getElementsByTagName("router_id");
Element source_router_id_el = (Element) source_router_id.item(0);
String s_r_id = getCharacterDataFromElement(source_router_id_el);
s_router_id_addr= EdgeUtils.getEdge(s_r_id);
NodeList source_if_id_nl = source_router_el.getElementsByTagName("if_id");
Element source_if_id_el = (Element) source_if_id_nl.item(0);
String s_source_if_id;
int src_if_id = -1;
if (source_if_id_el!=null){
s_source_if_id = getCharacterDataFromElement(source_if_id_el);
src_if_id = Integer.parseInt(s_source_if_id);
}
log.debug("SRC if id: "+src_if_id);
NodeList source_Numif_id_nl = source_router_el.getElementsByTagName("NumIf_id");
Element source_Numif_id_el = (Element) source_Numif_id_nl.item(0);
String s_source_Numif_id;
if (source_Numif_id_el!=null){
s_source_Numif_id = getCharacterDataFromElement(source_Numif_id_el);
try { // src_Numif_id type : Inet4Address
src_Numif_id = (Inet4Address) Inet4Address.getByName(s_source_Numif_id);
} catch (Exception e) { // src_Numif_id type : DataPathID
src_Numif_id = DataPathID.getByName(s_source_Numif_id);
}
}
NodeList dest_nl = element.getElementsByTagName("destination");
Element dest_el = (Element) dest_nl.item(0);
NodeList dest_router_id_nl = dest_el.getElementsByTagName("router_id");
Element dest_router_id_el = (Element) dest_router_id_nl.item(0);
String d_r_id = getCharacterDataFromElement(dest_router_id_el);
d_router_id_addr= EdgeUtils.getEdge(d_r_id);
//Anyadimos los SID
if (SIDS.get(s_router_id_addr)!=null && SIDS.get(d_router_id_addr)!=null)
{
log.debug("setting SIDS src: "+SIDS.get(s_router_id_addr)+" dst: "+SIDS.get(d_router_id_addr));
edge.setSrc_sid(SIDS.get(s_router_id_addr));
edge.setDst_sid(SIDS.get(d_router_id_addr));
log.debug("edge.getSrc_sid(): "+edge.getSrc_sid());
log.debug("edge.getDst_sid(): "+edge.getDst_sid());
}
else if (SIDSDP.get(s_router_id_addr)!=null && SIDSDP.get(d_router_id_addr)!=null)
{
log.debug("setting SIDSDP src: "+SIDSDP.get(s_router_id_addr)+" dst: "+SIDSDP.get(d_router_id_addr));
edge.setSrc_sid(SIDSDP.get(s_router_id_addr));
edge.setDst_sid(SIDSDP.get(d_router_id_addr));
log.debug("edge.getSrc_sid(): "+edge.getSrc_sid());
log.debug("edge.getDst_sid(): "+edge.getDst_sid());
}
NodeList dest_if_id_nl = dest_el.getElementsByTagName("if_id");
Element dest_if_id_el= (Element) dest_if_id_nl.item(0);
String s_dest_if_id;
int dst_if_id = -1;
if (dest_if_id_el!=null){
s_dest_if_id = getCharacterDataFromElement(dest_if_id_el);
dst_if_id = Integer.parseInt(s_dest_if_id);
}
log.debug("DST if id: "+dst_if_id);
NodeList dest_Numif_id_nl = dest_el.getElementsByTagName("NumIf_id");
Element dest_Numif_id_el = (Element) dest_Numif_id_nl.item(0);
String s_dest_Numif_id;
if (source_Numif_id_el!=null){
s_dest_Numif_id = getCharacterDataFromElement(dest_Numif_id_el);
try { // s_dest_Numif_id type : Inet4Address
dst_Numif_id = (Inet4Address) Inet4Address.getByName(s_dest_Numif_id);
} catch (Exception e) { // s_dest_Numif_id type : DataPathID
dst_Numif_id = DataPathID.getByName(s_dest_Numif_id);
}
}
// Añadimos interfaces Numeradas
if (src_Numif_id!=null){
edge.setSrc_Numif_id(src_Numif_id);
}if (dst_Numif_id!=null){
edge.setDst_Numif_id(dst_Numif_id);
}else{
if (src_if_id != -1){
edge.setSrc_if_id(src_if_id);
}
if (dst_if_id != -1){
edge.setDst_if_id(dst_if_id);
}
}
//DELAY, IF IT COMES..
NodeList delay_ms_nl = element.getElementsByTagName("delay");
if (delay_ms_nl.getLength()>0){
Element delay_ms_el = (Element)delay_ms_nl.item(0);
String s_delay_ms=getCharacterDataFromElement(delay_ms_el);
double delay_ms=Double.parseDouble(s_delay_ms);
edge.setDelay_ms(delay_ms);
}
//TE Link information
edge.setTE_info(readTE_INFOfromXml(tE_info_common, element, commonBitmapLabelSet,numLabels, grid, cs, n,lambdaIni,lambdaEnd));
NodeList availableLabels_node = element.getElementsByTagName("AvailableLabels");
if ( availableLabels_node != null){
for (int k = 0; k < availableLabels_node.getLength(); k++) {
Element availableLabels_e = (Element) availableLabels_node.item(k);
NodeList labelSetField_node = availableLabels_e.getElementsByTagName("LabelSetField");
Element labelSetField_el = (Element) labelSetField_node.item(0);
if (labelSetField_el.getAttributeNode("type").getValue().equals("4")){//Tengo BitMapSet
NodeList numbLabels_node = labelSetField_el.getElementsByTagName("numLabels");
Element numbLabels_e = (Element) numbLabels_node.item(0);
String numbLabels_s = getCharacterDataFromElement(numbLabels_e);
numLabels=Integer.parseInt(numbLabels_s);
NodeList baseLabel_node = labelSetField_el.getElementsByTagName("baseLabel");
Element baseLabel_e = (Element) baseLabel_node.item(0);
byte[] bitmap=new byte[1];
NodeList bitmap_node = labelSetField_el.getElementsByTagName("bitmap");
int result=0;
Element bitmap_e = (Element) bitmap_node.item(0);
if (bitmap_e!=null){
String bitmap_string=getCharacterDataFromElement(bitmap_e);
System.out.println("Bitmap read: "+bitmap_string);
for (int p =0; p<bitmap_string.length(); p++)
result= (int) (result+Math.pow(2, bitmap_string.length()-p-1)*(bitmap_string.charAt(p)-48));
bitmap[0]=(byte) result;
((BitmapLabelSet)edge.getTE_info().getAvailableLabels().getLabelSet()).setBytesBitmap(bitmap);
}
float min_frequency;
grid= Integer.parseInt(baseLabel_e.getAttributeNode("grid").getValue());
cs = Integer.parseInt(baseLabel_e.getAttributeNode("cs").getValue());
boolean n_frequency_included=false;
if (baseLabel_e.getAttributeNode("n") != null ){
n = Integer.parseInt(baseLabel_e.getAttributeNode("n").getValue());
n_frequency_included = true;
}
else if (baseLabel_e.getAttributeNode("min_frequency") != null){
String s_min_frequency = labelSetField_el.getAttributeNode("min_frequency").getValue();
min_frequency=Float.parseFloat(s_min_frequency);
n = ((int)min_frequency - 1471)/20;
n_frequency_included=true;
}
if (n_frequency_included){/*Modify availableLabels*/
((BitmapLabelSet)edge.getTE_info().getAvailableLabels().getLabelSet()).setNumLabels(numLabels);
((BitmapLabelSet)edge.getTE_info().getAvailableLabels().getLabelSet()).getDwdmWavelengthLabel().setGrid(grid);
((BitmapLabelSet)edge.getTE_info().getAvailableLabels().getLabelSet()).getDwdmWavelengthLabel().setChannelSpacing(cs);
((BitmapLabelSet)edge.getTE_info().getAvailableLabels().getLabelSet()).getDwdmWavelengthLabel().setN(n);
}
else{
log.error("ERROR reading the xml file of the topology, you should enter <baseLabel grid=\"1\" cs=\"2\" n=\"-11\"></baseLabel> ");
}
}
}
}
log.debug("Preparing to add edge");
log.debug("NODES IN GRAPH:: "+graph.vertexSet());
try{
if(graph.containsEdge(s_router_id_addr, d_router_id_addr)){
log.debug("New Intradomain Edge");
graph.getEdge(s_router_id_addr, d_router_id_addr).setNumberFibers(graph.getEdge(s_router_id_addr, d_router_id_addr).getNumberFibers()+1);
log.debug("s_router_id_addr: "+s_router_id_addr.toString()+"; d_router_id_addr: "+d_router_id_addr.toString()+"; edge: "+edge);
log.info("New intradomain link: "+s_router_id_addr.toString()+" --> "+d_router_id_addr.toString());//+" \n "+edge);
}else{
log.debug("s_router_id_addr: "+s_router_id_addr.toString()+"; d_router_id_addr: "+d_router_id_addr.toString()+"; edge: "+edge);
if(graph.containsVertex(d_router_id_addr)==false){
//interDomain edge
//TODO
type="interdomain";
}else{
graph.addEdge(s_router_id_addr, d_router_id_addr, edge);
graph.getEdge(s_router_id_addr, d_router_id_addr).setNumberFibers(1);
log.debug("New Intradomain Edge");
log.info("New intradomain link: "+s_router_id_addr.toString()+" --> "+d_router_id_addr.toString()+" learnt "+edge.getLearntFrom());//+" \n "+edge);
}
}
}catch(Exception e){
log.error("Problem with source "+s_router_id_addr+" destination "+d_router_id_addr);
e.printStackTrace();
System.exit(-1);
}
}
if(type.equals("interdomain")){
log.debug("New Interdomain Edge");
InterDomainEdge edge = new InterDomainEdge();
TE_Information tE_info=readTE_INFOfromXml(tE_info_common,element, false,numLabels, grid, cs, n, 0, Integer.MAX_VALUE);
edge.setTE_info(tE_info);
edge.setLearntFrom(learntFrom);
NodeList source = element.getElementsByTagName("source");
Element source_router_el = (Element) source.item(0);
NodeList source_router_id = source_router_el
.getElementsByTagName("router_id");
Element source_router_id_el = (Element) source_router_id
.item(0);
String s_r_id = getCharacterDataFromElement(source_router_id_el);
log.debug("Edge Source router_id: " + s_r_id);
try { // s_router_id_addr type: Inet4Address
s_router_id_addr = (Inet4Address) Inet4Address.getByName(s_r_id);
} catch (Exception e) {// s_router_id_addr type: DataPathID
s_router_id_addr = DataPathID.getByName(s_r_id);
}
Inet4Address source_domain_id = (Inet4Address) Inet4Address.getByName(domain_id);
log.debug("Edge Source domain_id: " + source_domain_id);
NodeList source_if_id_nl = source_router_el
.getElementsByTagName("if_id");
Element source_if_id_el = (Element) source_if_id_nl.item(0);
String s_source_if_id = getCharacterDataFromElement(source_if_id_el);
log.debug("Edge Source if_id: " + s_source_if_id);
int src_if_id = Integer.parseInt(s_source_if_id);
NodeList dest_nl = element.getElementsByTagName("destination");
Element dest_el = (Element) dest_nl.item(0);
NodeList dest_router_id_nl = dest_el
.getElementsByTagName("router_id");
Element dest_router_id_el = (Element) dest_router_id_nl.item(0);
String d_r_id = getCharacterDataFromElement(dest_router_id_el);
log.debug("Edge Destination router_id: " + d_r_id);
try { // d_router_id_addr type: Inet4Address
d_router_id_addr = (Inet4Address) Inet4Address.getByName(d_r_id);
} catch (Exception e) { // d_router_id_addr type: DataPathID
d_router_id_addr = DataPathID.getByName(d_r_id);
}
//Inet4Address dest_domain_id = router_id_domain_ed.get(d_router_id_addr);
log.debug("Destination domain_id: <Unknown>");
NodeList dest_if_id_nl = dest_el.getElementsByTagName("if_id");
Element dest_if_id_el = (Element) dest_if_id_nl.item(0);
String s_dest_if_id = getCharacterDataFromElement(dest_if_id_el);
log.debug("Edge Dest if_id: " + s_dest_if_id);
int dst_if_id = Integer.parseInt(s_dest_if_id);
//router_id_domain_ed
//edge.setDomain_src_router(source_domain_id);
edge.setSrc_if_id(src_if_id);
edge.setDst_if_id(dst_if_id);
edge.setDomain_src_router(source_domain_id);
//edge.setDomain_dst_router(dest_domain_id);
edge.setSrc_router_id(s_router_id_addr);
edge.setDst_router_id(d_router_id_addr);
if(domainTEDB.getInterDomainLinks()==null){
LinkedList<InterDomainEdge> interDomainLinks= new LinkedList<InterDomainEdge>();
interDomainLinks.add(edge);
domainTEDB.setInterDomainLinks(interDomainLinks);
log.info("New interdomain link: "+s_router_id_addr.toString()+" --> "+d_router_id_addr.toString()+" learnt "+edge.getLearntFrom());//+"; \n "+edge);
}else{
domainTEDB.getInterDomainLinks().add(edge);
log.info("New interdomain link: "+s_router_id_addr.toString()+" --> "+d_router_id_addr.toString()+" learnt "+edge.getLearntFrom());//+"; \n "+edge);
}
}
}
}
log.debug("Info graph edge :: "+graph.edgeSet());
}
} catch (Exception e) {
e.printStackTrace();
}
return TEDBs;
}
private static TE_Information readTE_INFOfromXml(TE_Information tE_info_common,Element element, Boolean commonBitmapLabelSet, int numLabels, int grid, int cs, int n, int lambdaIni, int lambdaEnd) {
TE_Information tE_info= new TE_Information();
if (commonBitmapLabelSet){
if(lambdaEnd!=Integer.MAX_VALUE)
tE_info.createBitmapLabelSet(numLabels, grid, cs, n,lambdaIni,lambdaEnd);
else
tE_info.createBitmapLabelSet(numLabels, grid, cs, n);
}
NodeList maximum_bandwidth_nl = element.getElementsByTagName("maximum_bandwidth");
if (maximum_bandwidth_nl!=null){
if (maximum_bandwidth_nl.getLength()>0){
Element maximum_bandwidth_el = (Element) maximum_bandwidth_nl.item(0);
String s_maximum_bandwidth = getCharacterDataFromElement(maximum_bandwidth_el);
float maximum_bandwidth=Float.parseFloat(s_maximum_bandwidth);
MaximumBandwidth maximumBandwidth =new MaximumBandwidth();
maximumBandwidth.setMaximumBandwidth(maximum_bandwidth);
tE_info.setMaximumBandwidth(maximumBandwidth);
}
}else if(tE_info_common!=null && tE_info_common.getMaximumBandwidth()!=null){
MaximumBandwidth maximumBandwidth =new MaximumBandwidth();
maximumBandwidth.setMaximumBandwidth(tE_info_common.getMaximumBandwidth().getMaximumBandwidth());
tE_info.setMaximumBandwidth(maximumBandwidth);
}
/**
* NodeList SID_aux = element.getElementsByTagName("sid");
Element SID_e = (Element) SID_aux.item(0);
if (SID_e!=null)
{
log.info("SID existe");
int SID = Integer.parseInt(getCharacterDataFromElement(SID_e));
SIDS.put(router_id_addr,SID);
log.info("SID of node: "+SID);
}
else
{
log.info("SID not found");
}
*/
NodeList defaultmetric = element.getElementsByTagName("default_te_metric");
Element metric_aux = (Element) defaultmetric.item(0);
if (metric_aux != null){
String s_metric_aux = getCharacterDataFromElement(metric_aux);
int metric = Integer.parseInt(s_metric_aux);
DefaultTEMetricLinkAttribTLV defaultTeMetric= new DefaultTEMetricLinkAttribTLV();
defaultTeMetric.setLinkMetric((long)metric);
tE_info.setDefaultTEMetric(defaultTeMetric);
}else if(tE_info_common!=null && tE_info_common.getDefaultTEMetric()!=null){
DefaultTEMetricLinkAttribTLV defaultTeMetric= new DefaultTEMetricLinkAttribTLV();
defaultTeMetric.setLinkMetric(tE_info_common.getDefaultTEMetric().getLinkMetric());
tE_info.setDefaultTEMetric(defaultTeMetric);
}
NodeList unreserved_bandwidth_nl = element.getElementsByTagName("unreserved_bandwidth");
if (unreserved_bandwidth_nl!=null){
int num_u_b=unreserved_bandwidth_nl.getLength();
UnreservedBandwidth unreservedBandwidth;
if (num_u_b>0){
unreservedBandwidth =new UnreservedBandwidth();
tE_info.setUnreservedBandwidth(unreservedBandwidth);
for(int k=0;k<num_u_b;++k){
Element unreserved_bandwidth_el = (Element) unreserved_bandwidth_nl.item(k);
String s_unreserved_bandwidth = getCharacterDataFromElement(unreserved_bandwidth_el);
String s_priority=unreserved_bandwidth_el.getAttributeNode("priority").getValue();
Integer priority = Integer.valueOf(s_priority);
float unreserved_bandwidth=Float.parseFloat(s_unreserved_bandwidth);
(unreservedBandwidth.getUnreservedBandwidth())[priority]=unreserved_bandwidth;
}
}
}
NodeList maximum_wlans_nl = element.getElementsByTagName("number_wlans");
if (maximum_wlans_nl!=null){
if (maximum_wlans_nl.getLength()>0){
Element number_wlan_el = (Element) maximum_wlans_nl.item(0);
String s_number_wlans = getCharacterDataFromElement(number_wlan_el);
int number_wlans=Integer.parseInt(s_number_wlans.replace("\n", "").replaceAll("\\s",""));
tE_info.setNumberWLANs(number_wlans);
tE_info.initWLANs();
}
}
NodeList undirDelayLinks = element.getElementsByTagName("undir_delay_link");
Element undirDelayLink = (Element) undirDelayLinks.item(0);
if (undirDelayLink != null){
String s_undirDelayLink = getCharacterDataFromElement(undirDelayLink);
int undirDelayLinkValue = Integer.parseInt(s_undirDelayLink);
UndirectionalLinkDelayDescriptorSubTLV uldSTLV = new UndirectionalLinkDelayDescriptorSubTLV();
uldSTLV.setDelay(undirDelayLinkValue);
tE_info.setUndirLinkDelay(uldSTLV);
}else if(tE_info_common!=null && tE_info_common.getUndirLinkDelay()!=null){
UndirectionalLinkDelayDescriptorSubTLV uldSTLV = new UndirectionalLinkDelayDescriptorSubTLV();
uldSTLV.setDelay(tE_info_common.getUndirLinkDelay().getDelay());
tE_info.setUndirLinkDelay(uldSTLV);
}
NodeList undirDelayVars = element.getElementsByTagName("undir_delay_variation");
Element undirDelayVar = (Element) undirDelayVars.item(0);
if (undirDelayVar != null){
String s_undirDelayVar = getCharacterDataFromElement(undirDelayVar);
int undirDelayVarValue = Integer.parseInt(s_undirDelayVar);
UndirectionalDelayVariationDescriptorSubTLV udvSTLV = new UndirectionalDelayVariationDescriptorSubTLV();
udvSTLV.setDelayVar(undirDelayVarValue);
tE_info.setUndirDelayVar(udvSTLV);
}else if(tE_info_common!=null && tE_info_common.getUndirDelayVar()!=null){
UndirectionalDelayVariationDescriptorSubTLV uldSTLV = new UndirectionalDelayVariationDescriptorSubTLV();
uldSTLV.setDelayVar(tE_info_common.getUndirDelayVar().getDelayVar());
tE_info.setUndirDelayVar(uldSTLV);
}
NodeList undirLinkLosss = element.getElementsByTagName("undir_link_loss");
Element undirLinkLoss = (Element) undirLinkLosss.item(0);
if (undirLinkLoss != null){
String s_undirLinkLoss = getCharacterDataFromElement(undirLinkLoss);
int undirLinkLossValue = Integer.parseInt(s_undirLinkLoss);
UndirectionalLinkLossDescriptorSubTLV uSTLV = new UndirectionalLinkLossDescriptorSubTLV();
uSTLV.setLinkLoss(undirLinkLossValue);
tE_info.setUndirLinkLoss(uSTLV);
}else if(tE_info_common!=null && tE_info_common.getUndirLinkLoss()!=null){
UndirectionalLinkLossDescriptorSubTLV uldSTLV = new UndirectionalLinkLossDescriptorSubTLV();
uldSTLV.setLinkLoss(tE_info_common.getUndirLinkLoss().getLinkLoss());
tE_info.setUndirLinkLoss(uldSTLV);
}
NodeList undirReBws = element.getElementsByTagName("undir_residual_bandwidth");
Element undirReBw = (Element) undirReBws.item(0);
if (undirReBw != null){
String s_undirReBw = getCharacterDataFromElement(undirReBw);
int undirReBwValue = Integer.parseInt(s_undirReBw);
UndirectionalResidualBandwidthDescriptorSubTLV uSTLV = new UndirectionalResidualBandwidthDescriptorSubTLV();
uSTLV.setResidualBw(undirReBwValue);
tE_info.setUndirResidualBw(uSTLV);
}else if(tE_info_common!=null && tE_info_common.getUndirResidualBw()!=null){
UndirectionalResidualBandwidthDescriptorSubTLV uldSTLV = new UndirectionalResidualBandwidthDescriptorSubTLV();
uldSTLV.setResidualBw( tE_info_common.getUndirResidualBw().getResidualBw());
tE_info.setUndirResidualBw(uldSTLV);
}
NodeList undirAvalBws = element.getElementsByTagName("undir_available_bandwidth");
Element undirAvalBw = (Element) undirAvalBws.item(0);
if (undirAvalBw != null){
String s_undirAvalBw = getCharacterDataFromElement(undirAvalBw);
int undirAvalBwValue = Integer.parseInt(s_undirAvalBw);
UndirectionalAvailableBandwidthDescriptorSubTLV uSTLV = new UndirectionalAvailableBandwidthDescriptorSubTLV();
uSTLV.setAvailableBw(undirAvalBwValue);
tE_info.setUndirAvailableBw(uSTLV);
}else if(tE_info_common!=null && tE_info_common.getUndirAvailableBw()!=null){
UndirectionalAvailableBandwidthDescriptorSubTLV uldSTLV = new UndirectionalAvailableBandwidthDescriptorSubTLV();
uldSTLV.setAvailableBw( tE_info_common.getUndirAvailableBw().getAvailableBw());
tE_info.setUndirAvailableBw(uldSTLV);
}
NodeList undirUtilBws = element.getElementsByTagName("undir_utilized_bandwidth");
Element undirUtilBw = (Element) undirUtilBws.item(0);
if (undirUtilBw != null){
String s_undirUtilBw = getCharacterDataFromElement(undirUtilBw);
int undirUtilBwValue = Integer.parseInt(s_undirUtilBw);
UndirectionalUtilizedBandwidthDescriptorSubTLV uSTLV = new UndirectionalUtilizedBandwidthDescriptorSubTLV();
uSTLV.setUtilizedBw(undirUtilBwValue);
tE_info.setUndirUtilizedBw(uSTLV);
}else if(tE_info_common!=null && tE_info_common.getUndirUtilizedBw()!=null){
UndirectionalUtilizedBandwidthDescriptorSubTLV uldSTLV = new UndirectionalUtilizedBandwidthDescriptorSubTLV();
uldSTLV.setUtilizedBw( tE_info_common.getUndirUtilizedBw().getUtilizedBw());
tE_info.setUndirUtilizedBw(uldSTLV);
}
NodeList minMaxDelays = element.getElementsByTagName("undir_min_max_delay");
Element minMaxDelay = (Element) minMaxDelays.item(0);
if (minMaxDelay != null){
NodeList minDelays = minMaxDelay.getElementsByTagName("min");
Element minDelay = (Element) minDelays.item(0);
NodeList maxDelays = minMaxDelay.getElementsByTagName("max");
Element maxDelay = (Element) maxDelays.item(0);
if(minDelay !=null && maxDelay!=null){
String s_minDelay = getCharacterDataFromElement(minDelay);
String s_maxDelay = getCharacterDataFromElement(maxDelay);
int minDelayValue = Integer.parseInt(s_minDelay);
int maxDelayValue = Integer.parseInt(s_maxDelay);
MinMaxUndirectionalLinkDelayDescriptorSubTLV ummSTLV = new MinMaxUndirectionalLinkDelayDescriptorSubTLV();
ummSTLV.setHighDelay(maxDelayValue);
ummSTLV.setLowDelay(minDelayValue);
tE_info.setMinMaxUndirLinkDelay(ummSTLV);
}
}else if(tE_info_common!=null && tE_info_common.getMinMaxUndirLinkDelay()!=null){
MinMaxUndirectionalLinkDelayDescriptorSubTLV uldSTLV = new MinMaxUndirectionalLinkDelayDescriptorSubTLV();
uldSTLV.setHighDelay( tE_info_common.getMinMaxUndirLinkDelay().getHighDelay());
uldSTLV.setLowDelay( tE_info_common.getMinMaxUndirLinkDelay().getLowDelay());
tE_info.setMinMaxUndirLinkDelay(uldSTLV);
}
return tE_info;
}
public static SimpleDirectedWeightedGraph<Object,IntraDomainEdge> readITNetwork(String fileName){
Logger log=LoggerFactory.getLogger("BGP4Peer");
SimpleDirectedWeightedGraph<Object,IntraDomainEdge> graph =new SimpleDirectedWeightedGraph<Object,IntraDomainEdge>(IntraDomainEdge.class);
Object router_id_addr = null;
Object it_site_id_addr = null;
Object resource_addr = null;
Object s_id_addr = null;
Object d_id_addr = null;
Object s_router_id_addr = null;
Object d_router_id_addr = null;
Object s_it_site_id_addr = null;
Object d_it_site_id_addr = null;
Object s_resource_id_addr = null;
Object d_resource_id_addr = null;
log.debug("2. SimpleDirectedWeightedGraph");
File file = new File(fileName);
try {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(file);
NodeList nodes_domains = doc.getElementsByTagName("domain");
HashMap<Inet4Address, Integer >SIDS = new HashMap<Inet4Address,Integer>();
HashMap<DataPathID, Integer >SIDSDP = new HashMap<DataPathID,Integer>();
for (int j = 0; j < nodes_domains.getLength(); j++) {
Element element_domain = (Element) nodes_domains.item(j);
NodeList nodes_domain_id = element_domain.getElementsByTagName("domain_id");
for (int k = 0; k < nodes_domain_id.getLength(); k++) {
Element domain_id_e = (Element) nodes_domain_id.item(0);
String domain_id=getCharacterDataFromElement(domain_id_e);
log.debug("Network domain: "+domain_id);
}
NodeList nodes = doc.getElementsByTagName("node");
for (int i = 0; i < nodes.getLength(); i++) {
Element element = (Element) nodes.item(i);
NodeList router_id_node = element.getElementsByTagName("router_id");
Element router_id_e = (Element) router_id_node.item(0);
String router_id=getCharacterDataFromElement(router_id_e);
log.debug("El router_id es "+router_id);
try { // router_id_addr type: Inet4Address
router_id_addr = (Inet4Address) Inet4Address.getByName(router_id);
} catch (Exception e) { // router_id_addr type: DataPathID
router_id_addr = DataPathID.getByName(router_id);
}
graph.addVertex(router_id_addr);
Element SID_e = (Element) element.getElementsByTagName("sid");
if (SID_e!=null)
{ int SID = Integer.parseInt(getCharacterDataFromElement(SID_e));
try { // router_id_addr type: Inet4Address
SIDS.put((Inet4Address)router_id_addr,SID);
} catch (Exception e) { // router_id_addr type: DataPathID
SIDSDP.put((DataPathID)router_id_addr,SID);
}
}
}
NodeList it_sites = doc.getElementsByTagName("it_site");
for (int i = 0; i < it_sites.getLength(); i++) {
Element element = (Element) it_sites.item(i);
NodeList it_site_id_node = element.getElementsByTagName("it_site_id");
Element it_site_id_e = (Element) it_site_id_node.item(0);
String it_site_id=getCharacterDataFromElement(it_site_id_e);
log.debug("El IT_site_id es "+it_site_id);
try { // it_site_id_addr type: Inet4Address
it_site_id_addr = (Inet4Address) Inet4Address.getByName(it_site_id);
} catch (Exception e) { // it_site_id_addr type: DataPathID
it_site_id_addr = DataPathID.getByName(it_site_id);
}
graph.addVertex(it_site_id_addr);
}
NodeList storages = doc.getElementsByTagName("storage");
for (int i = 0; i < storages.getLength(); i++) {
Element element = (Element) storages.item(i);
NodeList resource_id_node = element.getElementsByTagName("resource_id");
Element resource_id_e = (Element) resource_id_node.item(0);
String resource_id=getCharacterDataFromElement(resource_id_e);
log.debug("El resource_id es "+resource_id);
try {
resource_addr = (Inet4Address) Inet4Address.getByName(resource_id);
} catch (Exception e) {
resource_addr = DataPathID.getByName(resource_id);
}
graph.addVertex(resource_addr);
}
NodeList edges = doc.getElementsByTagName("edge");
for (int i = 0; i < edges.getLength(); i++) {
Element element = (Element) edges.item(i);
// We only want those routers which have type="intradomain" //MARTA
if (element.getAttributeNode("type").getValue().equals("intradomain")) {//MARTA
//IntraDomainEdge edge = new IntraDomainEdge();
IntraDomainEdge edge = new IntraDomainEdge();
NodeList source = element.getElementsByTagName("source");
Element source_router_el = (Element)source.item(0);
NodeList source_router_id= source_router_el.getElementsByTagName("router_id");
if (source_router_id.getLength()>0){
Element source_router_id_el=(Element)source_router_id.item(0);
String s_r_id=getCharacterDataFromElement(source_router_id_el);
try { // s_router_id_addr type: Inet4Address
s_router_id_addr = (Inet4Address) Inet4Address.getByName(s_r_id);
} catch (Exception e) { // s_router_id_addr type: DataPathID
s_router_id_addr = DataPathID.getByName(s_r_id);
}
s_id_addr=s_router_id_addr;
}
NodeList source_it_site_id= source_router_el.getElementsByTagName("it_site_id");
if (source_it_site_id.getLength()>0){
Element source_it_site_id_el=(Element)source_it_site_id.item(0);
String s_itsite_id=getCharacterDataFromElement(source_it_site_id_el);
log.debug("Edge Source IT_site_id: "+s_itsite_id);
try { // s_it_site_id_addr type: Inet4Address
s_it_site_id_addr = (Inet4Address) Inet4Address.getByName(s_itsite_id);
} catch (Exception e) { // s_it_site_id_addr type: DataPathID
s_it_site_id_addr = DataPathID.getByName(s_itsite_id);
}
s_id_addr=s_it_site_id_addr;
}
NodeList source_resource_id= source_router_el.getElementsByTagName("resource_id");
if (source_resource_id.getLength()>0){
Element source_resource_id_el=(Element)source_resource_id.item(0);
String s_resource_id=getCharacterDataFromElement(source_resource_id_el);
log.debug("Edge Source resource_id: "+s_resource_id);
try {// s_resource_id_addr type: Inet4Address
s_resource_id_addr = (Inet4Address) Inet4Address.getByName(s_resource_id);
} catch (Exception e) { // s_resource_id_addr type: DataPathID
s_resource_id_addr = DataPathID.getByName(s_resource_id);
}
s_id_addr=s_resource_id_addr;
}
NodeList source_if_id_nl= source_router_el.getElementsByTagName("if_id");
Element source_if_id_el=(Element)source_if_id_nl.item(0);
String s_source_if_id=getCharacterDataFromElement(source_if_id_el);
log.debug("Edge Source if_id: "+s_source_if_id);
int src_if_id=Integer.parseInt(s_source_if_id);
NodeList dest_nl = element.getElementsByTagName("destination");
Element dest_el = (Element)dest_nl.item(0);
NodeList dest_router_id_nl= dest_el.getElementsByTagName("router_id");
if (dest_router_id_nl.getLength()>0){
Element dest_router_id_el=(Element)dest_router_id_nl.item(0);
String d_r_id=getCharacterDataFromElement(dest_router_id_el);
log.debug("Edge Destination router_id: "+d_r_id);
try { // d_router_id_addr type: Inet4Address
d_router_id_addr = (Inet4Address) Inet4Address.getByName(d_r_id);
} catch (Exception e) { // d_router_id_addr type: DataPathID
d_router_id_addr = DataPathID.getByName(d_r_id);
}
d_id_addr=d_router_id_addr;
}
NodeList dest_it_site_id_nl= dest_el.getElementsByTagName("it_site_id");
if (dest_it_site_id_nl.getLength()>0){
Element dest_it_site_id_el=(Element)dest_it_site_id_nl.item(0);
String d_it_site_id=getCharacterDataFromElement(dest_it_site_id_el);
log.debug("Edge Destination IT_site_id: "+d_it_site_id);
try { // d_it_site_id_addr type: Inet4Address
d_it_site_id_addr = (Inet4Address) Inet4Address.getByName(d_it_site_id);
} catch (Exception e) { // d_it_site_id_addr type: DataPathID
d_it_site_id_addr = DataPathID.getByName(d_it_site_id);
}
d_id_addr=d_it_site_id_addr;
}
NodeList dest_resource_id_nl= dest_el.getElementsByTagName("resource_id");
if (dest_resource_id_nl.getLength()>0){
Element dest_resource_id_el=(Element)dest_resource_id_nl.item(0);
String d_resource_id=getCharacterDataFromElement(dest_resource_id_el);
log.debug("Edge Destination resource_id: "+d_resource_id);
try { // d_resource_id_addr type: Inet4Address
d_resource_id_addr = (Inet4Address) Inet4Address.getByName(d_resource_id);
} catch (Exception e) { // d_resource_id_addr type: DataPathID
d_resource_id_addr = DataPathID.getByName(d_resource_id);
}
d_id_addr=d_resource_id_addr;
}
NodeList dest_if_id_nl= dest_el.getElementsByTagName("if_id");
Element dest_if_id_el=(Element)dest_if_id_nl.item(0);
String s_dest_if_id=getCharacterDataFromElement(dest_if_id_el);
log.debug("Edge Dest if_id: "+s_dest_if_id);
int dst_if_id=Integer.parseInt(s_dest_if_id);
edge.setSrc_if_id(src_if_id);
edge.setDst_if_id(dst_if_id);
//TODO: Tal vez pete aqui
//Anyadimos los SID
if (SIDS.get(s_id_addr)!=null && SIDS.get(d_id_addr)!=null)
{
edge.setSrc_sid(SIDS.get(s_id_addr));
edge.setSrc_sid(SIDS.get(d_id_addr));
}
graph.addEdge(s_id_addr, d_id_addr,edge);
}//MARTA
}
}
}
catch (Exception e) {
e.printStackTrace();
}
return graph;
}
public static Inet4Address readNetworkDomain(String fileName) {
Logger log = LoggerFactory.getLogger("BGP4Peer");
File file = new File(fileName);
try {
DocumentBuilder builder = DocumentBuilderFactory.newInstance()
.newDocumentBuilder();
Document doc = builder.parse(file);
NodeList nodes_domains = doc.getElementsByTagName("domain");
Element element_domain = (Element) nodes_domains.item(0);
NodeList nodes_domain_id = element_domain.getElementsByTagName("domain_id");
Element domain_id_e = (Element) nodes_domain_id.item(0);
String domain_id = getCharacterDataFromElement(domain_id_e);
log.info("Network domain: " + domain_id);
Inet4Address domId = (Inet4Address) Inet4Address
.getByName(domain_id);
return domId;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static String getCharacterDataFromElement(Element e) {
Node child = e.getFirstChild();
if (child instanceof CharacterData) {
CharacterData cd = (CharacterData) child;
return cd.getData();
} else {
return "?";
}
}
/**
* Reads the inter-domain Topology from a topology XML file.
* Needs update to work with datapath IDs.
* @param fileName Name of the XML
* @return Graph of the network.
*/
public static DirectedWeightedMultigraph<Object, InterDomainEdge> readMDNetwork(
String fileName) {
Logger log = LoggerFactory.getLogger("BGP4Peer");
DirectedWeightedMultigraph<Object, InterDomainEdge> graph = new DirectedWeightedMultigraph<Object, InterDomainEdge>(
InterDomainEdge.class);
Hashtable<Object, Inet4Address> router_id_domain_ed = new Hashtable<Object, Inet4Address>();
Hashtable<Object, DataPathID> router_id_domain_ed_dp = new Hashtable<Object, DataPathID>();
HashMap<Inet4Address, Integer >SIDS = new HashMap<Inet4Address,Integer>();
HashMap<DataPathID, Integer >SIDSDP = new HashMap<DataPathID,Integer>();
Object router_id_addr = null;
Object s_router_id_addr = null;
Object d_router_id_addr = null;
File file = new File(fileName);
try {
DocumentBuilder builder = DocumentBuilderFactory.newInstance()
.newDocumentBuilder();
Document doc = builder.parse(file);
NodeList nodes_domains = doc.getElementsByTagName("domain");
// First pass to read all the nodes and domains
log.info("Multidomain Graph");
for (int j = 0; j < nodes_domains.getLength(); j++) {
Element element_domain = (Element) nodes_domains.item(j);
NodeList nodes_domain_id = element_domain
.getElementsByTagName("domain_id");
Element domain_id_e = (Element) nodes_domain_id.item(0);
String domain_id_str = getCharacterDataFromElement(domain_id_e);
Inet4Address domain_id = (Inet4Address) Inet4Address
.getByName(domain_id_str);
log.info("Adding Domain: " + domain_id);
graph.addVertex(domain_id);
NodeList nodes = element_domain.getElementsByTagName("node");
for (int i = 0; i < nodes.getLength(); i++) {
Element element = (Element) nodes.item(i);
NodeList router_id_node = element
.getElementsByTagName("router_id");
Element router_id_e = (Element) router_id_node.item(0);
String router_id = getCharacterDataFromElement(router_id_e);
log.debug("Router_id: " + router_id);
try { // router_id_addr type: Inet4Address
router_id_addr = (Inet4Address) Inet4Address.getByName(router_id);
} catch (Exception e) { // router_id_addr type: DataPathID
router_id_addr = DataPathID.getByName(router_id);
}
router_id_domain_ed.put(router_id_addr, domain_id);
NodeList nl_sid=element.getElementsByTagName("sid");
Element SID_e = (Element) nl_sid.item(0);
if (SID_e!=null)
{ int SID = Integer.parseInt(getCharacterDataFromElement(SID_e));
try {
SIDS.put((Inet4Address)router_id_addr,SID);
} catch (Exception e) {
SIDSDP.put((DataPathID)router_id_addr,SID);
}
}
}
}
log.debug("Domain_ids read");
int numLabels=0;
Boolean commonBitmapLabelSet = false;
NodeList edgeCommon = doc.getElementsByTagName("edgeCommon");
int grid=0;
int cs=0;
int n=0;
for (int i = 0; i < edgeCommon.getLength(); i++) {
Element edgeCommonElement = (Element) edgeCommon.item(i);
NodeList availableLabels_node = edgeCommonElement.getElementsByTagName("AvailableLabels");
for (int k = 0; k < availableLabels_node.getLength(); k++) {
Element availableLabels_e = (Element) availableLabels_node.item(k);
NodeList labelSetField_node = availableLabels_e.getElementsByTagName("LabelSetField");
Element labelSetField_el = (Element) labelSetField_node.item(0);
if (labelSetField_el.getAttributeNode("type").getValue().equals("4")){//Tengo BitMapSet
//Crear un BitMapSet
NodeList numbLabels_node = labelSetField_el.getElementsByTagName("numLabels");
Element numbLabels_e = (Element) numbLabels_node.item(0);
String numbLabels_s = getCharacterDataFromElement(numbLabels_e);
numLabels=Integer.parseInt(numbLabels_s);
NodeList baseLabel_node = labelSetField_el.getElementsByTagName("baseLabel");
Element baseLabel_e = (Element) baseLabel_node.item(0);
float min_frequency;
grid= Integer.parseInt(baseLabel_e.getAttributeNode("grid").getValue());
cs = Integer.parseInt(baseLabel_e.getAttributeNode("cs").getValue());
boolean n_frequency_included=false;
if (baseLabel_e.getAttributeNode("n") != null ){
n = Integer.parseInt(baseLabel_e.getAttributeNode("n").getValue());
n_frequency_included = true;
}
else if (baseLabel_e.getAttributeNode("min_frequency") != null){
String s_min_frequency = labelSetField_el.getAttributeNode("min_frequency").getValue();
min_frequency=Float.parseFloat(s_min_frequency);
n = ((int)min_frequency - 1471)/20;
n_frequency_included=true;
}
if (n_frequency_included){
commonBitmapLabelSet = true;
}else{
log.error("ERROR reading the xml file of the topology, you should enter <baseLabel grid=\"1\" cs=\"2\" n=\"-11\"></baseLabel> ");
}
}
}
}
NodeList edges = doc.getElementsByTagName("edge");
boolean a =true;
for (int i = 0; i < edges.getLength(); i++) {
log.debug("Looking at edge");
Element element = (Element) edges.item(i);
InterDomainEdge edge = new InterDomainEdge();
TE_Information tE_info=readTE_INFOfromXml(null, element, false,numLabels, grid, cs, n, 0, Integer.MAX_VALUE);
edge.setTE_info(tE_info);
NodeList source = element.getElementsByTagName("source");
Element source_router_el = (Element) source.item(0);
NodeList source_router_id = source_router_el
.getElementsByTagName("router_id");
Element source_router_id_el = (Element) source_router_id
.item(0);
String s_r_id = getCharacterDataFromElement(source_router_id_el);
log.debug("Edge Source router_id: " + s_r_id);
try { // s_router_id_addr type: Inet4Address
s_router_id_addr = (Inet4Address) Inet4Address.getByName(s_r_id);
} catch (Exception e) {// s_router_id_addr type: DataPathID
s_router_id_addr = DataPathID.getByName(s_r_id);
}
Inet4Address source_domain_id = router_id_domain_ed.get(s_router_id_addr);
log.debug("Edge Source domain_id: " + source_domain_id);
NodeList source_if_id_nl = source_router_el
.getElementsByTagName("if_id");
Element source_if_id_el = (Element) source_if_id_nl.item(0);
String s_source_if_id = getCharacterDataFromElement(source_if_id_el);
log.debug("Edge Source if_id: " + s_source_if_id);
int src_if_id = Integer.parseInt(s_source_if_id);
NodeList dest_nl = element.getElementsByTagName("destination");
Element dest_el = (Element) dest_nl.item(0);
NodeList dest_router_id_nl = dest_el
.getElementsByTagName("router_id");
Element dest_router_id_el = (Element) dest_router_id_nl.item(0);
String d_r_id = getCharacterDataFromElement(dest_router_id_el);
log.debug("Edge Destination router_id: " + d_r_id);
try { // d_router_id_addr type: Inet4Address
d_router_id_addr = (Inet4Address) Inet4Address.getByName(d_r_id);
} catch (Exception e) { // d_router_id_addr type: DataPathID
d_router_id_addr = DataPathID.getByName(d_r_id);
}
Inet4Address dest_domain_id = router_id_domain_ed.get(d_router_id_addr);
log.debug("Destination domain_id: " + dest_domain_id);
NodeList dest_if_id_nl = dest_el.getElementsByTagName("if_id");
Element dest_if_id_el = (Element) dest_if_id_nl.item(0);
String s_dest_if_id = getCharacterDataFromElement(dest_if_id_el);
log.debug("Edge Dest if_id: " + s_dest_if_id);
int dst_if_id = Integer.parseInt(s_dest_if_id);
//router_id_domain_ed
//edge.setDomain_src_router(source_domain_id);
edge.setSrc_if_id(src_if_id);
edge.setDst_if_id(dst_if_id);
edge.setDomain_src_router(source_domain_id);
edge.setDomain_dst_router(dest_domain_id);
edge.setSrc_router_id(s_router_id_addr);
edge.setDst_router_id(d_router_id_addr);
if (!source_domain_id.equals(dest_domain_id)) {
log.info("Adding interdomain link "+source_domain_id.toString()+"-->"+dest_domain_id.toString());//edge.toString());
//Only add if the source and destination domains are different
graph.addEdge(source_domain_id, dest_domain_id, edge);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return graph;
}
public static DirectedWeightedMultigraph<Object, InterDomainEdge> readMDNetwork(
String fileName, String LearntFrom) {
Logger log = LoggerFactory.getLogger("BGP4Peer");
DirectedWeightedMultigraph<Object, InterDomainEdge> graph = new DirectedWeightedMultigraph<Object, InterDomainEdge>(
InterDomainEdge.class);
Hashtable<Object, Inet4Address> router_id_domain_ed = new Hashtable<Object, Inet4Address>();
Hashtable<Object, DataPathID> router_id_domain_ed_dp = new Hashtable<Object, DataPathID>();
HashMap<Inet4Address, Integer >SIDS = new HashMap<Inet4Address,Integer>();
HashMap<DataPathID, Integer >SIDSDP = new HashMap<DataPathID,Integer>();
Object router_id_addr = null;
Object s_router_id_addr = null;
Object d_router_id_addr = null;
File file = new File(fileName);
try {
DocumentBuilder builder = DocumentBuilderFactory.newInstance()
.newDocumentBuilder();
Document doc = builder.parse(file);
NodeList nodes_domains = doc.getElementsByTagName("domain");
// First pass to read all the nodes and domains
log.info("Multidomain Graph");
for (int j = 0; j < nodes_domains.getLength(); j++) {
Element element_domain = (Element) nodes_domains.item(j);
NodeList nodes_domain_id = element_domain
.getElementsByTagName("domain_id");
Element domain_id_e = (Element) nodes_domain_id.item(0);
String domain_id_str = getCharacterDataFromElement(domain_id_e);
Inet4Address domain_id = (Inet4Address) Inet4Address
.getByName(domain_id_str);
log.info("Adding Domain: " + domain_id);
graph.addVertex(domain_id);
NodeList nodes = element_domain.getElementsByTagName("node");
for (int i = 0; i < nodes.getLength(); i++) {
Element element = (Element) nodes.item(i);
NodeList router_id_node = element
.getElementsByTagName("router_id");
Element router_id_e = (Element) router_id_node.item(0);
String router_id = getCharacterDataFromElement(router_id_e);
log.debug("Router_id: " + router_id);
try { // router_id_addr type: Inet4Address
router_id_addr = (Inet4Address) Inet4Address.getByName(router_id);
} catch (Exception e) { // router_id_addr type: DataPathID
router_id_addr = DataPathID.getByName(router_id);
}
router_id_domain_ed.put(router_id_addr, domain_id);
NodeList nl_sid=element.getElementsByTagName("sid");
Element SID_e = (Element) nl_sid.item(0);
if (SID_e!=null)
{ int SID = Integer.parseInt(getCharacterDataFromElement(SID_e));
try {
SIDS.put((Inet4Address)router_id_addr,SID);
} catch (Exception e) {
SIDSDP.put((DataPathID)router_id_addr,SID);
}
}
}
}
log.debug("Domain_ids read");
int numLabels=0;
Boolean commonBitmapLabelSet = false;
NodeList edgeCommon = doc.getElementsByTagName("edgeCommon");
int grid=0;
int cs=0;
int n=0;
for (int i = 0; i < edgeCommon.getLength(); i++) {
Element edgeCommonElement = (Element) edgeCommon.item(i);
NodeList availableLabels_node = edgeCommonElement.getElementsByTagName("AvailableLabels");
for (int k = 0; k < availableLabels_node.getLength(); k++) {
Element availableLabels_e = (Element) availableLabels_node.item(k);
NodeList labelSetField_node = availableLabels_e.getElementsByTagName("LabelSetField");
Element labelSetField_el = (Element) labelSetField_node.item(0);
if (labelSetField_el.getAttributeNode("type").getValue().equals("4")){//Tengo BitMapSet
//Crear un BitMapSet
NodeList numbLabels_node = labelSetField_el.getElementsByTagName("numLabels");
Element numbLabels_e = (Element) numbLabels_node.item(0);
String numbLabels_s = getCharacterDataFromElement(numbLabels_e);
numLabels=Integer.parseInt(numbLabels_s);
NodeList baseLabel_node = labelSetField_el.getElementsByTagName("baseLabel");
Element baseLabel_e = (Element) baseLabel_node.item(0);
float min_frequency;
grid= Integer.parseInt(baseLabel_e.getAttributeNode("grid").getValue());
cs = Integer.parseInt(baseLabel_e.getAttributeNode("cs").getValue());
boolean n_frequency_included=false;
if (baseLabel_e.getAttributeNode("n") != null ){
n = Integer.parseInt(baseLabel_e.getAttributeNode("n").getValue());
n_frequency_included = true;
}
else if (baseLabel_e.getAttributeNode("min_frequency") != null){
String s_min_frequency = labelSetField_el.getAttributeNode("min_frequency").getValue();
min_frequency=Float.parseFloat(s_min_frequency);
n = ((int)min_frequency - 1471)/20;
n_frequency_included=true;
}
if (n_frequency_included){
commonBitmapLabelSet = true;
}else{
log.error("ERROR reading the xml file of the topology, you should enter <baseLabel grid=\"1\" cs=\"2\" n=\"-11\"></baseLabel> ");
}
}
}
}
NodeList edges = doc.getElementsByTagName("edge");
boolean a =true;
for (int i = 0; i < edges.getLength(); i++) {
log.debug("Looking at edge");
Element element = (Element) edges.item(i);
InterDomainEdge edge = new InterDomainEdge();
TE_Information tE_info=readTE_INFOfromXml(null, element, false,numLabels, grid, cs, n, 0, Integer.MAX_VALUE);
edge.setTE_info(tE_info);
edge.setLearntFrom(LearntFrom);
NodeList source = element.getElementsByTagName("source");
Element source_router_el = (Element) source.item(0);
NodeList source_router_id = source_router_el
.getElementsByTagName("router_id");
Element source_router_id_el = (Element) source_router_id
.item(0);
String s_r_id = getCharacterDataFromElement(source_router_id_el);
log.debug("Edge Source router_id: " + s_r_id);
try { // s_router_id_addr type: Inet4Address
s_router_id_addr = (Inet4Address) Inet4Address.getByName(s_r_id);
} catch (Exception e) {// s_router_id_addr type: DataPathID
s_router_id_addr = DataPathID.getByName(s_r_id);
}
Inet4Address source_domain_id = router_id_domain_ed.get(s_router_id_addr);
log.debug("Edge Source domain_id: " + source_domain_id);
NodeList source_if_id_nl = source_router_el
.getElementsByTagName("if_id");
Element source_if_id_el = (Element) source_if_id_nl.item(0);
String s_source_if_id = getCharacterDataFromElement(source_if_id_el);
log.debug("Edge Source if_id: " + s_source_if_id);
int src_if_id = Integer.parseInt(s_source_if_id);
NodeList dest_nl = element.getElementsByTagName("destination");
Element dest_el = (Element) dest_nl.item(0);
NodeList dest_router_id_nl = dest_el
.getElementsByTagName("router_id");
Element dest_router_id_el = (Element) dest_router_id_nl.item(0);
String d_r_id = getCharacterDataFromElement(dest_router_id_el);
log.debug("Edge Destination router_id: " + d_r_id);
try { // d_router_id_addr type: Inet4Address
d_router_id_addr = (Inet4Address) Inet4Address.getByName(d_r_id);
} catch (Exception e) { // d_router_id_addr type: DataPathID
d_router_id_addr = DataPathID.getByName(d_r_id);
}
Inet4Address dest_domain_id = router_id_domain_ed.get(d_router_id_addr);
log.debug("Destination domain_id: " + dest_domain_id);
NodeList dest_if_id_nl = dest_el.getElementsByTagName("if_id");
Element dest_if_id_el = (Element) dest_if_id_nl.item(0);
String s_dest_if_id = getCharacterDataFromElement(dest_if_id_el);
log.debug("Edge Dest if_id: " + s_dest_if_id);
int dst_if_id = Integer.parseInt(s_dest_if_id);
//router_id_domain_ed
//edge.setDomain_src_router(source_domain_id);
edge.setSrc_if_id(src_if_id);
edge.setDst_if_id(dst_if_id);
edge.setDomain_src_router(source_domain_id);
edge.setDomain_dst_router(dest_domain_id);
edge.setSrc_router_id(s_router_id_addr);
edge.setDst_router_id(d_router_id_addr);
if (!source_domain_id.equals(dest_domain_id)) {
log.info("Adding interdomain link "+source_domain_id.toString()+"-->"+dest_domain_id.toString()+" learnt "+edge.getLearntFrom());//edge.toString());
//Only add if the source and destination domains are different
graph.addEdge(source_domain_id, dest_domain_id, edge);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return graph;
}
public static void initializeReachabilityFromFile(String fileName,
ReachabilityManager rm) {
Logger log = LoggerFactory.getLogger("BGP4Peer");
log.debug("Initializing reachability from " + fileName);
File file = new File(fileName);
try {
DocumentBuilder builder = DocumentBuilderFactory.newInstance()
.newDocumentBuilder();
Document doc = builder.parse(file);
NodeList nodes_domains = doc.getElementsByTagName("domain");
for (int j = 0; j < nodes_domains.getLength(); j++) {
Element element_domain = (Element) nodes_domains.item(j);
NodeList nodes_domain_id = element_domain
.getElementsByTagName("domain_id");
Element domain_id_e = (Element) nodes_domain_id.item(0);
String domain_id_str = getCharacterDataFromElement(domain_id_e);
Inet4Address domain_id = (Inet4Address) Inet4Address
.getByName(domain_id_str);
log.debug("Network domain es: " + domain_id);
NodeList nodes = element_domain
.getElementsByTagName("reachability_entry");
log.debug("HAY : " + nodes.getLength());
for (int i = 0; i < nodes.getLength(); i++) {
Element element = (Element) nodes.item(i);
NodeList ipv4_address_node = element
.getElementsByTagName("ipv4_address");
Element ipv4_address_el = (Element) ipv4_address_node
.item(0);
String ipv4_address_str = getCharacterDataFromElement(ipv4_address_el);
log.debug("ipv4_address: " + ipv4_address_str);
Inet4Address ipv4_address = (Inet4Address) Inet4Address
.getByName(ipv4_address_str);
IPv4prefixEROSubobject eroso = new IPv4prefixEROSubobject();
eroso.setIpv4address(ipv4_address);
NodeList prefix_node = element
.getElementsByTagName("prefix");
Element prefix_el = (Element) prefix_node.item(0);
String prefix_str = getCharacterDataFromElement(prefix_el);
int prefix = Integer.parseInt(prefix_str);
eroso.setPrefix(prefix);
rm.addEROSubobject(domain_id, eroso);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
// IT update del GEYSERS
public static DirectedWeightedMultigraph<Object,InterDomainEdge> readITMDNetwork(String fileName){
Logger log=LoggerFactory.getLogger("BGP4Peer");
DirectedWeightedMultigraph<Object,InterDomainEdge>graph =new DirectedWeightedMultigraph<Object,InterDomainEdge>(InterDomainEdge.class);
Hashtable <Object,Object> router_id_domain_ed=new Hashtable <Object,Object>();
Hashtable <Object,Object> it_site_id_domain_ed2=new Hashtable <Object,Object>();
Hashtable <Object,Object> resource_id_domain_ed=new Hashtable <Object,Object>();
File file = new File(fileName);
try {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(file);
NodeList nodes_domains = doc.getElementsByTagName("domain");
for (int j = 0; j < nodes_domains.getLength(); j++) {
Element element_domain = (Element) nodes_domains.item(j);
NodeList nodes_domain_id = element_domain.getElementsByTagName("domain_id");
Element domain_id_e = (Element) nodes_domain_id.item(0);
String domain_id_str=getCharacterDataFromElement(domain_id_e);
Inet4Address domain_id= (Inet4Address) Inet4Address.getByName(domain_id_str);
log.info("Network domain: "+domain_id);
graph.addVertex(domain_id);
NodeList nodes = element_domain.getElementsByTagName("node");
for (int i = 0; i < nodes.getLength(); i++) {
Element element = (Element) nodes.item(i);
NodeList router_id_node = element.getElementsByTagName("router_id");
Element router_id_e = (Element) router_id_node.item(0);
String router_id=getCharacterDataFromElement(router_id_e);
log.debug("El router_id es "+router_id);
Inet4Address router_id_addr= (Inet4Address) Inet4Address.getByName(router_id);
NodeList domain_id_node = element.getElementsByTagName("domain_id");
router_id_domain_ed.put(router_id_addr, domain_id);
//graph.addVertex(router_id_addr);
}
NodeList ITsites = element_domain.getElementsByTagName("it_site");
for (int i = 0; i < ITsites.getLength(); i++) {
Element element = (Element) ITsites.item(i);
NodeList it_site_id_node = element.getElementsByTagName("it_site_id");
Element it_site_id_e = (Element) it_site_id_node.item(0);
String it_site_id=getCharacterDataFromElement(it_site_id_e);
log.info("El it_site_id es "+it_site_id);
Inet4Address it_site_id_addr= (Inet4Address) Inet4Address.getByName(it_site_id);
NodeList domain_id_node = element.getElementsByTagName("domain_id");
it_site_id_domain_ed2.put(it_site_id_addr, domain_id);
//graph.addVertex(router_id_addr);
}
NodeList storages = element_domain.getElementsByTagName("storage");
for (int i = 0; i < storages.getLength(); i++) {
Element element = (Element) storages.item(i);
NodeList resource_id_node = element.getElementsByTagName("resource_id");
Element resource_id_e = (Element) resource_id_node.item(0);
String resource_id=getCharacterDataFromElement(resource_id_e);
log.info("El resource_id es "+resource_id);
Inet4Address resource_id_addr= (Inet4Address) Inet4Address.getByName(resource_id);
NodeList domain_id_node = element.getElementsByTagName("domain_id");
resource_id_domain_ed.put(resource_id_addr, domain_id);
//graph.addVertex(router_id_addr);
}
}
NodeList edges = doc.getElementsByTagName("edge");
for (int i = 0; i < edges.getLength(); i++) {
log.info("New interdomain edge");
Inet4Address s_router_id_addr= null;
Inet4Address d_router_id_addr= null;
Inet4Address s_itsite_id_addr= null;
Inet4Address d_itsite_id_addr= null;
Inet4Address s_resource_id_addr= null;
Inet4Address d_resource_id_addr= null;
Inet4Address source_domain_id=null;
Inet4Address dest_domain_id=null;
Element element = (Element) edges.item(i);
InterDomainEdge edge =new InterDomainEdge();
NodeList source = element.getElementsByTagName("source");
Element source_router_el = (Element)source.item(0);
NodeList source_router_id= source_router_el.getElementsByTagName("router_id");
if (source_router_id.getLength()>0){
Element source_router_id_el=(Element)source_router_id.item(0);
String s_r_id=getCharacterDataFromElement(source_router_id_el);
log.info("Edge Source router_id: "+s_r_id);
s_router_id_addr= (Inet4Address) Inet4Address.getByName(s_r_id);
source_domain_id= (Inet4Address)router_id_domain_ed.get(s_router_id_addr);
log.info("Edge Source domain_id: "+source_domain_id);
}
NodeList source_it_site_id= source_router_el.getElementsByTagName("it_site_id");
if (source_it_site_id.getLength()>0){
Element source_it_site_id_el=(Element)source_it_site_id.item(0);
String s_itsite_id=getCharacterDataFromElement(source_it_site_id_el);
log.info("Edge Source it_site_id: "+s_itsite_id);
s_itsite_id_addr= (Inet4Address) Inet4Address.getByName(s_itsite_id);
source_domain_id= (Inet4Address)it_site_id_domain_ed2.get(s_itsite_id_addr);
log.info("Edge Source ITsite domain_id: "+source_domain_id);
}
NodeList source_resource_id= source_router_el.getElementsByTagName("resource_id");
if (source_resource_id.getLength()>0){
Element source_resource_id_el=(Element)source_resource_id.item(0);
String s_resource_id=getCharacterDataFromElement(source_resource_id_el);
log.info("Edge Source resource_id: "+s_resource_id);
s_resource_id_addr= (Inet4Address) Inet4Address.getByName(s_resource_id);
source_domain_id= (Inet4Address)resource_id_domain_ed.get(s_resource_id_addr);
log.info("Edge Source ITsite domain_id: "+source_domain_id);
}
NodeList source_if_id_nl= source_router_el.getElementsByTagName("if_id");
Element source_if_id_el=(Element)source_if_id_nl.item(0);
String s_source_if_id=getCharacterDataFromElement(source_if_id_el);
log.info("Edge Source if_id: "+s_source_if_id);
int src_if_id=Integer.parseInt(s_source_if_id);
NodeList dest_nl = element.getElementsByTagName("destination");
Element dest_el = (Element)dest_nl.item(0);
NodeList dest_router_id_nl= dest_el.getElementsByTagName("router_id");
if (dest_router_id_nl.getLength()>0){
Element dest_router_id_el=(Element)dest_router_id_nl.item(0);
String d_r_id=getCharacterDataFromElement(dest_router_id_el);
log.info("Edge Destination router_id: "+d_r_id);
d_router_id_addr= (Inet4Address) Inet4Address.getByName(d_r_id);
dest_domain_id= (Inet4Address)router_id_domain_ed.get(d_router_id_addr);
log.info("Destination domain_id: "+dest_domain_id);
}
NodeList dest_it_site_id_nl= dest_el.getElementsByTagName("it_site_id");
if (dest_it_site_id_nl.getLength()>0){
Element dest_it_site_id_el=(Element)dest_it_site_id_nl.item(0);
String d_itsite_id=getCharacterDataFromElement(dest_it_site_id_el);
log.info("Edge Destination it_site_id: "+d_itsite_id);
d_itsite_id_addr= (Inet4Address) Inet4Address.getByName(d_itsite_id);
dest_domain_id= (Inet4Address)it_site_id_domain_ed2.get(d_itsite_id_addr);
log.info("Destination ITsite domain_id: "+dest_domain_id);
}
NodeList dest_resource_id_nl= dest_el.getElementsByTagName("resource_id");
if (dest_resource_id_nl.getLength()>0){
Element dest_resource_id_el=(Element)dest_resource_id_nl.item(0);
String d_resource_id=getCharacterDataFromElement(dest_resource_id_el);
log.info("Edge Destination resource_id: "+d_resource_id);
d_resource_id_addr= (Inet4Address) Inet4Address.getByName(d_resource_id);
dest_domain_id= (Inet4Address)resource_id_domain_ed.get(d_resource_id_addr);
log.info("Destination ITsite domain_id: "+dest_domain_id);
}
NodeList dest_if_id_nl= dest_el.getElementsByTagName("if_id");
Element dest_if_id_el=(Element)dest_if_id_nl.item(0);
String s_dest_if_id=getCharacterDataFromElement(dest_if_id_el);
log.info("Edge Dest if_id: "+s_dest_if_id);
int dst_if_id=Integer.parseInt(s_dest_if_id);
edge.setSrc_if_id(src_if_id);
edge.setDst_if_id(dst_if_id);
if (source_router_id.getLength()>0){
edge.setSrc_router_id(s_router_id_addr);
}else if(source_it_site_id.getLength()>0){
edge.setSrc_router_id(s_itsite_id_addr);
}else if(source_resource_id.getLength()>0){
edge.setSrc_router_id(s_resource_id_addr);
}
if (dest_router_id_nl.getLength()>0){
edge.setDst_router_id(d_router_id_addr);
}else if(dest_it_site_id_nl.getLength()>0){
edge.setDst_router_id(d_itsite_id_addr);
}else if(dest_resource_id_nl.getLength()>0){
edge.setDst_router_id(d_resource_id_addr);
}
graph.addEdge(source_domain_id, dest_domain_id,edge);
}
}
catch (Exception e) {
e.printStackTrace();
}
return graph;
}
public static WSONInformation getWSONInformation(String fileName){
return FileTEDBUpdater.getWSONInformation(fileName,null);
}
public static WSONInformation getWSONInformation(String fileName, String layer){
Logger log = LoggerFactory.getLogger("BGP4Peer");
File file = new File(fileName);
AvailableLabels commonAvailableLabels = null;
WSONInformation WSONinfo = null;
int numLabels = 0;
int grid=0;
int cs=0;
int n=0;
log.debug("FileName:::"+fileName);
try {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(file);
// NodeList nodes_domains = doc.getElementsByTagName("domain");
// for (int j = 0; j < nodes_domains.getLength(); j++) {
// Element element_domain = (Element) nodes_domains.item(j);
NodeList edgeCommon = doc.getElementsByTagName("edgeCommon");
for (int i = 0; i < edgeCommon.getLength(); i++) {
Element edgeCommonElement = (Element) edgeCommon.item(i);
NodeList availableLabels_node = edgeCommonElement.getElementsByTagName("AvailableLabels");
for (int k = 0; k < availableLabels_node.getLength(); k++) {
commonAvailableLabels = new AvailableLabels();
Element availableLabels_e = (Element) availableLabels_node.item(k);
NodeList labelSetField_node = availableLabels_e.getElementsByTagName("LabelSetField");
Element labelSetField_el = (Element) labelSetField_node.item(0);
if (labelSetField_el.getAttributeNode("type").getValue().equals("4")){//Tengo BitMapSet
//Crear un BitMapSet
NodeList numbLabels_node = labelSetField_el.getElementsByTagName("numLabels");
Element numbLabels_e = (Element) numbLabels_node.item(0);
String numbLabels_s = getCharacterDataFromElement(numbLabels_e);
numLabels=Integer.parseInt(numbLabels_s);
NodeList baseLabel_node = labelSetField_el.getElementsByTagName("baseLabel");
Element baseLabel_e = (Element) baseLabel_node.item(0);
float min_frequency;
grid= Integer.parseInt(baseLabel_e.getAttributeNode("grid").getValue());
cs = Integer.parseInt(baseLabel_e.getAttributeNode("cs").getValue());
boolean n_frequency_included=false;
if (baseLabel_e.getAttributeNode("n") != null ){
n = Integer.parseInt(baseLabel_e.getAttributeNode("n").getValue());
n_frequency_included = true;
}
else if (baseLabel_e.getAttributeNode("min_frequency") != null){
String s_min_frequency = labelSetField_el.getAttributeNode("min_frequency").getValue();
min_frequency=Float.parseFloat(s_min_frequency);
n = ((int)min_frequency - 1471)/20;
n_frequency_included=true;
}
if (n_frequency_included){
createBitmapLabelSet(commonAvailableLabels,numLabels,grid,cs,n);
}else{
log.error("ERROR reading the xml file of the topology, you should enter <baseLabel grid=\"1\" cs=\"2\" n=\"-11\"></baseLabel> ");
}
}
}
}
//}
} catch (Exception e) {
log.error(e.toString());
e.printStackTrace();
}
if (commonAvailableLabels !=null){
WSONinfo = new WSONInformation();
WSONinfo.setCommonAvailableLabels(commonAvailableLabels);
WSONinfo.setNumLambdas(numLabels);
WSONinfo.setCs(cs);
WSONinfo.setGrid(grid);
WSONinfo.setnMin(n);
}
return WSONinfo;
}
public static SSONInformation getSSONInformation(String fileName){
return FileTEDBUpdater.getSSONInformation(fileName,null);
}
public static SSONInformation getSSONInformation(String fileName, String layer){
Logger log = LoggerFactory.getLogger("BGP4Peer");
File file = new File(fileName);
AvailableLabels commonAvailableLabels = null;
SSONInformation SSONinfo = null;
int numLabels = 0;
int grid=0;
int cs=0;
int n=0;
try {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(file);
// NodeList nodes_domains = doc.getElementsByTagName("domain");
// for (int j = 0; j < nodes_domains.getLength(); j++) {
// Element element_domain = (Element) nodes_domains.item(j);
NodeList edgeCommon = doc.getElementsByTagName("edgeCommon");
for (int i = 0; i < edgeCommon.getLength(); i++) {
Element edgeCommonElement = (Element) edgeCommon.item(i);
NodeList availableLabels_node = edgeCommonElement.getElementsByTagName("AvailableLabels");
for (int k = 0; k < availableLabels_node.getLength(); k++) {
commonAvailableLabels = new AvailableLabels();
Element availableLabels_e = (Element) availableLabels_node.item(k);
NodeList labelSetField_node = availableLabels_e.getElementsByTagName("LabelSetField");
Element labelSetField_el = (Element) labelSetField_node.item(0);
if (labelSetField_el.getAttributeNode("type").getValue().equals("4")){//Tengo BitMapSet
//Crear un BitMapSet
NodeList numbLabels_node = labelSetField_el.getElementsByTagName("numLabels");
Element numbLabels_e = (Element) numbLabels_node.item(0);
String numbLabels_s = getCharacterDataFromElement(numbLabels_e);
numLabels=Integer.parseInt(numbLabels_s);
NodeList baseLabel_node = labelSetField_el.getElementsByTagName("baseLabel");
Element baseLabel_e = (Element) baseLabel_node.item(0);
float min_frequency;
grid= Integer.parseInt(baseLabel_e.getAttributeNode("grid").getValue());
cs = Integer.parseInt(baseLabel_e.getAttributeNode("cs").getValue());
boolean n_frequency_included=false;
if (baseLabel_e.getAttributeNode("n") != null ){
n = Integer.parseInt(baseLabel_e.getAttributeNode("n").getValue());
n_frequency_included = true;
}
else if (baseLabel_e.getAttributeNode("min_frequency") != null){
String s_min_frequency = labelSetField_el.getAttributeNode("min_frequency").getValue();
min_frequency=Float.parseFloat(s_min_frequency);
n = ((int)min_frequency - 1471)/20;
n_frequency_included=true;
}
if (n_frequency_included){
createBitmapLabelSet(commonAvailableLabels,numLabels,grid,cs,n);
}else{
log.error("ERROR reading the xml file of the topology, you should enter <baseLabel grid=\"1\" cs=\"2\" n=\"-11\"></baseLabel> ");
}
}
}
}
//}
} catch (Exception e) {
e.printStackTrace();
}
if (commonAvailableLabels !=null){
SSONinfo = new SSONInformation();
SSONinfo.setCommonAvailableLabels(commonAvailableLabels);
// if(cs==5){
// SSONinfo.setNumLambdas(numLabels*8);
// }
SSONinfo.setNumLambdas(numLabels);
SSONinfo.setCs(cs);
SSONinfo.setGrid(grid);
SSONinfo.setnMin(n);
}
return SSONinfo;
}
public static void createBitmapLabelSet(AvailableLabels availableLabels,int numLabels,int grid, int cs,int n){
//FIXME: no hay problema de que se salga el ancho de banda
BitmapLabelSet bitmapLabelSet = new BitmapLabelSet();
DWDMWavelengthLabel dwdmWavelengthLabel = new DWDMWavelengthLabel();
dwdmWavelengthLabel.setGrid(grid);
dwdmWavelengthLabel.setChannelSpacing(cs);
dwdmWavelengthLabel.setN(n);
bitmapLabelSet.setDwdmWavelengthLabel(dwdmWavelengthLabel);
int numberBytes = numLabels/8;
if ((numberBytes*8)<numLabels){
numberBytes++;
}
byte[] bytesBitMap = new byte[numberBytes];
for (int i=0;i<numberBytes;i++)
bytesBitMap[i]=0x00;
bitmapLabelSet.setBytesBitmap(bytesBitMap);
bitmapLabelSet.setNumLabels(numLabels);
availableLabels.setLabelSet(bitmapLabelSet);
}
public static void getDomainReachabilityFromFile(String fileName, ReachabilityEntry reachabilityEntry) {
FileTEDBUpdater.getDomainReachabilityFromFile(fileName, reachabilityEntry,null);
}
public static Inet4Address getDomainIDfromSimpleDomain(String fileName) {
Logger log = LoggerFactory.getLogger("BGP4Peer");
log.debug("Initializng reachability from " + fileName);
File file = new File(fileName);
Inet4Address domain_id = null;
try {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(file);
NodeList nodes_domains = doc.getElementsByTagName("domain");
Element element_domain = (Element) nodes_domains.item(0);
NodeList nodes_domain_id = element_domain.getElementsByTagName("domain_id");
Element domain_id_e = (Element) nodes_domain_id.item(0);
String domain_id_str = getCharacterDataFromElement(domain_id_e);
domain_id = (Inet4Address) Inet4Address.getByName(domain_id_str);
log.debug("El dominio leido es: " + domain_id);
} catch (Exception e) {
e.printStackTrace();
}
return domain_id;
}
public static void getDomainReachabilityFromFile(String fileName,
/*byte[] domainReachabilityIPv4Prefix,*/ ReachabilityEntry reachabilityEntry,String layer) {
Logger log = LoggerFactory.getLogger("BGP4Peer");
log.debug("Initializng reachability from " + fileName);
log.debug("probandoooo Initializng reachability from " + fileName);
File file = new File(fileName);
try {
DocumentBuilder builder = DocumentBuilderFactory.newInstance()
.newDocumentBuilder();
Document doc = builder.parse(file);
NodeList nodes_domains = doc.getElementsByTagName("domain");
for (int j = 0; j < nodes_domains.getLength(); j++) {
boolean readNetwork=false;
if (layer!=null){
NodeList nodes_layer = doc.getElementsByTagName("layer");
for (int i = 0; i < nodes_layer.getLength(); i++) {
Element element = (Element) nodes_layer.item(i);
String layer2 =getCharacterDataFromElement(element);
if (layer2.equals(layer)){
readNetwork=true;
}
}
}else {
readNetwork=true;
}
if (readNetwork){
Element element_domain = (Element) nodes_domains.item(j);
NodeList nodes_domain_id = element_domain
.getElementsByTagName("domain_id");
Element domain_id_e = (Element) nodes_domain_id.item(0);
String domain_id_str = getCharacterDataFromElement(domain_id_e);
Inet4Address domain_id = (Inet4Address) Inet4Address
.getByName(domain_id_str);
reachabilityEntry.setDomainId(domain_id);
log.debug("Network domain es: " + domain_id);
NodeList nodes = element_domain
.getElementsByTagName("reachability_entry");
for (int i = 0; i < nodes.getLength(); i++) {
Element element = (Element) nodes.item(i);
NodeList ipv4_address_node = element
.getElementsByTagName("ipv4_address");
Element ipv4_address_el = (Element) ipv4_address_node
.item(0);
String ipv4_address_str = getCharacterDataFromElement(ipv4_address_el);
log.debug("ipv4_address: " + ipv4_address_str);
Inet4Address ipv4_address = (Inet4Address) Inet4Address
.getByName(ipv4_address_str);
reachabilityEntry.setAggregatedIPRange(ipv4_address);
//FIXME: dudas de esto. Si asignar la IP o copiarla byte a byte con arraycopy
/* System.arraycopy(ipv4_address.getAddress(), 0,
reachabilityEntry.getAggregatedIPRange(), 0, 4);*/
IPv4prefixEROSubobject eroso = new IPv4prefixEROSubobject();
NodeList prefix_node = element
.getElementsByTagName("prefix");
Element prefix_el = (Element) prefix_node.item(0);
String prefix_str = getCharacterDataFromElement(prefix_el);
int prefix = Integer.parseInt(prefix_str);
//Meto el prefijo
reachabilityEntry.setPrefix(prefix);
long resta = ((long) 0x1 << prefix) - 1;
long maskLong = resta << (32 - prefix);
byte[] mask = new byte[4];
mask[0] = (byte) (maskLong >>> 24 & 0xFF);
mask[1] = (byte) (maskLong >>> 16 & 0xFF);
mask[2] = (byte) (maskLong >>> 8 & 0xFF);
mask[3] = (byte) (maskLong & 0xFF);
//Meto la mascara
reachabilityEntry.setMask(mask);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Read the interdomain Topology from a topology file
* @param fileName Name of the xml file.
* @return List of interdomain edges.
*/
public static LinkedList<InterDomainEdge> readInterDomainLinks(String fileName) {
LinkedList<InterDomainEdge> interDomainLinks = new LinkedList<InterDomainEdge>();
Logger log = LoggerFactory.getLogger("BGP4Peer");
File file = new File(fileName);
Inet4Address domain_id=null;
try {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(file);
NodeList nodes_domains = doc.getElementsByTagName("domain");
if (nodes_domains!=null){
if (nodes_domains.getLength()>=1){
for (int j = 0; j < nodes_domains.getLength(); j++) {
Element element_domain = (Element) nodes_domains.item(j);
NodeList nodes_domain_id = element_domain.getElementsByTagName("domain_id");
Element domain_id_e = (Element) nodes_domain_id.item(0);
String domain_id_str=getCharacterDataFromElement(domain_id_e);
domain_id= (Inet4Address) Inet4Address.getByName(domain_id_str);
}
}
}
Boolean commonBitmapLabelSet = false;
NodeList edgeCommon = doc.getElementsByTagName("edgeCommon");
int grid=0;
int cs=0;
int n=0;
int numLabels=0;
for (int i = 0; i < edgeCommon.getLength(); i++) {
Element edgeCommonElement = (Element) edgeCommon.item(i);
NodeList availableLabels_node = edgeCommonElement.getElementsByTagName("AvailableLabels");
for (int k = 0; k < availableLabels_node.getLength(); k++) {
Element availableLabels_e = (Element) availableLabels_node.item(k);
NodeList labelSetField_node = availableLabels_e.getElementsByTagName("LabelSetField");
Element labelSetField_el = (Element) labelSetField_node.item(0);
if (labelSetField_el.getAttributeNode("type").getValue().equals("4")){//Tengo BitMapSet
//Crear un BitMapSet
NodeList numbLabels_node = labelSetField_el.getElementsByTagName("numLabels");
Element numbLabels_e = (Element) numbLabels_node.item(0);
String numbLabels_s = getCharacterDataFromElement(numbLabels_e);
numLabels=Integer.parseInt(numbLabels_s);
NodeList baseLabel_node = labelSetField_el.getElementsByTagName("baseLabel");
Element baseLabel_e = (Element) baseLabel_node.item(0);
float min_frequency;
grid= Integer.parseInt(baseLabel_e.getAttributeNode("grid").getValue());
cs = Integer.parseInt(baseLabel_e.getAttributeNode("cs").getValue());
boolean n_frequency_included=false;
if (baseLabel_e.getAttributeNode("n") != null ){
n = Integer.parseInt(baseLabel_e.getAttributeNode("n").getValue());
n_frequency_included = true;
}
else if (baseLabel_e.getAttributeNode("min_frequency") != null){
String s_min_frequency = labelSetField_el.getAttributeNode("min_frequency").getValue();
min_frequency=Float.parseFloat(s_min_frequency);
n = ((int)min_frequency - 1471)/20;
n_frequency_included=true;
}
if (n_frequency_included){
commonBitmapLabelSet = true;
}else{
log.error("ERROR reading the xml file of the topology, you should enter <baseLabel grid=\"1\" cs=\"2\" n=\"-11\"></baseLabel> ");
}
}
}
}
// Read the nodes of the domain which has interdomain connection
NodeList edges = doc.getElementsByTagName("edge");
for (int i = 0; i < edges.getLength(); i++) {
Element element = (Element) edges.item(i);
// We only want those routers which have type="interdomain"
//if (((String)element.getAttributeNode("type").getValue()).equals("interdomain")) {
if (element.getAttributeNode("type")!=null) {
if (element.getAttributeNode("type").getValue().equals("interdomain")) {
// Create a variable InterDomainEdge where we include
// the two nodes of the connection.
InterDomainEdge connection = new InterDomainEdge();
NodeList source = element.getElementsByTagName("source");
Element source_router_el = (Element) source.item(0);
//Read the source router IP
NodeList source_router_id = source_router_el.getElementsByTagName("router_id");
Element source_router_id_el = (Element) source_router_id.item(0);
String s_r_id = getCharacterDataFromElement(source_router_id_el);
Inet4Address s_router_id_addr = (Inet4Address) Inet4Address.getByName(s_r_id);
//Read the source router interface identifier of the connection
NodeList source_if_id_nl = source_router_el.getElementsByTagName("if_id");
Element source_if_id_el = (Element) source_if_id_nl.item(0);
String s_source_if_id = getCharacterDataFromElement(source_if_id_el);
int src_if_id = Integer.parseInt(s_source_if_id);
NodeList src_domain_nl = source_router_el.getElementsByTagName("domain_id");
Inet4Address s_router_domain=null;
if (src_domain_nl!=null)
{
if (src_domain_nl.getLength()>=1){
Element domain_id_el = (Element) src_domain_nl.item(0);
String s_r_domain = getCharacterDataFromElement(domain_id_el).trim();
s_router_domain = (Inet4Address) Inet4Address.getByName(s_r_domain);
}else{
s_router_domain= domain_id;
}
}else {
s_router_domain= domain_id;
}
//Read the router destination
NodeList dest_nl = element.getElementsByTagName("destination");
Element dest_el = (Element) dest_nl.item(0);
NodeList dest_router_id_nl = dest_el.getElementsByTagName("router_id");
Element dest_router_id_el = (Element) dest_router_id_nl.item(0);
String d_r_id = getCharacterDataFromElement(dest_router_id_el);
log.info("Edge Destination router_id: "+ d_r_id);
Inet4Address d_router_id_addr = (Inet4Address) Inet4Address.getByName(d_r_id);
NodeList dest_if_id_nl = dest_el.getElementsByTagName("if_id");
Element dest_if_id_el = (Element) dest_if_id_nl.item(0);
String s_dest_if_id = getCharacterDataFromElement(dest_if_id_el);
log.info("Edge Dest if_id: " + s_dest_if_id);
int dst_if_id = Integer.parseInt(s_dest_if_id);
NodeList domain = dest_el.getElementsByTagName("domain_id");
Element domain_id_el = (Element) domain.item(0);
String d_r_domain = getCharacterDataFromElement(domain_id_el);
log.info("Destination router domain: "+ d_r_domain);
Inet4Address d_router_domain= (Inet4Address) Inet4Address.getByName(d_r_domain);
// Include the connection between both nodes
connection.setSrc_if_id(src_if_id);
connection.setSrc_router_id(s_router_id_addr);
connection.setDst_if_id(dst_if_id);
connection.setDst_router_id(d_router_id_addr);
connection.setDomain_src_router(s_router_domain);
connection.setDomain_dst_router(d_router_domain);
if(connection.getTE_info()==null){
TE_Information tE_info= new TE_Information();
if (commonBitmapLabelSet){
tE_info.createBitmapLabelSet(numLabels, grid, cs, n);
}
connection.setTE_info(tE_info);
}
//add the connection to the LinkedList.
interDomainLinks.add(connection);
}
}
}
//}//end for domains
} catch (Exception e) {
e.printStackTrace();
}
return interDomainLinks;
}
public static int readWSONLambdas(String fileName){
Logger log=LoggerFactory.getLogger("BGP4Peer");
File file = new File(fileName);
int num_wavelengths=4;
try {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(file);
NodeList nodes_domains = doc.getElementsByTagName("domain");
for (int j = 0; j < nodes_domains.getLength(); j++) {
Element element_domain = (Element) nodes_domains.item(j);
NodeList nodes_wl= element_domain.getElementsByTagName("num_wavelengths");
for (int k = 0; k < nodes_wl.getLength(); k++) {
Element nodes_wl_e = (Element) nodes_wl.item(0);
String num_wavelengths_id=getCharacterDataFromElement(nodes_wl_e );
num_wavelengths=Integer.parseInt(num_wavelengths_id);
log.info("num_wavelength: "+num_wavelengths);
}
}
}
catch (Exception e) {
e.printStackTrace();
}
return num_wavelengths;
}
public static Hashtable <Object,Object> getITSites(String fileName){
Hashtable <Object,Object> it_site_id_domain_ed=new Hashtable <Object,Object>();
File file2 = new File(fileName);
try {
DocumentBuilder builder2 = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc2 = builder2.parse(file2);
NodeList nodes_domains = doc2.getElementsByTagName("domain");
for (int j = 0; j < nodes_domains.getLength(); j++) {
Element element_domain = (Element) nodes_domains.item(j);
NodeList nodes_domain_id = element_domain.getElementsByTagName("domain_id");
Element domain_id_e = (Element) nodes_domain_id.item(0);
String domain_id_str=getCharacterDataFromElement(domain_id_e);
Inet4Address domain_id= (Inet4Address) Inet4Address.getByName(domain_id_str);
NodeList ITsites = element_domain.getElementsByTagName("it_site");
for (int i = 0; i < ITsites.getLength(); i++) {
Element element = (Element) ITsites.item(i);
NodeList it_site_id_node = element.getElementsByTagName("it_site_id");
Element it_site_id_e = (Element) it_site_id_node.item(0);
String it_site_id=getCharacterDataFromElement(it_site_id_e);
Inet4Address it_site_id_addr= (Inet4Address) Inet4Address.getByName(it_site_id);
NodeList domain_id_node = element.getElementsByTagName("domain_id");
it_site_id_domain_ed.put(it_site_id_addr, domain_id);
//graph.addVertex(router_id_addr);
}
}
}
catch (Exception e) {
e.printStackTrace();
}
return it_site_id_domain_ed;
}
public static Hashtable <Object,Object> getResource(String fileName){
Hashtable <Object,Object> resource_id_domain_ed=new Hashtable <Object,Object>();
File file2 = new File(fileName);
try {
DocumentBuilder builder2 = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc2 = builder2.parse(file2);
NodeList nodes_domains = doc2.getElementsByTagName("domain");
for (int j = 0; j < nodes_domains.getLength(); j++) {
Element element_domain = (Element) nodes_domains.item(j);
NodeList nodes_domain_id = element_domain.getElementsByTagName("domain_id");
Element domain_id_e = (Element) nodes_domain_id.item(0);
String domain_id_str=getCharacterDataFromElement(domain_id_e);
Inet4Address domain_id= (Inet4Address) Inet4Address.getByName(domain_id_str);
NodeList storages = element_domain.getElementsByTagName("storage");
for (int i = 0; i < storages.getLength(); i++) {
Element element = (Element) storages.item(i);
NodeList resource_id_node = element.getElementsByTagName("resource_id");
Element resource_id_e = (Element) resource_id_node.item(0);
String resource_id=getCharacterDataFromElement(resource_id_e);
Inet4Address resource_id_addr= (Inet4Address) Inet4Address.getByName(resource_id);
NodeList domain_id_node = element.getElementsByTagName("domain_id");
resource_id_domain_ed.put(resource_id_addr, domain_id);
//graph.addVertex(router_id_addr);
}
}
}
catch (Exception e) {
e.printStackTrace();
}
return resource_id_domain_ed;
}
}
// Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package eu.teraflow.tid.tedb;
import es.tid.bgp.bgp4.update.tlv.linkstate_attribute_tlvs.DefaultTEMetricLinkAttribTLV;
import es.tid.bgp.bgp4.update.tlv.linkstate_attribute_tlvs.IPv4RouterIDLocalNodeLinkAttribTLV;
import es.tid.bgp.bgp4.update.tlv.linkstate_attribute_tlvs.IPv4RouterIDRemoteNodeLinkAttribTLV;
import es.tid.bgp.bgp4.update.tlv.linkstate_attribute_tlvs.LinkProtectionTypeLinkAttribTLV;
import es.tid.bgp.bgp4.update.tlv.linkstate_attribute_tlvs.MF_OTPAttribTLV;
import es.tid.bgp.bgp4.update.tlv.linkstate_attribute_tlvs.MetricLinkAttribTLV;
import es.tid.bgp.bgp4.update.tlv.linkstate_attribute_tlvs.TransceiverClassAndAppAttribTLV;
import es.tid.bgp.bgp4.update.tlv.node_link_prefix_descriptor_subTLVs.MinMaxUndirectionalLinkDelayDescriptorSubTLV;
import es.tid.bgp.bgp4.update.tlv.node_link_prefix_descriptor_subTLVs.UndirectionalAvailableBandwidthDescriptorSubTLV;
import es.tid.bgp.bgp4.update.tlv.node_link_prefix_descriptor_subTLVs.UndirectionalDelayVariationDescriptorSubTLV;
import es.tid.bgp.bgp4.update.tlv.node_link_prefix_descriptor_subTLVs.UndirectionalLinkDelayDescriptorSubTLV;
import es.tid.bgp.bgp4.update.tlv.node_link_prefix_descriptor_subTLVs.UndirectionalLinkLossDescriptorSubTLV;
import es.tid.bgp.bgp4.update.tlv.node_link_prefix_descriptor_subTLVs.UndirectionalResidualBandwidthDescriptorSubTLV;
import es.tid.bgp.bgp4.update.tlv.node_link_prefix_descriptor_subTLVs.UndirectionalUtilizedBandwidthDescriptorSubTLV;
import es.tid.ospf.ospfv2.lsa.tlv.subtlv.AdministrativeGroup;
import es.tid.ospf.ospfv2.lsa.tlv.subtlv.AvailableLabels;
import es.tid.ospf.ospfv2.lsa.tlv.subtlv.IPv4RemoteASBRID;
import es.tid.ospf.ospfv2.lsa.tlv.subtlv.InterfaceSwitchingCapabilityDescriptor;
import es.tid.ospf.ospfv2.lsa.tlv.subtlv.LinkLocalRemoteIdentifiers;
import es.tid.ospf.ospfv2.lsa.tlv.subtlv.LinkProtectionType;
import es.tid.ospf.ospfv2.lsa.tlv.subtlv.MaximumBandwidth;
import es.tid.ospf.ospfv2.lsa.tlv.subtlv.MaximumReservableBandwidth;
import es.tid.ospf.ospfv2.lsa.tlv.subtlv.RemoteASNumber;
import es.tid.ospf.ospfv2.lsa.tlv.subtlv.SharedRiskLinkGroup;
import es.tid.ospf.ospfv2.lsa.tlv.subtlv.TrafficEngineeringMetric;
import es.tid.ospf.ospfv2.lsa.tlv.subtlv.UnreservedBandwidth;
import es.tid.ospf.ospfv2.lsa.tlv.subtlv.complexFields.BitmapLabelSet;
import es.tid.rsvp.constructs.gmpls.DWDMWavelengthLabel;
public class IT_Resources {
private String controllerIT;
private String cpu;
private String mem;
private String storage;
private String learntFrom;
private String domainID;
/**
* TEDB logger
*/
public IT_Resources()
{
//initWLANs();
}
public String getCpu() {
return cpu;
}
public void setCpu(String cpu) {
this.cpu = cpu;
}
public String getMem() {
return mem;
}
public void setMem(String mem) {
this.mem = mem;
}
public String getStorage() {
return storage;
}
public void setStorage(String storage) {
this.storage = storage;
}
/**
* Funcion que transforma una cantidad de bits en el numero de bytes que necesita
* @param numBit
*/
private int getNumberBytes(int numBits){
int numberBytes = numBits/8;
if ((numberBytes*8)<numBits){
numberBytes++;
}
return numberBytes;
}
public String toString(){
String ret="";
if (controllerIT!=null){
ret=ret+controllerIT.toString()+"\t";
}
if (cpu!=null){
ret=ret+cpu.toString()+"\t";
}
if (mem!=null){
ret=ret+mem.toString()+"\t";
}
if (storage!=null){
ret=ret+storage.toString()+"\t";
}
return ret;
}
public String getControllerIT() {
return controllerIT;
}
public void setControllerIT(String controllerIT) {
this.controllerIT = controllerIT;
}
public String getLearntFrom() {
return learntFrom;
}
public void setLearntFrom(String learntFrom) {
this.learntFrom = learntFrom;
}
public String getITdomainID() {
return domainID;
}
public void setITdomainID(String ID) {
this.domainID = ID;
}
}
// Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package eu.teraflow.tid.tedb;
import org.jgrapht.graph.DefaultWeightedEdge;
public class InterDomainEdge extends DefaultWeightedEdge {
/**
* Interface ID of the outgoing interface from the source
*/
public long src_if_id;
/**
* Interface ID of the incoming interface from the destination
*/
public long dst_if_id;
public Object src_router_id;
public Object dst_router_id;
/**
* Source route domain
*/
public Object domain_src_router;
/**
* Destination router domain
*/
public Object domain_dst_router;
public TE_Information TE_info;
public InterDomainEdge(){
TE_info=new TE_Information();
}
public InterDomainEdge(Object src, Object dst){
src_router_id= src;
dst_router_id=dst;
}
public Object getDomain_dst_router() {
return domain_dst_router;
}
public void setDomain_dst_router(Object domain_dst_router) {
this.domain_dst_router = domain_dst_router;
}
public Object getSource(){
Object source= (Object)super.getSource();
return source;
}
public TE_Information getTE_info() {
return TE_info;
}
public void setTE_info(TE_Information tE_info) {
TE_info = tE_info;
}
public Object getTarget(){
Object destination= (Object)super.getTarget();
return destination;
}
public long getSrc_if_id() {
return src_if_id;
}
public void setSrc_if_id(long src_if_id) {
this.src_if_id = src_if_id;
}
public long getDst_if_id() {
return dst_if_id;
}
public void setDst_if_id(long dst_if_id) {
this.dst_if_id = dst_if_id;
}
public Object getSrc_router_id() {
return src_router_id;
}
public void setSrc_router_id(Object src_router_id) {
this.src_router_id = src_router_id;
}
public Object getDst_router_id() {
return dst_router_id;
}
public void setDst_router_id(Object dst_router_id) {
this.dst_router_id = dst_router_id;
}
public Node_Info getLocal_Node_Info() {
return Local_Node_Info;
}
public void setLocal_Node_Info(Node_Info local_Node_Info) {
Local_Node_Info = local_Node_Info;
}
public Node_Info getRemote_Node_Info() {
return Remote_Node_Info;
}
public void setRemote_Node_Info(Node_Info remote_Node_Info) {
Remote_Node_Info = remote_Node_Info;
}
public String getLearntFrom() {
return learntFrom;
}
public void setLearntFrom(String learntFrom) {
this.learntFrom = learntFrom;
}
public int getSrc_sid() {
return src_sid;
}
public void setSrc_sid(int src_sid) {
this.src_sid = src_sid;
}
public int getDst_sid() {
return dst_sid;
}
public void setDst_sid(int dst_sid) {
this.dst_sid = dst_sid;
}
/**
* Characterization of local node
*
*/
public Node_Info Local_Node_Info;
/**
* Characterization of remote node
*
*/
public Node_Info Remote_Node_Info;
/**
* where have we leanrt the info from...
*/
private String learntFrom;
/**
* SID of the source node
*/
private int src_sid;
/**
* SID of the destination node
*/
private int dst_sid;
@Override
public boolean equals(Object obj) {
if ((((InterDomainEdge)obj).getDst_router_id()).equals(dst_router_id)
&& (((InterDomainEdge)obj).getSrc_router_id()).equals(src_router_id)){
return true;
}
return false;
}
@Override
public String toString(){
String ideString;
//TODO: he cambiado esta linea,...porq no me funcionaba super.getSource...Hayq ue mirarlo!!
//ideString=src_router_id.toString()+":"+src_if_id+" ("+((Object)super.getSource()).toString()+") --> "+dst_router_id.toString()+":"+dst_if_id+" ("+((Object)super.getTarget()).toString()+")";
ideString=src_router_id.toString()+": "+src_if_id+" --> "+dst_router_id.toString()+": "+dst_if_id;
/*if (TE_info==null){
return ideString;
}
else
{
if ((this.TE_info.getAvailableLabels()!=null) &&(this.TE_info.getAvailableLabels().getLabelSet()!=null)){
ideString=ideString+" Bitmap: {";
for (int i=0;i<this.TE_info.getAvailableLabels().getLabelSet().getNumLabels();++i){
ideString = ideString+ (this.TE_info.isWavelengthFree(i)?"0":"1");
}
ideString=ideString+"}";
ideString=ideString+" Reserved: {";
for (int i=0;i<this.TE_info.getAvailableLabels().getLabelSet().getNumLabels();++i){
ideString = ideString+ (this.TE_info.isWavelengthUnreserved(i)?"0":"1");
}
ideString=ideString+"}";
ideString = ideString + "\r\n TED: " + this.TE_info.toString() + "\r\n";
return ideString;
}else {*/
return ideString + "\r\n TED: " + this.TE_info.toString() + "\r\n";
// }
//}
}
public Object getDomain_src_router() {
return domain_src_router;
}
public void setDomain_src_router(Object domain_src_router) {
this.domain_src_router = domain_src_router;
}
}
// Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package eu.teraflow.tid.tedb;
import org.jgrapht.graph.DefaultWeightedEdge;
import eu.teraflow.tid.tedb.elements.Bandwidth;
/**
* IntraDomain Edge of a Traffic Engineering Database.
* @author ogondio, msc. pac
*
*/
public class IntraDomainEdge extends DefaultWeightedEdge {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Unnumbered Interface ID of the outgoing interface from the source
*/
public long src_if_id;
/**
* Unnumbered Interface ID of the incoming interface from the destination
*/
public long dst_if_id;
/**
* Numbered Interface ID of the outgoing interface from the source
*/
public Object src_Numif_id;
/**
* Numbered Interface ID of the incoming interface from the destination
*/
public Object dst_Numif_id;
/**
* Traffic engineering information, as defined in IETF
*/
public TE_Information TE_info = new TE_Information();
/**
* Transmission delay of the link (just transmission)
*/
private double delay_ms;
/**
* Number of parallel fibers in the logical link.
*/
public int numFibers;
/**
* Characterization of local node
*
*/
public Node_Info Local_Node_Info;
/**
* Characterization of remote node
*
*/
public Node_Info Remote_Node_Info;
/**
* where have we leanrt the info from...
*/
private String learntFrom;
/**
* SID of the source node
*/
private int src_sid;
/**
* SID of the destination node
*/
private int dst_sid;
private String linkID=null;
private boolean isDirectional;
private String type=null;
private double temetric;
private Bandwidth bw=null;
public String getLinkID() {
return linkID;
}
public void setLinkID(String linkID) {
this.linkID = linkID;
}
public boolean isDirectional() {
return isDirectional;
}
public void setDirectional(boolean isDirectional) {
this.isDirectional = isDirectional;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public double getTemetric() {
return temetric;
}
public void setTemetric(double temetric) {
this.temetric = temetric;
}
public Bandwidth getBw() {
return bw;
}
public void setBw(Bandwidth bw) {
this.bw = bw;
}
public IntraDomainEdge()
{
TE_info = new TE_Information();
}
public Object getSource(){
Object source= (Object)super.getSource();
return source;
}
public Object getTarget(){
Object destination= (Object)super.getTarget();
return destination;
}
public long getSrc_if_id() {
return src_if_id;
}
public void setSrc_if_id(long src_if_id) {
this.src_if_id = src_if_id;
}
public long getDst_if_id() {
return dst_if_id;
}
public void setDst_if_id(long dst_if_id) {
this.dst_if_id = dst_if_id;
}
public TE_Information getTE_info() {
return TE_info;
}
public void setTE_info(TE_Information tE_info) {
TE_info = tE_info;
}
public double getDelay_ms() {
return delay_ms;
}
public void setDelay_ms(double delay_ms) {
this.delay_ms = delay_ms;
}
public int getNumberFibers() {
return numFibers;
}
public void setNumberFibers(int numFibers) {
this.numFibers = numFibers;
}
public Object getSrc_Numif_id() {
return src_Numif_id;
}
public void setSrc_Numif_id(Object srcNumifId) {
src_Numif_id = srcNumifId;
}
public Node_Info getLocal_Node_Info() {
return Local_Node_Info;
}
public void setLocal_Node_Info(Node_Info local_Node_Info) {
Local_Node_Info = local_Node_Info;
}
public Node_Info getRemote_Node_Info() {
return Remote_Node_Info;
}
public void setRemote_Node_Info(Node_Info remote_Node_Info) {
Remote_Node_Info = remote_Node_Info;
}
public Object getDst_Numif_id() {
return dst_Numif_id;
}
public void setDst_Numif_id(Object dstNumifId) {
dst_Numif_id = dstNumifId;
}
public String getLearntFrom() {
return learntFrom;
}
public void setLearntFrom(String leanrtFrom) {
this.learntFrom = leanrtFrom;
}
public int getSrc_sid() {
return src_sid;
}
public void setSrc_sid(int src_sid) {
this.src_sid = src_sid;
}
public int getDst_sid() {
return dst_sid;
}
public void setDst_sid(int dst_sid) {
this.dst_sid = dst_sid;
}
public String toString(){
String ret=this.getSource()+":"+this.getSrc_if_id()+"-->"+this.getTarget()+":"+this.getDst_if_id()+" NumFibers = "+numFibers;
if (TE_info==null){
return ret;
}
else
{
if ((this.TE_info.getAvailableLabels()!=null) &&(this.TE_info.getAvailableLabels().getLabelSet()!=null)){
ret=ret+" Bitmap: {";
for (int i=0;i<this.TE_info.getAvailableLabels().getLabelSet().getNumLabels();++i){
ret = ret+ (this.TE_info.isWavelengthFree(i)?"0":"1");
}
ret=ret+"}";
ret=ret+" Reserved: {";
for (int i=0;i<this.TE_info.getAvailableLabels().getLabelSet().getNumLabels();++i){
ret = ret+ (this.TE_info.isWavelengthUnreserved(i)?"0":"1");
}
ret=ret+"}";
ret = ret + "\r\n TED: " + this.TE_info.toString() + "\r\n";
return ret;
}else {
return ret + "\r\n TED: " + this.TE_info.toString() + "\r\n";
}
}
}
/*
@Override
public String toString() {
return "IntraDomainEdge [src_if_id=" + src_if_id + ", dst_if_id="
+ dst_if_id + ", src_Numif_id=" + src_Numif_id
+ ", dst_Numif_id=" + dst_Numif_id + ", TE_info=" + TE_info
+ ", delay_ms=" + delay_ms + ", numFibers=" + numFibers + "]";
}*/
}
\ No newline at end of file
// Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package eu.teraflow.tid.tedb;
import java.net.Inet4Address;
import org.jgrapht.graph.DefaultWeightedEdge;
/**
* IntraDomain Edge of a Traffic Engineering Database.
* @author ogondio, msc
*
*/
public class IntraDomainWeightEdge extends DefaultWeightedEdge {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Interface ID of the outgoing interface from the source
*/
public long src_if_id;
/**
* Interface ID of the incoming interface from the destination
*/
public long dst_if_id;
/**
* Traffic engineering information, as defined in IETF
*/
public TE_Information TE_info;
/**
* Transmission delay of the link (just transmission)
*/
private double delay_ms;
public IntraDomainWeightEdge(){
}
public Inet4Address getSource(){
Inet4Address source= (Inet4Address)super.getSource();
return source;
}
public Inet4Address getTarget(){
Inet4Address destination= (Inet4Address)super.getTarget();
return destination;
}
public long getSrc_if_id() {
return src_if_id;
}
public void setSrc_if_id(long src_if_id) {
this.src_if_id = src_if_id;
}
public long getDst_if_id() {
return dst_if_id;
}
public void setDst_if_id(long dst_if_id) {
this.dst_if_id = dst_if_id;
}
public TE_Information getTE_info() {
return TE_info;
}
public void setTE_info(TE_Information tE_info) {
TE_info = tE_info;
}
public double getDelay_ms() {
return delay_ms;
}
public void setDelay_ms(double delay_ms) {
this.delay_ms = delay_ms;
}
public String toString(){
String ret=this.getSource()+":"+this.getSrc_if_id()+"-->"+this.getTarget()+":"+this.getDst_if_id();
if (TE_info==null){
return ret;
}
else
{
if (this.TE_info.getAvailableLabels()!=null){
ret=ret+" Bitmap: {";
for (int i=0;i<this.TE_info.getAvailableLabels().getLabelSet().getNumLabels();++i){
ret = ret+ (this.TE_info.isWavelengthFree(i)?"0":"1");
}
ret=ret+"}";
ret=ret+" Reserved: {";
for (int i=0;i<this.TE_info.getAvailableLabels().getLabelSet().getNumLabels();++i){
ret = ret+ (this.TE_info.isWavelengthUnreserved(i)?"0":"1");
}
ret=ret+"}";
return ret;
}else {
return ret;
}
}
}
}
// Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package eu.teraflow.tid.tedb;
public class Layer {
/**
* True if it is a GMPLS layer
* False if it is an IP/MPLS layer (by default, false)
*/
public boolean gmpls=false;
/**
*
*/
public int encodingType;
/**
*
*/
public int switchingType;
public static final int SWITCHING_TYPE_WSON=150;
}
// Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package eu.teraflow.tid.tedb;
import org.jgrapht.graph.DirectedWeightedMultigraph;
import org.jgrapht.graph.SimpleDirectedWeightedGraph;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.Inet4Address;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Set;
/**
* Base de datos de ingenieria de trafico
* CLASE DE PRUEBA REESTRUCTURAR DESPUES!!!!!!!!!!
* @author ogondio
*
*/
public class MDTEDB implements MultiDomainTEDB {
private long graphId;
private DirectedWeightedMultigraph<Object,InterDomainEdge> networkDomainGraph;
public SimpleDirectedWeightedGraph<Object,IntraDomainEdge> networkGraph;
//private LinkedList<InterDomainEdge> interDomainLinks;
public SimpleTEDB simple_ted;
private Logger log;
private boolean addBidirectional;
/**
* Table with IP address/prefix --> domain
*/
LinkedList<ReachabilityEntry> reachability;
public MDTEDB(){
log=LoggerFactory.getLogger("BGP4Peer");
networkDomainGraph=new DirectedWeightedMultigraph<Object,InterDomainEdge> (InterDomainEdge.class);
addBidirectional=true;//FIXME: ESTO ES UN APA�O TEMPORAL
reachability=new LinkedList<ReachabilityEntry>();
//interDomainLinks = new LinkedList<InterDomainEdge>();
}
public DirectedWeightedMultigraph<Object,InterDomainEdge> getDuplicatedMDNetworkGraph(){
DirectedWeightedMultigraph<Object,InterDomainEdge> graphCopy= (DirectedWeightedMultigraph<Object, InterDomainEdge>) networkDomainGraph.clone();
return graphCopy;
}
public DirectedWeightedMultigraph<Object, InterDomainEdge> getNetworkDomainGraph() {
return networkDomainGraph;
}
public void setNetworkDomainGraph(
DirectedWeightedMultigraph<Object, InterDomainEdge> networkDomainGraph) {
this.networkDomainGraph = networkDomainGraph;
}
public void initializeFromFile(String file){
networkDomainGraph=FileTEDBUpdater.readMDNetwork(file);
}
public void initializeFromFile(String file, String learntFrom){
networkDomainGraph=FileTEDBUpdater.readMDNetwork(file, learntFrom);
}
public void initializeFromFileInterDomainLinks(String file){
}
public void initializeFullTEDFromFile(String file){
networkGraph=FileTEDBUpdater.readNetwork(file);
}
public long getGraphId() {
return graphId;
}
public void setGraphId(long graphId) {
this.graphId = graphId;
}
public SimpleDirectedWeightedGraph<Object, IntraDomainEdge> getDuplicatedNetworkGraph() {
return networkGraph;
}
public synchronized void addInterdomainLink( Object localDomainID, Object localRouterASBR, long localRouterASBRIf, Object remoteDomainID, Object remoteRouterASBR, long remoteRouterASBRIf, TE_Information te_info){
if (!networkDomainGraph.containsVertex(localDomainID)){
networkDomainGraph.addVertex(localDomainID);
log.debug("Vertex (domain) "+localDomainID+" added");
}
if (!networkDomainGraph.containsVertex(remoteDomainID)){
networkDomainGraph.addVertex(remoteDomainID);
log.debug("Vertex (domain) "+remoteDomainID+" added");
}
log.debug("Looking to add "+localRouterASBR+":"+localRouterASBRIf+" ("+localDomainID+") -->"+remoteRouterASBR+":"+remoteRouterASBRIf+" ("+remoteDomainID+")");
Set<InterDomainEdge> edgeset= networkDomainGraph.edgesOf(localDomainID);
Iterator <InterDomainEdge> iterador=edgeset.iterator();
boolean edgeFound=false;
InterDomainEdge interDomainEdgeFound=null;
if (edgeset.size() == 0)
log.debug("Edge set size = 0");
while (iterador.hasNext()){
InterDomainEdge interDomainEdge=iterador.next();
log.debug("existing edge: "+interDomainEdge.toString());
if (interDomainEdge.getSrc_router_id().equals(localRouterASBR)){
log.debug("Local router is the same!!!");
if (interDomainEdge.getDst_router_id().equals(remoteRouterASBR)){
log.debug("Destination router is the same!!!");
edgeFound=true;
interDomainEdgeFound=interDomainEdge;
}
else {
log.debug("Destination router is NOT the same!!!");
}
}else {
log.debug("Local router is NOT the same!!!");
}
}
if (edgeFound==false) {
InterDomainEdge newInterDomainEdge =new InterDomainEdge();
newInterDomainEdge.setSrc_router_id(localRouterASBR);
newInterDomainEdge.setDst_router_id(remoteRouterASBR);
newInterDomainEdge.setSrc_if_id(localRouterASBRIf);
newInterDomainEdge.setDst_if_id(remoteRouterASBRIf);
newInterDomainEdge.setDomain_dst_router(remoteDomainID);
newInterDomainEdge.setDomain_src_router(localDomainID);
if (te_info != null)
newInterDomainEdge.setTE_info(te_info);
networkDomainGraph.addEdge(localDomainID, remoteDomainID, newInterDomainEdge);
log.info("New interdomain edge between "+localDomainID+" and "+remoteDomainID+" received");
}else {
if (te_info != null){
//FIXME: Update of TE info to be optimized
log.debug("TE_info updated");
interDomainEdgeFound.setTE_info(te_info);
}
}
}
public void addReachabilityIPv4(Inet4Address domainId,Inet4Address aggregatedIPRange,int prefix){
ReachabilityEntry ra=new ReachabilityEntry();
ra.setAggregatedIPRange(aggregatedIPRange);
long resta=((long)0x1<<prefix)-1;
long maskLong=resta<<(32-prefix);
byte[] mask=new byte[4];
mask[0]=(byte)(maskLong>>>24 & 0xFF);
mask[1]=(byte)(maskLong>>>16 & 0xFF);
mask[2]=(byte)(maskLong>>>8 & 0xFF);
mask[3]=(byte)(maskLong& 0xFF);
ra.setMask(mask);
ra.setDomainId(domainId);
ra.setPrefix(prefix);
if (!(reachability.contains(ra))){
reachability.add(ra);
}
return;
}
public String printMDTopology(){
String topoString;
Set<Object> vetexSet= networkDomainGraph.vertexSet();
Iterator <Object> vertexIterator=vetexSet.iterator();
topoString="Domains: \r\n";
while (vertexIterator.hasNext()){
Object vertex= vertexIterator.next();
topoString=topoString+"\t"+vertex.toString()+"\r\n";
}
topoString=topoString+"Interdomain list: \r\n";
Set<InterDomainEdge> edgeSet= networkDomainGraph.edgeSet();
Iterator <InterDomainEdge> edgeIterator=edgeSet.iterator();
while (edgeIterator.hasNext()){
InterDomainEdge edge= edgeIterator.next();
topoString=topoString+"\t"+edge.toString()+"\r\n";
}
return topoString;
}
// public String printMD2Topology(){
// String topoString;
// Set<Object> vetexSet= networkDomainGraph.vertexSet();
// Iterator <Object> vertexIterator=vetexSet.iterator();
// topoString="Domains: \r\n";
// while (vertexIterator.hasNext()){
// Object vertex= vertexIterator.next();
// topoString=topoString+"\t"+vertex.toString()+"\r\n";
// }
// topoString=topoString+"Interdomain list: \r\n";
// Iterator <InterDomainEdge> edgeIterator=interDomainLinks.iterator();
// while (edgeIterator.hasNext()){
// InterDomainEdge edge= edgeIterator.next();
// topoString=topoString+"\t"+edge.toString()+"\r\n";
// }
//
// return topoString;
// }
//Check resources SSON and WSON
public boolean CheckLocalResources(long ifID, Object ip){
Iterator<InterDomainEdge> iteredges = networkDomainGraph.edgeSet().iterator();
InterDomainEdge link;
while (iteredges.hasNext())
{
link = iteredges.next();
if ((link.getSrc_if_id()==(ifID)))
{
log.info("InterDomain Link Found to "+link.getDst_router_id().toString());
return true;
}
}
return false;
}
@Override
public String printTopology() {
// TODO Auto-generated method stub
return printMDTopology();
}
public LinkedList<InterDomainEdge> getInterDomainLinks() {
return new LinkedList<InterDomainEdge>(networkDomainGraph.edgeSet());
}
@Override
public boolean isITtedb() {
// TODO Auto-generated method stub
return false;
}
public SimpleTEDB getSimple_ted() {
return simple_ted;
}
public void setSimple_ted(SimpleTEDB simple_ted) {
this.simple_ted = simple_ted;
}
public LinkedList<ReachabilityEntry> getReachability() {
return reachability;
}
public void setReachability(LinkedList<ReachabilityEntry> reachability) {
this.reachability = reachability;
}
}
// Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package eu.teraflow.tid.tedb;
import java.net.Inet4Address;
public interface MultiDomainTEDB extends TEDB {
public void addInterdomainLink( Object localDomainID, Object localRouterASBR, long localRouterASBRIf, Object remoteDomainID, Object remoteRouterASBR, long remoteRouterASBRIf, TE_Information te_info );
public void addReachabilityIPv4(Inet4Address domainId,Inet4Address aggregatedIPRange,int prefix);
}
// Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package eu.teraflow.tid.tedb;
import es.tid.ospf.ospfv2.lsa.tlv.subtlv.complexFields.BitmapLabelSet;
import org.jgrapht.graph.SimpleDirectedWeightedGraph;
import java.net.Inet4Address;
import java.util.*;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
public class MultiLayerTEDB implements DomainTEDB {
private ArrayList<TEDListener> registeredAlgorithms;
/**
* Graph of the Upper Layer Network
*/
/**
*
*/
private SimpleDirectedWeightedGraph<Object,IntraDomainEdge> upperLayerGraph;
/**
* Graph of the Upper Layer Network
*/
private SimpleDirectedWeightedGraph<Object,IntraDomainEdge> lowerLayerGraph;
/**
* InterLayer Graph
*/
private SimpleDirectedWeightedGraph<Object,IntraDomainEdge> interLayerGraph;
/**
* Reachability information
*/
private ReachabilityEntry reachabilityEntry;
/**
* WSON Information of the lower Layer
*/
private WSONInformation WSONinfo=null;
private Lock TEDBlock;
/**
* List of interdomain Links
*/
private LinkedList<InterDomainEdge> interDomainLinks;
private Hashtable<Object,Object> RelationNodesInterlayer;
public MultiLayerTEDB(){
registeredAlgorithms= new ArrayList<TEDListener>();
TEDBlock=new ReentrantLock();
}
public SimpleDirectedWeightedGraph<Object, IntraDomainEdge> getUpperLayerGraph() {
return upperLayerGraph;
}
public void setUpperLayerGraph(
SimpleDirectedWeightedGraph<Object, IntraDomainEdge> upperLayerGraph) {
this.upperLayerGraph = upperLayerGraph;
}
public SimpleDirectedWeightedGraph<Object, IntraDomainEdge> getLowerLayerGraph() {
return lowerLayerGraph;
}
public void setLowerLayerGraph(
SimpleDirectedWeightedGraph<Object, IntraDomainEdge> lowerLayerGraph) {
this.lowerLayerGraph = lowerLayerGraph;
}
public SimpleDirectedWeightedGraph<Object, IntraDomainEdge> getInterLayerGraph() {
return interLayerGraph;
}
public void setInterLayerGraph(
SimpleDirectedWeightedGraph<Object, IntraDomainEdge> interLayerGraph) {
this.interLayerGraph = interLayerGraph;
}
public SimpleDirectedWeightedGraph<Object,IntraDomainEdge> getDuplicatedUpperLayerkGraph(){
SimpleDirectedWeightedGraph<Object,IntraDomainEdge> graphCopy;
TEDBlock.lock();
try{
graphCopy= (SimpleDirectedWeightedGraph<Object, IntraDomainEdge>) upperLayerGraph.clone();
} finally{
TEDBlock.unlock();
}
return graphCopy;
}
public Hashtable<Object, Object> getRelationNodesInterlayer() {
return RelationNodesInterlayer;
}
public SimpleDirectedWeightedGraph<Object,IntraDomainEdge> getDuplicatedLowerLayerkGraph(){
SimpleDirectedWeightedGraph<Object,IntraDomainEdge> graphCopy;
TEDBlock.lock();
try{
graphCopy= (SimpleDirectedWeightedGraph<Object, IntraDomainEdge>) lowerLayerGraph.clone();
} finally{
TEDBlock.unlock();
}
return graphCopy;
}
public SimpleDirectedWeightedGraph<Object,IntraDomainEdge> getDuplicatedInterLayerGraph(){
SimpleDirectedWeightedGraph<Object,IntraDomainEdge> graphCopy;
TEDBlock.lock();
try{
graphCopy= (SimpleDirectedWeightedGraph<Object, IntraDomainEdge>) interLayerGraph.clone();
} finally{
TEDBlock.unlock();
}
return graphCopy;
}
public void initializeFromFile(String file) {
upperLayerGraph=FileTEDBUpdater.readNetwork(file, "mpls");
lowerLayerGraph=FileTEDBUpdater.readNetwork(file, "wson");
interLayerGraph=FileTEDBUpdater.readNetwork(file, "interlayer");
WSONinfo = FileTEDBUpdater.getWSONInformation(file, "wson");
interDomainLinks = FileTEDBUpdater.readInterDomainLinks(file);
reachabilityEntry = new ReachabilityEntry();
//domainReachabilityIPv4Prefix=new byte[4];
FileTEDBUpdater.getDomainReachabilityFromFile(file,reachabilityEntry,"mpls");
}
@Override
public void initializeFromFile(String file, String learnFrom) {
}
@Override
public boolean isITtedb() {
// TODO Auto-generated method stub
return false;
}
@Override
public String printTopology() {
String topoString;
Set<Object> vetexSet= upperLayerGraph.vertexSet();
Iterator <Object> vertexIterator=vetexSet.iterator();
topoString="MPLS Nodes: \r\n";
while (vertexIterator.hasNext()){
Object vertex= vertexIterator.next();
topoString=topoString+"\t"+vertex.toString()+"\r\n";
}
topoString=topoString+"MPLS Link list: \r\n";
Set<IntraDomainEdge> edgeSet= upperLayerGraph.edgeSet();
Iterator <IntraDomainEdge> edgeIterator=edgeSet.iterator();
while (edgeIterator.hasNext()){
IntraDomainEdge edge= edgeIterator.next();
topoString=topoString+"\t"+edge.toString()+"\r\n";
}
vetexSet= lowerLayerGraph.vertexSet();
vertexIterator=vetexSet.iterator();
topoString="GMPLS Nodes: \r\n";
while (vertexIterator.hasNext()){
Object vertex= vertexIterator.next();
topoString=topoString+"\t"+vertex.toString()+"\r\n";
}
topoString=topoString+"gmpls Link list: \r\n";
edgeSet= lowerLayerGraph.edgeSet();
edgeIterator=edgeSet.iterator();
while (edgeIterator.hasNext()){
IntraDomainEdge edge= edgeIterator.next();
topoString=topoString+"\t"+edge.toString()+"\r\n";
}
topoString=topoString+"InterLayer list: \r\n";
edgeSet= interLayerGraph.edgeSet();
edgeIterator=edgeSet.iterator();
while (edgeIterator.hasNext()){
IntraDomainEdge edge= edgeIterator.next();
topoString=topoString+"\t"+edge.toString()+"\r\n";
}
topoString=topoString+printInterDomainLinks();
return topoString;
}
@Override
public boolean belongsToDomain(Object addr) {
int i;
byte[] addrbytes= ((Inet4Address)addr).getAddress();
for (i=0;i<4;++i){
addrbytes[i]=(byte) (addrbytes[i]&(reachabilityEntry.getMask())[i]);
}
return Arrays.equals(addrbytes,reachabilityEntry.getAggregatedIPRange().getAddress());
}
public ReachabilityEntry getReachabilityEntry() {
return reachabilityEntry;
}
public LinkedList<InterDomainEdge> getInterDomainLinks() {
return interDomainLinks;
}
@Override
public String printInterDomainLinks(){
String topoString="";
int size = interDomainLinks.size();
topoString="Interdomain Link list: \r\n";
for (int i=0;i<size;i++){
//por pantalla
InterDomainEdge edge = interDomainLinks.get(i);
topoString=topoString+"\t"+edge.toString()+"\r\n";
}
return topoString;
}
public boolean containsVertex(Object vertex) {
return upperLayerGraph.containsVertex(vertex);
}
public WSONInformation getWSONinfo() {
return WSONinfo;
}
@Override
public void notifyWavelengthReservation(LinkedList<Object> sourceVertexList, LinkedList<Object> targetVertexList, int wavelength, boolean bidirectional){
TEDBlock.lock();
try {
for (int i=0;i<sourceVertexList.size();++i){
IntraDomainEdge edge=lowerLayerGraph.getEdge(sourceVertexList.get(i), targetVertexList.get(i));
edge.getTE_info().setWavelengthReserved(wavelength);
if (bidirectional == true){
edge=lowerLayerGraph.getEdge(targetVertexList.get(i), sourceVertexList.get(i));
edge.getTE_info().setWavelengthReserved(wavelength);
}
}
}finally{
TEDBlock.unlock();
}
for (int i=0;i<registeredAlgorithms.size();++i){
registeredAlgorithms.get(i).notifyWavelengthReservation(sourceVertexList, targetVertexList, wavelength);
if (bidirectional == true){
registeredAlgorithms.get(i).notifyWavelengthReservation(targetVertexList, sourceVertexList, wavelength);
}
}
}
@Override
public void notifyWavelengthEndReservation(LinkedList<Object> sourceVertexList, LinkedList<Object> targetVertexList, int wavelength, boolean bidirectional){
// TODO Auto-generated method stub
//Delete the resource reservation
TEDBlock.lock();
try {
for (int i=0;i<sourceVertexList.size();++i){
// SimpleDirectedWeightedGraph<Object,FiberLinkEdge> graph= ted.getNetworkGraph();
IntraDomainEdge edge=lowerLayerGraph.getEdge(sourceVertexList.get(i),targetVertexList.get(i) );
edge.getTE_info().setWavelengthUnReserved(wavelength);
if (bidirectional == true)
{
edge=lowerLayerGraph.getEdge(targetVertexList.get(i), sourceVertexList.get(i));
edge.getTE_info().setWavelengthUnReserved(wavelength);
}
}
}finally{
TEDBlock.unlock();
}
for (int i=0;i<registeredAlgorithms.size();++i){
registeredAlgorithms.get(i).notifyWavelengthEndReservation(sourceVertexList, targetVertexList, wavelength);
if (bidirectional == true)
{
registeredAlgorithms.get(i).notifyWavelengthEndReservation(targetVertexList, sourceVertexList, wavelength);
}
}
//FIXME:TEMPORAL!!!!!!
//requestDispatcher.moveRetryQueueToComputingRequestQueue();
//Call request dispatcher to pass requests to queue?
}
@Override
public void notifyWavelengthChange(Object localInterfaceIPAddress, Object remoteInterfaceIPAddress, BitmapLabelSet previousBitmapLabelSet, BitmapLabelSet newBitmapLabelSet) {
for (int i=0;i<registeredAlgorithms.size();++i){
registeredAlgorithms.get(i).notifyWavelengthStatusChange(localInterfaceIPAddress, remoteInterfaceIPAddress, previousBitmapLabelSet, newBitmapLabelSet);
}
}
@Override
public void register(TEDListener compAlgPreComp) {
registeredAlgorithms.add(compAlgPreComp);
}
@Override
public void notifyNewVertex(Object vertex) {
for (int i=0;i<registeredAlgorithms.size();++i){
registeredAlgorithms.get(i).notifyNewVertex(vertex);
}
}
@Override
public void notifyNewEdge(Object source, Object destination) {
for (int i=0;i<registeredAlgorithms.size();++i){
registeredAlgorithms.get(i).notifyNewEdge(source,destination);
}
}
@Override
public void clearAllReservations() {
if (WSONinfo!=null){
TEDBlock.lock();
try{
Set<IntraDomainEdge> edgeSet= lowerLayerGraph.edgeSet();
Iterator <IntraDomainEdge> edgeIterator=edgeSet.iterator();
while (edgeIterator.hasNext()){
IntraDomainEdge edge= edgeIterator.next();
edge.TE_info.setAllWavelengtshUnReserved();
}
}finally{
TEDBlock.unlock();
}
for (int i=0;i<registeredAlgorithms.size();++i){
registeredAlgorithms.get(i).notifyTEDBFullUpdate();
}
}
}
@Override
public void notifyNewEdgeIP(Object source, Object destination, TE_Information informationTEDB) {
for (int i=0;i<registeredAlgorithms.size();++i){
registeredAlgorithms.get(i).notifyNewEdgeIP(source,destination, informationTEDB);
}
}
public void notificationEdgeIP_AuxGraph(Object src, Object dst, TE_Information informationTEDB) {
for (int i=0;i<registeredAlgorithms.size();++i){
registeredAlgorithms.get(i).notificationEdgeIP_AuxGraph(src,dst, informationTEDB);
}
}
public void notificationEdgeOPTICAL_AuxGraph(Object src, Object dst, int lambda) {
for (int i=0;i<registeredAlgorithms.size();++i){
registeredAlgorithms.get(i).notificationEdgeOPTICAL_AuxGraph(src, dst, lambda);
}
}
@Override
public void notifyWavelengthEndReservationSSON(
LinkedList<Object> sourceVertexList,
LinkedList<Object> targetVertexList, int wavelength,
boolean bidirectional, int m) {
// TODO Auto-generated method stub
}
@Override
public void notifyWavelengthReservationSSON(
LinkedList<Object> sourceVertexList,
LinkedList<Object> targetVertexList, int wavelength,
boolean bidirectional, int m) {
// TODO Auto-generated method stub
}
@Override
public SSONInformation getSSONinfo() {
// TODO Auto-generated method stub
return null;
}
@Override
public Set<IntraDomainEdge> getIntraDomainLinks() {
// TODO Auto-generated method stub
return null;
}
@Override
public void notifyWavelengthReservationWLAN(
LinkedList<Object> sourceVertexList,
LinkedList<Object> targetVertexList,
LinkedList<Integer> wlans, boolean bidirectional) {
// TODO Auto-generated method stub
}
@Override
public void registerSSON(SSONListener compAlgPreComp) {
// TODO Auto-generated method stub
}
@Override
public Inet4Address getDomainID() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setWSONinfo(WSONInformation wSONinfo) {
// TODO Auto-generated method stub
}
@Override
public void setSSONinfo(SSONInformation sSONinfo) {
// TODO Auto-generated method stub
}
@Override
public void createGraph() {
// TODO Auto-generated method stub
}
@Override
public Set<Object> getIntraDomainLinksvertexSet() {
// TODO Auto-generated method stub
return null;
}
@Override
public Hashtable<Object, Node_Info> getNodeTable() {
// TODO Auto-generated method stub
return null;
}
@Override
public IT_Resources getItResources() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setItResources(IT_Resources itResources) {
// TODO Auto-generated method stub
}
}