rspec_parser.h 5.78 KB
Newer Older
1 2
/*
 * Copyright (c) 2010 University of Utah and the Flux Group.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 * 
 * {{{EMULAB-LICENSE
 * 
 * This file is part of the Emulab network testbed software.
 * 
 * This file is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at
 * your option) any later version.
 * 
 * This file is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
 * License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this file.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * }}}
22 23 24 25 26 27 28 29 30 31 32 33 34
 */

/*
 * Header for RSPEC parser files
 */

# ifdef WITH_XML

#ifndef __RSPEC_PARSER__
#define __RSPEC_PARSER__

#include <list>
#include <map>
35
#include <set>
36 37
#include <string>
#include <utility>
38
#include <vector>
39
#include <xercesc/dom/DOM.hpp>
40 41
#include "rspec_parser_helper.h"
#include "emulab_extensions_parser.h"
42

43 44
#define RSPEC_TYPE_ADVT 0
#define RSPEC_TYPE_REQ 1
45

46 47 48 49
#define RSPEC_ERROR_BAD_IFACE_COUNT -1
#define RSPEC_ERROR_UNSEEN_NODEIFACE_SRC -2
#define RSPEC_ERROR_UNSEEN_NODEIFACE_DST -3

50 51
#define RSPEC_ASYMMETRIC_LINK -1

52 53
struct node_type 
{
54 55 56
  std::string typeName;
  int typeSlots;
  bool isStatic;
57 58
};

59 60
struct link_type
{
61 62
  std::string name;
  std::string typeName;
63 64
};

65 66
struct link_characteristics
{
67 68 69
  int bandwidth;
  int latency;
  double packetLoss;
70 71 72 73
};

struct link_interface
{
74 75 76 77
  std::string virtualNodeId;
  std::string virtualIfaceId;
  std::string physicalNodeId;
  std::string physicalIfaceId;
78 79 80 81
};

struct node_interface
{
82 83
  std::string componentId;
  std::string clientId;
84 85
};

86
class rspec_parser : public rspec_parser_helper
87
{
88 89 90 91 92 93 94
 private:

 protected:
  // Extensions parser object
  rspec_emulab_extension::emulab_extensions_parser* emulabExtensions;
  
  int rspecType; 
95
  std::map< std::string, std::string > shortNames;
96
  std::set< std::pair<std::string, std::string> >ifacesSeen;
97 98
  std::set< std::string > switches; 
  virtual void addSwitch (const xercesc::DOMElement*);
99 100 101 102 103 104 105 106 107 108 109 110
  struct link_interface getIface (const xercesc::DOMElement*);
  
 public:
  // Constructors and destructors
  rspec_parser(int type);
  ~rspec_parser();
  
  // Common functions
  virtual std::string readPhysicalId (const xercesc::DOMElement*, bool&);
  virtual std::string readVirtualId (const xercesc::DOMElement*, bool&);
  virtual std::string readComponentManagerId (const xercesc::DOMElement*,
					      bool&);
111
  virtual std::string readComponentName (const xercesc::DOMElement*, bool&);
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
  virtual std::string readVirtualizationType (const xercesc::DOMElement*,
					      bool&);
  
  // Functions for nodes
  virtual std::vector<std::string>readLocation(const xercesc::DOMElement*, 
					       int&);
  virtual std::vector<struct node_type> 
    readNodeTypes (const xercesc::DOMElement*,
		   int&, int unlimitedSlots=1000);
  
  // Reads the exclusive tag if present
  virtual std::string readExclusive (const xercesc::DOMElement*, bool&);
  
  // Reads the available tag, if present
  virtual std::string readAvailable (const xercesc::DOMElement*, bool&);

  // Functions for links
  virtual struct link_characteristics 
    readLinkCharacteristics (const xercesc::DOMElement*, 
			     int&,
			     int defaultBandwidth = -1, 
			     int unlimitedBandwidth = -1);
  // Reads the interfaces on a link		
  virtual std::vector< struct link_interface >
    readLinkInterface (const xercesc::DOMElement*, int&);
  
  // Reads the link types
  virtual std::vector< struct link_type >
    readLinkTypes (const xercesc::DOMElement*, int&);
  
  // Reads all the interfaces on a node
  // Returns the number of interfaces found. 
  // This only populates the internal data structures of the object.
  // Ideally, this ought to be done automatically,
  // but there doesn't seem to be a clean way of making it happen.
  virtual std::map< std::pair<std::string, std::string>, 
    std::pair<std::string, std::string> >
    readInterfacesOnNode (const xercesc::DOMElement*, bool&);

151 152
  // Gets a map of the interface URNS to the short names
  // that assign needs for fixed interfaces
153
  virtual std::map<std::string, std::string> getShortNames (void);
154

155
  // These are functions needed to deal with extensions
156 157
  virtual std::vector<struct rspec_emulab_extension::type_limit> 
    readTypeLimits (const xercesc::DOMElement*, int&);
158 159 160

  virtual std::vector<struct rspec_emulab_extension::fd>
    readFeaturesDesires(const xercesc::DOMElement*, int&);
161 162 163 164 165 166 167 168 169 170 171

  virtual bool checkIsSwitch (std::string nodeId);

  virtual std::vector<struct rspec_emulab_extension::vclass> 
    readVClasses (const xercesc::DOMElement* tag);
  virtual std::string readSubnodeOf (const xercesc::DOMElement* tag, 
				     bool& isSubnode,
				     int& count);
  virtual bool readDisallowTrivialMix (const xercesc::DOMElement* tag);
  virtual bool readUnique (const xercesc::DOMElement* tag);
  virtual int readTrivialBandwidth (const xercesc::DOMElement* tag, bool&);
172
  virtual bool readMultiplexOk (const xercesc::DOMElement* tag);
173 174 175
  virtual std::string readHintTo (const xercesc::DOMElement* tag, bool&);
  virtual bool readNoDelay (const xercesc::DOMElement* tag);
  virtual bool readTrivialOk (const xercesc::DOMElement* tag);
176 177
  virtual std::vector<struct rspec_emulab_extension::policy>
    readPolicies (const xercesc::DOMElement* tag, int& count);
178 179 180 181 182 183

  // XXX: This is really, really bad. We shouldn't have a function which 
  // converts a single type name into the composite name that version 2
  // expects but we need it when dealing with default types
  virtual std::string convertType (const std::string, const std::string);
  virtual std::string convertType (const std::string hwType);
184 185 186 187 188 189
};


#endif

#endif