1 /* Copyright (c) 2012 Massachusetts Institute of Technology
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to deal
5 * in the Software without restriction, including without limitation the rights
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 * copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 #include "model/OpticalModel.h"
24 #include "model/PortInfo.h"
25 #include "model/EventInfo.h"
26 #include "model/optical_graph/OpticalWaveguide.h"
27 #include "model/optical_graph/OpticalNode.h"
28 #include "model/optical_graph/OpticalLaser.h"
29 #include "model/optical_graph/OpticalModulator.h"
30 #include "model/optical_graph/OpticalFilter.h"
31 #include "model/optical_graph/OpticalDetector.h"
32 #include "model/optical_graph/OpticalWavelength.h"
36 OpticalModel::OpticalModel(const String
& instance_name_
, const TechModel
* tech_model_
)
37 : ElectricalModel(instance_name_
, tech_model_
)
39 m_optical_input_ports_
= new Map
<PortInfo
*>;
40 m_optical_output_ports_
= new Map
<PortInfo
*>;
42 m_waveguides_
= new Map
<OpticalWaveguide
*>;
43 m_lasers_
= new Map
<OpticalLaser
*>;
44 m_modulators_
= new Map
<OpticalModulator
*>;
45 m_filters_
= new Map
<OpticalFilter
*>;
46 m_detectors_
= new Map
<OpticalDetector
*>;
49 OpticalModel::~OpticalModel()
51 delete m_optical_input_ports_
;
52 delete m_optical_output_ports_
;
53 deletePtrMap
<OpticalWaveguide
>(m_waveguides_
);
54 deletePtrMap
<OpticalLaser
>(m_lasers_
);
55 deletePtrMap
<OpticalModulator
>(m_modulators_
);
56 deletePtrMap
<OpticalFilter
>(m_filters_
);
57 deletePtrMap
<OpticalDetector
>(m_detectors_
);
58 m_optical_input_ports_
= NULL
;
59 m_optical_output_ports_
= NULL
;
67 // Connect an optical port (input or output) to some OpticalWaveguide
68 void OpticalModel::opticalPortConnect(OpticalModel
* connect_model_
, const String
& port_name_
, const String
& waveguide_name_
)
70 // Check that the connecting waveguide exists
71 ASSERT(m_waveguides_
->keyExist(waveguide_name_
), "[Error] " + getInstanceName() +
72 " -> Waveguide '" + waveguide_name_
+ "' does not exist!");
74 // Check whether the port name is an input or output, assertion error if neither
75 bool is_input
= connect_model_
->getOpticalInputs()->keyExist(port_name_
);
76 bool is_output
= connect_model_
->getOpticalOutputs()->keyExist(port_name_
);
77 ASSERT(is_input
|| is_output
, "[Error] " + getInstanceName() + " -> Model '" + connect_model_
->getInstanceName() +
78 "' does not have a port named '" + port_name_
+ "'!");
80 // Get the two waveguides
81 OpticalWaveguide
* port_waveguide
= connect_model_
->getWaveguide(port_name_
);
82 OpticalWaveguide
* connect_waveguide
= getWaveguide(waveguide_name_
);
84 // Check that the two waveguides expect the same wavelengths
85 ASSERT((port_waveguide
->getWavelengths().first
== connect_waveguide
->getWavelengths().first
) &&
86 (port_waveguide
->getWavelengths().second
== connect_waveguide
->getWavelengths().second
),
87 "[Error] " + getInstanceName() + " -> Optical port expects different wavelengths for Model '" +
88 connect_model_
->getInstanceName() + "." + port_name_
+ "' and waveguide '" + waveguide_name_
+ "'!");
92 connect_waveguide
->addDownstreamNode(port_waveguide
);
96 port_waveguide
->addDownstreamNode(connect_waveguide
);
101 const Map
<OpticalWaveguide
*>* OpticalModel::getWaveguides() const
103 return m_waveguides_
;
106 OpticalWaveguide
* OpticalModel::getWaveguide(const String
& name_
)
108 return m_waveguides_
->get(name_
);
112 const Map
<OpticalLaser
*>* OpticalModel::getLasers() const
117 OpticalLaser
* OpticalModel::getLaser(const String
& name_
)
119 return m_lasers_
->get(name_
);
123 const Map
<OpticalModulator
*>* OpticalModel::getModulators() const
125 return m_modulators_
;
128 OpticalModulator
* OpticalModel::getModulator(const String
& name_
)
130 return m_modulators_
->get(name_
);
134 const Map
<OpticalFilter
*>* OpticalModel::getFilters() const
139 OpticalFilter
* OpticalModel::getFilter(const String
& name_
)
141 return m_filters_
->get(name_
);
145 const Map
<OpticalDetector
*>* OpticalModel::getDetectors() const
150 OpticalDetector
* OpticalModel::getDetector(const String
& name_
)
152 return m_detectors_
->get(name_
);
156 const Map
<PortInfo
*>* OpticalModel::getOpticalInputs() const
158 return m_optical_input_ports_
;
161 PortInfo
* OpticalModel::getOpticalInputPort(const String
& name_
)
163 ASSERT(m_optical_input_ports_
->keyExist(name_
), "[Error] " + getInstanceName() +
164 " -> Input port (" + name_
+ ") does not exist");
166 return m_optical_input_ports_
->get(name_
);
169 const PortInfo
* OpticalModel::getOpticalInputPort(const String
& name_
) const
171 ASSERT(m_optical_input_ports_
->keyExist(name_
), "[Error] " + getInstanceName() +
172 " -> Input port (" + name_
+ ") does not exist");
174 return m_optical_input_ports_
->get(name_
);
178 const Map
<PortInfo
*>* OpticalModel::getOpticalOutputs() const
180 return m_optical_output_ports_
;
183 PortInfo
* OpticalModel::getOpticalOutputPort(const String
& name_
)
185 ASSERT(m_optical_output_ports_
->keyExist(name_
), "[Error] " + getInstanceName() +
186 " -> Input port (" + name_
+ ") does not exist");
188 return m_optical_output_ports_
->get(name_
);
191 const PortInfo
* OpticalModel::getOpticalOutputPort(const String
& name_
) const
193 ASSERT(m_optical_output_ports_
->keyExist(name_
), "[Error] " + getInstanceName() +
194 " -> Input port (" + name_
+ ") does not exist");
196 return m_optical_output_ports_
->get(name_
);
199 //-------------------------------------------------------------------------
200 // Optical Connectivity Creation Functions
201 //-------------------------------------------------------------------------
202 void OpticalModel::createOpticalInputPort(const String
& name_
, const WavelengthGroup
& wavelength_group_
)
204 // Create the new waveguides
205 // This should already check that it has not been previously declared
206 createWaveguide(name_
, wavelength_group_
);
207 // Add the waveguide name to list of input ports
208 m_optical_input_ports_
->set(name_
, new PortInfo(name_
, wavelength_group_
));
212 void OpticalModel::createOpticalOutputPort(const String
& name_
, const WavelengthGroup
& wavelength_group_
)
214 // Create the new waveguides (including its waveguide reference)
215 // This should already check that it has not been previously declared
216 createWaveguide(name_
, wavelength_group_
);
217 // Add the waveguide name to list of output ports
218 m_optical_output_ports_
->set(name_
, new PortInfo(name_
, wavelength_group_
));
222 // Waveguide creation
223 void OpticalModel::createWaveguide(const String
& name_
, const WavelengthGroup
& wavelengths_
)
225 // Check that the waveguide hasn't been previously declared
226 ASSERT( !m_waveguides_
->keyExist(name_
), "[Error] " + getInstanceName() +
227 " -> Redeclaration of waveguide " + name_
);
228 m_waveguides_
->set(name_
, new OpticalWaveguide(name_
, this, wavelengths_
));
233 void OpticalModel::createLaser(const String
& name_
, const WavelengthGroup
& wavelengths_
)
235 // Check that the laser hasn't been previously declared
236 ASSERT( !m_lasers_
->keyExist(name_
), "[Error] " + getInstanceName() +
237 " -> Redeclaration of laser " + name_
);
238 m_lasers_
->set(name_
, new OpticalLaser(name_
, this, wavelengths_
));
242 // Modulator creation
243 void OpticalModel::createModulator(const String
& name_
, const WavelengthGroup
& wavelengths_
, bool opt_loss_
, OpticalTransmitter
* transmitter_
)
245 // Check that the modulator hasn't been previously declared
246 ASSERT( !m_modulators_
->keyExist(name_
), "[Error] " + getInstanceName() +
247 " -> Redeclaration of modulator " + name_
);
248 m_modulators_
->set(name_
, new OpticalModulator(name_
, this, wavelengths_
, opt_loss_
, transmitter_
));
252 // Modulator Multiplier creation
253 void OpticalModel::createFilter(const String
& name_
, const WavelengthGroup
& wavelengths_
, bool drop_all_
, const WavelengthGroup
& drop_wavelengths_
)
255 // Check that the filter hasn't been previously declared
256 ASSERT( !m_filters_
->keyExist(name_
), "[Error] " + getInstanceName() +
257 " -> Redeclaration of filter " + name_
);
258 m_filters_
->set(name_
, new OpticalFilter(name_
, this, wavelengths_
, drop_all_
, drop_wavelengths_
));
263 void OpticalModel::createDetector(const String
& name_
, const WavelengthGroup
& wavelengths_
, OpticalReceiver
* receiver_
)
265 // Check that the detector hasn't been previously declared
266 ASSERT( !m_detectors_
->keyExist(name_
), "[Error] " + getInstanceName() +
267 " -> Redeclaration of detector " + name_
);
268 m_detectors_
->set(name_
, new OpticalDetector(name_
, this, wavelengths_
, receiver_
));
272 //-------------------------------------------------------------------------
274 // Assign a waveguide to be downstream from another waveguide
275 // assign downtream_waveguide_name_ = upstream_waveguide_name_
276 void OpticalModel::opticalAssign(const String
& downstream_waveguide_name_
, const String
& upstream_waveguide_name_
)
278 ASSERT(getWaveguides()->keyExist(downstream_waveguide_name_
), "[Error] " + getInstanceName() + " -> Waveguide '" +
279 downstream_waveguide_name_
+ "' does not exist!");
281 ASSERT(getWaveguides()->keyExist(upstream_waveguide_name_
), "[Error] " + getInstanceName() + " -> Waveguide '" +
282 upstream_waveguide_name_
+ "' does not exist!");
284 // Get the two waveguides
285 OpticalWaveguide
* upstream_waveguide
= getWaveguide(upstream_waveguide_name_
);
286 OpticalWaveguide
* downstream_waveguide
= getWaveguide(downstream_waveguide_name_
);
288 // Check that the two waveguides expect the same wavelengths
289 ASSERT((upstream_waveguide
->getWavelengths().first
== downstream_waveguide
->getWavelengths().first
) &&
290 (upstream_waveguide
->getWavelengths().second
== downstream_waveguide
->getWavelengths().second
),
291 "[Error] " + getInstanceName() + " -> Assignment expects different wavelengths for waveguide '" +
292 upstream_waveguide_name_
+ "' and waveguide '" + downstream_waveguide_name_
+ "'!");
294 // Connect the downstream waveguide and the upstream waveguide
295 upstream_waveguide
->addDownstreamNode(downstream_waveguide
);