org.renci.ahab.libndl.SliceGraph Maven / Gradle / Ivy
/*
* Copyright (c) 2011 RENCI/UNC Chapel Hill
*
* @author Ilia Baldine
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and/or hardware specification (the "Work") to deal in the Work without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Work, and to permit persons to whom the Work is furnished to do so, subject to
* the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Work.
*
* THE WORK IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE WORK OR THE USE OR OTHER DEALINGS
* IN THE WORK.
*/
package org.renci.ahab.libndl;
import java.awt.Dialog.ModalExclusionType;
import java.io.File;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.apache.log4j.Logger;
import org.renci.ahab.libndl.ndl.ExistingSliceModel;
import org.renci.ahab.libndl.ndl.ManifestLoader;
import org.renci.ahab.libndl.ndl.ModifyGenerator;
import org.renci.ahab.libndl.ndl.NDLModel;
import org.renci.ahab.libndl.ndl.NewSliceModel;
import org.renci.ahab.libndl.ndl.RequestGenerator;
import org.renci.ahab.libndl.ndl.RequestLoader;
import org.renci.ahab.libndl.resources.common.ModelResource;
import org.renci.ahab.libndl.resources.manifest.LinkConnection;
import org.renci.ahab.libndl.resources.manifest.ManifestResource;
import org.renci.ahab.libndl.resources.request.BroadcastNetwork;
import org.renci.ahab.libndl.resources.request.ComputeNode;
import org.renci.ahab.libndl.resources.request.Interface;
import org.renci.ahab.libndl.resources.request.InterfaceNode2Net;
import org.renci.ahab.libndl.resources.request.Network;
import org.renci.ahab.libndl.resources.request.Node;
import org.renci.ahab.libndl.resources.request.RequestReservationTerm;
import org.renci.ahab.libndl.resources.request.RequestResource;
import org.renci.ahab.libndl.resources.request.StitchPort;
import org.renci.ahab.libndl.resources.request.StorageNode;
import org.renci.ahab.libndl.util.IP4Assign;
import org.renci.ahab.libndl.util.IP4Subnet;
import orca.ndl.NdlCommons;
import edu.uci.ics.jung.graph.SparseMultigraph;
/**
* Singleton class that holds shared NDLLIB request state. Since dialogs are all modal, no need for locking for now.
* @author ibaldin
* @author pruth
*
*/
public class SliceGraph {
private Slice slice;
private NDLModel ndlModel;
private SparseMultigraph sliceGraph = new SparseMultigraph();
private SparseMultigraph manifestGraph = new SparseMultigraph();
private String rawLoadedRDF; //original rdf loaded. used for reseting uncommited modifies
//Obeject for managing subnets for autoIP functionallity
private IP4Assign ipAssign;
private static final String IMAGE_NAME_SUFFIX = "-req";
public static final String NO_GLOBAL_IMAGE = "None";
public static final String NO_DOMAIN_SELECT = "System select";
public static final String NODE_TYPE_SITE_DEFAULT = "Site default";
public static final String NO_NODE_DEPS="No dependencies";
private static final String RDF_START = " resources = new HashSet(sliceGraph.getVertices());
for (ModelResource r: resources)
sliceGraph.removeVertex(r);
resDomainName = null;
term = new RequestReservationTerm();
ofNeededVersion = null;
ofUserEmail = null;
ofSlicePass = null;
ofCtrlUrl = null;
nsGuid = null;
saveFile = null;
rawLoadedRDF = null;
ipAssign = new IP4Assign();
}
public Collection getResources(){
return sliceGraph.getVertices();
}
protected SparseMultigraph getGraph() {
return sliceGraph;
}
public void printGraph() {
LIBNDL.logger().debug("JUNG Graph: " + sliceGraph);
}
//public boolean isNewRequest(){
// return true;
//}
public NDLModel getNDLModel(){
if(ndlModel == null) LIBNDL.logger().debug("SliceGraph.getNDLModel ndlModel is null");
return ndlModel;
}
/************************************* Add/Delete/Get resources ************************************/
public void increaseComputeNodeCount(ComputeNode node, int addCount){
//modify.addNodesToGroup(node.getModelResource().getURI(), addCount);
}
//deletes the node at uri from the group node
public void deleteComputeNode(ComputeNode node, String uri){
LIBNDL.logger().debug("Request.deleteComputeNode: node = " + node + ", uri = " + uri);
//modify.removeNodeFromGroup(node.getURI(), uri);
}
/************ Build resources in jung model without adding to ndlmodel **********/
public ComputeNode buildComputeNode(String name){
LIBNDL.logger().debug("PRUTH_BUILD: SliceGraph.buildComputeNode: adding node " + name);
ComputeNode node = new ComputeNode(this,name);
sliceGraph.addVertex(node);
return node;
}
public StorageNode buildStorageNode(String name){
LIBNDL.logger().debug("PRUTH_BUILD: SliceGraph.buildStorageNode: adding node " + name);
StorageNode node = new StorageNode(this,name);
sliceGraph.addVertex(node);
return node;
}
public StitchPort buildStitchPort(String name, String label, String port, long bandwidth){
StitchPort node = new StitchPort(this,name,label,port,bandwidth);
sliceGraph.addVertex(node);
return node;
}
public BroadcastNetwork buildLink(String name){
BroadcastNetwork link = new BroadcastNetwork(this,name);
sliceGraph.addVertex(link);
return link;
}
public BroadcastNetwork buildBroadcastLink(String name){
BroadcastNetwork link = new BroadcastNetwork(this,name);
sliceGraph.addVertex(link);
return link;
}
public InterfaceNode2Net buildInterfaceNode2Net(Node node, Network net){
LIBNDL.logger().debug("PRUTH_BUILD_INTERFACE: " + node + ", " + net);
InterfaceNode2Net i = new InterfaceNode2Net(node,net,this);
sliceGraph.addEdge(i, node, net);
return i;
}
/************************ build resources and add them to ndl model ************/
public ComputeNode addComputeNode(String name){
ComputeNode node = buildComputeNode(name);
node.setIsNew(true);
ndlModel.add(node,name);
return node;
}
public StorageNode addStorageNode(String name){
StorageNode node = buildStorageNode(name);
node.setIsNew(true);
ndlModel.add(node, name);
return node;
}
public StitchPort addStitchPort(String name, String label, String port, long bandwidth){
StitchPort node = buildStitchPort(name, label, port, bandwidth);
node.setIsNew(true);
ndlModel.add(node, name, label, port);
return node;
}
public Network addLink(String name, long bandwidth){
BroadcastNetwork link = buildLink(name);
link.setIsNew(true);
ndlModel.add(link, name, bandwidth);
return link;
}
public BroadcastNetwork addBroadcastLink(String name, long bandwidth){
BroadcastNetwork link = buildBroadcastLink(name);
link.setIsNew(true);
ndlModel.add(link, name, bandwidth);
return link;
}
public void addStitch(RequestResource a, RequestResource b, Interface s){
if(s instanceof InterfaceNode2Net){
ndlModel.add((InterfaceNode2Net)s);
}
sliceGraph.addEdge(s, a, b);
}
public RequestResource getResourceByName(String nm){
if (nm == null)
return null;
LIBNDL.logger().debug("RAW jung graph: " + sliceGraph);
for (ModelResource n: sliceGraph.getVertices()) {
if (nm.equals(n.getName()) && n instanceof RequestResource){
return (RequestResource)n;
}
}
return null;
}
public RequestResource getResourceByURI(String uri){
LIBNDL.logger().debug("getResourceByURI: " + uri);
if (uri == null)
return null;
LIBNDL.logger().debug("getResourceByURI: " + sliceGraph);
for (ModelResource n: sliceGraph.getVertices()) {
LIBNDL.logger().debug("getResourceByURI: " + n.getName());
//LIBNDL.logger().debug("getResourceByURI: " + n.getURI());
//if (n.getURI() != null && uri.equals(n.getURI()) && n instanceof RequestResource){
// LIBNDL.logger().debug("getResourceByURI: returning " + n.getName());
// return (RequestResource)n;
//}
}
return null;
}
public void deleteResource(ComputeNode node){
ndlModel.remove(node);
deleteResource((RequestResource)node);
}
public void deleteResource(BroadcastNetwork bn){
for (Interface i: bn.getInterfaces()){
this.deleteResource(i);
}
ndlModel.remove(bn);
sliceGraph.removeVertex(bn);
deleteResource((RequestResource)bn);
}
//XXXXXXXXXXXXXXXXXX Should be private XXXXXXXXXXXXXXXXXXX
public void deleteResource(RequestResource requestResource){
//for (Interface i: requestResource.getInterfaces()){
// this.deleteResource(i);
//}
sliceGraph.removeVertex(requestResource);
//deleteResource((RequestResource)requestResource);
}
public void deleteResource(Interface i){
//TODO: Only handles InterfaceNode2Net for now
ndlModel.remove((InterfaceNode2Net)i);
sliceGraph.removeEdge(i);
}
public Collection getInterfaces(){
ArrayList interfaces = new ArrayList();
for (Interface i: sliceGraph.getEdges()) {
if (i instanceof Interface){
interfaces.add((Interface)i);
}
}
return interfaces;
}
public Collection getInterfaces(RequestResource r){
return sliceGraph.getIncidentEdges(r);
}
public void clear(){
//reset the whole request
}
/************************************* Request level properties: domain,term,user, etc. ************************************/
public RequestReservationTerm getTerm() {
return term;
}
public void setTerm(RequestReservationTerm t) {
term = t;
}
public void setNsGuid(String g) {
nsGuid = g;
}
public void setOfUserEmail(String ue) {
ofUserEmail = ue;
}
public String getOfUserEmail() {
return ofUserEmail;
}
public void setOfSlicePass(String up) {
ofSlicePass = up;
}
public String getOfSlicePass() {
return ofSlicePass;
}
public void setOfCtrlUrl(String cu) {
ofCtrlUrl = cu;
}
public String getOfCtrlUrl() {
return ofCtrlUrl;
}
/************************************** Add/remove resources *******************************/
public Collection getLinks(){
ArrayList links = new ArrayList();
for (ModelResource resource: sliceGraph.getVertices()) {
if(resource instanceof Network){
links.add((Network)resource);
}
}
return links;
}
public Collection getBroadcastLinks(){
ArrayList broadcastlinks = new ArrayList();
for (ModelResource resource: sliceGraph.getVertices()) {
if(resource instanceof BroadcastNetwork){
broadcastlinks.add((BroadcastNetwork)resource);
}
}
return broadcastlinks;
}
public Collection getNodes(){
ArrayList nodes = new ArrayList();
for (ModelResource resource: sliceGraph.getVertices()) {
if(resource instanceof Node){
nodes.add((Node)resource);
}
}
return nodes;
}
public Collection getComputeNodes(){
ArrayList nodes = new ArrayList();
for (ModelResource resource: sliceGraph.getVertices()) {
if(resource instanceof ComputeNode){
nodes.add((ComputeNode)resource);
}
}
return nodes;
}
public Collection getStorageNodes(){
ArrayList nodes = new ArrayList();
for (ModelResource resource: sliceGraph.getVertices()) {
if(resource instanceof StorageNode){
nodes.add((StorageNode)resource);
}
}
return nodes;
}
public Collection getStitchPorts(){
ArrayList nodes = new ArrayList();
for (ModelResource resource: sliceGraph.getVertices()) {
if(resource instanceof StitchPort){
nodes.add((StitchPort)resource);
}
}
return nodes;
}
/************************************* AutoIP mthrow e;ethods ************************************/
public IP4Subnet setSubnet(String ip, int maskLength){
IP4Subnet subnet = null;
try{
subnet = ipAssign.getSubnet((Inet4Address)InetAddress.getByName(ip), maskLength);
subnet.markIPUsed(subnet.getStartIP());
} catch (Exception e){
LIBNDL.logger().warn("setSubnet warning: " + e);
}
return subnet;
}
public IP4Subnet allocateSubnet(int count){
IP4Subnet subnet = null;
try{
subnet = ipAssign.getAvailableSubnet(count);
subnet.markIPUsed(subnet.getStartIP());
} catch (Exception e){
LIBNDL.logger().warn("allocateSubnet warning: " + e);
}
return subnet;
}
public void autoIP(){
LIBNDL.logger().debug("autoIP unimplemented");
}
/************************************* RDF Functions: save, load, getRDFString, etc. ************************************/
public void loadNewRequest(){
rawLoadedRDF = "New Request";
NewSliceModel model = new NewSliceModel();
model.init(this);
this.ndlModel = model;
}
public void loadRequestRDF(String rdf){
rawLoadedRDF = rdf;
this.ndlModel = new NewSliceModel();
this.ndlModel.init(this,rdf);
}
public void loadManifestRDF(String rdf){
LIBNDL.logger().debug("SliceGraph::loadManifestRDF");
rawLoadedRDF = rdf;
this.ndlModel = new ExistingSliceModel();
((ExistingSliceModel)this.ndlModel).init(this,rdf);
LIBNDL.logger().debug("SliceGraph::loadManifestRDF this.ndlModel = " + this.ndlModel);
}
public void save(String file){
saveNewRequest(file);
}
public void saveNewRequest(String file){
//RequestGenerator saver = new RequestGenerator(this);
//SliceGraph r = new SliceGraph(slice);
//saver.saveRequest(file);
}
public void saveModifyRequest(String file){
//RequestGenerator saver = new RequestGenerator(this);
//SliceGraph r = new SliceGraph(slice);
//saver.saveModifyRequest(file);
}
public String getRDFString(){
//RequestGenerator saver = new RequestGenerator(this);
//SliceGraph r = new SliceGraph(slice);
return ndlModel.getRequest();
}
/************************************* Higher level Functionality: autoip, etc. ************************************/
public boolean autoAssignIPAddresses() {
return true;
}
/************************************* debugging ************************************/
public String getDebugString(){
String rtnStr = "getRequestDebugString: ";
for (ModelResource r : sliceGraph.getVertices()){
rtnStr += ", Resource:" + r.getName();
}
//rtnStr += sliceGraph.toString();
return rtnStr;
}
public String getSliceGraphString(){
return sliceGraph.toString();
}
public Object getDomainInReservation() {
// TODO Auto-generated method stub
return null;
}
public void addNetworkConnection(String string) {
// TODO Auto-generated method stub
}
public LinkConnection addLinkConnection(String string) {
// TODO Auto-generated method stub
return null;
}
public void addCrossConnect(String string) {
// TODO Auto-generated method stub
}
public Node addNode(String string) {
// TODO Auto-generated method stub
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy