Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.provider.of.device.impl; |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 17 | |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame^] | 18 | import static com.google.common.base.Preconditions.checkArgument; |
| 19 | import static com.google.common.base.Strings.isNullOrEmpty; |
| 20 | import static org.onlab.util.Tools.get; |
| 21 | import static org.onosproject.net.DeviceId.deviceId; |
| 22 | import static org.onosproject.net.Port.Type.COPPER; |
| 23 | import static org.onosproject.net.Port.Type.FIBER; |
| 24 | import static org.onosproject.openflow.controller.Dpid.dpid; |
| 25 | import static org.onosproject.openflow.controller.Dpid.uri; |
| 26 | import static org.slf4j.LoggerFactory.getLogger; |
| 27 | |
| 28 | import java.util.ArrayList; |
| 29 | import java.util.Collection; |
| 30 | import java.util.Collections; |
| 31 | import java.util.Dictionary; |
| 32 | import java.util.HashMap; |
| 33 | import java.util.HashSet; |
| 34 | import java.util.List; |
| 35 | |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 36 | import org.apache.felix.scr.annotations.Activate; |
| 37 | import org.apache.felix.scr.annotations.Component; |
| 38 | import org.apache.felix.scr.annotations.Deactivate; |
Dusan Pajin | bab8a5e | 2015-07-24 17:37:19 +0200 | [diff] [blame] | 39 | import org.apache.felix.scr.annotations.Modified; |
| 40 | import org.apache.felix.scr.annotations.Property; |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 41 | import org.apache.felix.scr.annotations.Reference; |
| 42 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
Thomas Vachuska | f0397b5 | 2015-05-29 13:50:17 -0700 | [diff] [blame] | 43 | import org.onlab.packet.ChassisId; |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 44 | import org.onlab.util.Frequency; |
| 45 | import org.onlab.util.Spectrum; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame^] | 46 | import org.onosproject.cfg.ComponentConfigService; |
Thomas Vachuska | b52a014 | 2015-04-21 17:48:15 -0700 | [diff] [blame] | 47 | import org.onosproject.net.AnnotationKeys; |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 48 | import org.onosproject.net.ChannelSpacing; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 49 | import org.onosproject.net.DefaultAnnotations; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame^] | 50 | import org.onosproject.net.Device; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 51 | import org.onosproject.net.DeviceId; |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 52 | import org.onosproject.net.GridType; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 53 | import org.onosproject.net.MastershipRole; |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 54 | import org.onosproject.net.OchSignal; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame^] | 55 | import org.onosproject.net.OduCltPort; |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 56 | import org.onosproject.net.OduSignalType; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 57 | import org.onosproject.net.Port; |
| 58 | import org.onosproject.net.PortNumber; |
| 59 | import org.onosproject.net.SparseAnnotations; |
| 60 | import org.onosproject.net.device.DefaultDeviceDescription; |
| 61 | import org.onosproject.net.device.DefaultPortDescription; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 62 | import org.onosproject.net.device.DefaultPortStatistics; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 63 | import org.onosproject.net.device.DeviceDescription; |
| 64 | import org.onosproject.net.device.DeviceProvider; |
| 65 | import org.onosproject.net.device.DeviceProviderRegistry; |
| 66 | import org.onosproject.net.device.DeviceProviderService; |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 67 | import org.onosproject.net.device.OchPortDescription; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame^] | 68 | import org.onosproject.net.device.OduCltPortDescription; |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 69 | import org.onosproject.net.device.OmsPortDescription; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 70 | import org.onosproject.net.device.PortDescription; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 71 | import org.onosproject.net.device.PortStatistics; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 72 | import org.onosproject.net.provider.AbstractProvider; |
| 73 | import org.onosproject.net.provider.ProviderId; |
| 74 | import org.onosproject.openflow.controller.Dpid; |
| 75 | import org.onosproject.openflow.controller.OpenFlowController; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 76 | import org.onosproject.openflow.controller.OpenFlowEventListener; |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 77 | import org.onosproject.openflow.controller.OpenFlowOpticalSwitch; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 78 | import org.onosproject.openflow.controller.OpenFlowSwitch; |
| 79 | import org.onosproject.openflow.controller.OpenFlowSwitchListener; |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 80 | import org.onosproject.openflow.controller.PortDescPropertyType; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 81 | import org.onosproject.openflow.controller.RoleState; |
Dusan Pajin | bab8a5e | 2015-07-24 17:37:19 +0200 | [diff] [blame] | 82 | import org.osgi.service.component.ComponentContext; |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 83 | import org.projectfloodlight.openflow.protocol.OFCalientPortDescStatsEntry; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame^] | 84 | import org.projectfloodlight.openflow.protocol.OFExpPort; |
| 85 | import org.projectfloodlight.openflow.protocol.OFExpPortDescPropOpticalTransport; |
| 86 | import org.projectfloodlight.openflow.protocol.OFExpPortOpticalTransportLayerEntry; |
Ayaka Koshibe | e8708e3 | 2014-10-22 13:40:18 -0700 | [diff] [blame] | 87 | import org.projectfloodlight.openflow.protocol.OFFactory; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 88 | import org.projectfloodlight.openflow.protocol.OFMessage; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame^] | 89 | import org.projectfloodlight.openflow.protocol.OFObject; |
alshabib | 4680bb6 | 2014-09-04 17:15:08 -0700 | [diff] [blame] | 90 | import org.projectfloodlight.openflow.protocol.OFPortConfig; |
alshabib | 25c8eec | 2014-09-04 16:41:31 -0700 | [diff] [blame] | 91 | import org.projectfloodlight.openflow.protocol.OFPortDesc; |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 92 | import org.projectfloodlight.openflow.protocol.OFPortDescPropOpticalTransport; |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 93 | import org.projectfloodlight.openflow.protocol.OFPortFeatures; |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 94 | import org.projectfloodlight.openflow.protocol.OFPortOptical; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame^] | 95 | import org.projectfloodlight.openflow.protocol.OFPortOpticalTransportLayerClass; |
| 96 | import org.projectfloodlight.openflow.protocol.OFPortOpticalTransportSignalType; |
alshabib | afc514a | 2014-12-01 14:44:05 -0800 | [diff] [blame] | 97 | import org.projectfloodlight.openflow.protocol.OFPortReason; |
alshabib | 4680bb6 | 2014-09-04 17:15:08 -0700 | [diff] [blame] | 98 | import org.projectfloodlight.openflow.protocol.OFPortState; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 99 | import org.projectfloodlight.openflow.protocol.OFPortStatsEntry; |
| 100 | import org.projectfloodlight.openflow.protocol.OFPortStatsReply; |
alshabib | a14f364 | 2014-09-05 09:31:31 -0700 | [diff] [blame] | 101 | import org.projectfloodlight.openflow.protocol.OFPortStatus; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 102 | import org.projectfloodlight.openflow.protocol.OFStatsReply; |
Thomas Vachuska | 893bf4b | 2015-05-29 18:13:18 -0700 | [diff] [blame] | 103 | import org.projectfloodlight.openflow.protocol.OFStatsReplyFlags; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 104 | import org.projectfloodlight.openflow.protocol.OFStatsType; |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 105 | import org.projectfloodlight.openflow.protocol.OFVersion; |
| 106 | import org.projectfloodlight.openflow.types.PortSpeed; |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 107 | import org.slf4j.Logger; |
tom | 5f38b3a | 2014-08-27 23:50:54 -0700 | [diff] [blame] | 108 | |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame^] | 109 | import com.google.common.base.Strings; |
| 110 | import com.google.common.collect.Lists; |
| 111 | import com.google.common.collect.Maps; |
| 112 | import com.google.common.collect.Sets; |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 113 | |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 114 | /** |
tom | b1260e4 | 2014-08-26 18:39:57 -0700 | [diff] [blame] | 115 | * Provider which uses an OpenFlow controller to detect network |
tom | e06f855 | 2014-08-26 16:58:42 -0700 | [diff] [blame] | 116 | * infrastructure devices. |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 117 | */ |
tom | b1260e4 | 2014-08-26 18:39:57 -0700 | [diff] [blame] | 118 | @Component(immediate = true) |
tom | ab21e7c | 2014-08-26 15:23:08 -0700 | [diff] [blame] | 119 | public class OpenFlowDeviceProvider extends AbstractProvider implements DeviceProvider { |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 120 | |
alshabib | a89cc58 | 2014-09-09 16:43:00 -0700 | [diff] [blame] | 121 | private static final Logger LOG = getLogger(OpenFlowDeviceProvider.class); |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 122 | private static final long MBPS = 1_000 * 1_000; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame^] | 123 | private static final Frequency FREQ100 = Frequency.ofGHz(100); |
| 124 | private static final Frequency FREQ193_1 = Frequency.ofTHz(193.1); |
| 125 | private static final Frequency FREQ4_4 = Frequency.ofTHz(4.4); |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 126 | |
| 127 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
tom | 96dfcab | 2014-08-28 09:26:03 -0700 | [diff] [blame] | 128 | protected DeviceProviderRegistry providerRegistry; |
tom | ab21e7c | 2014-08-26 15:23:08 -0700 | [diff] [blame] | 129 | |
tom | 5f38b3a | 2014-08-27 23:50:54 -0700 | [diff] [blame] | 130 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 131 | protected OpenFlowController controller; |
| 132 | |
Dusan Pajin | bab8a5e | 2015-07-24 17:37:19 +0200 | [diff] [blame] | 133 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 134 | protected ComponentConfigService cfgService; |
| 135 | |
tom | ab21e7c | 2014-08-26 15:23:08 -0700 | [diff] [blame] | 136 | private DeviceProviderService providerService; |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 137 | |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 138 | private final InternalDeviceProvider listener = new InternalDeviceProvider(); |
| 139 | |
| 140 | // TODO: We need to make the poll interval configurable. |
Srikanth Vavilapalli | 78baf58 | 2015-06-05 11:40:14 -0700 | [diff] [blame] | 141 | static final int POLL_INTERVAL = 5; |
Dusan Pajin | bab8a5e | 2015-07-24 17:37:19 +0200 | [diff] [blame] | 142 | @Property(name = "PortStatsPollFrequency", intValue = POLL_INTERVAL, |
| 143 | label = "Frequency (in seconds) for polling switch Port statistics") |
| 144 | private int portStatsPollFrequency = POLL_INTERVAL; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 145 | |
| 146 | private HashMap<Dpid, PortStatsCollector> collectors = Maps.newHashMap(); |
tom | d40fc7a | 2014-09-04 16:41:10 -0700 | [diff] [blame] | 147 | |
tom | ab21e7c | 2014-08-26 15:23:08 -0700 | [diff] [blame] | 148 | /** |
| 149 | * Creates an OpenFlow device provider. |
| 150 | */ |
| 151 | public OpenFlowDeviceProvider() { |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 152 | super(new ProviderId("of", "org.onosproject.provider.openflow")); |
tom | ab21e7c | 2014-08-26 15:23:08 -0700 | [diff] [blame] | 153 | } |
| 154 | |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 155 | @Activate |
Dusan Pajin | bab8a5e | 2015-07-24 17:37:19 +0200 | [diff] [blame] | 156 | public void activate(ComponentContext context) { |
| 157 | cfgService.registerProperties(getClass()); |
tom | 96dfcab | 2014-08-28 09:26:03 -0700 | [diff] [blame] | 158 | providerService = providerRegistry.register(this); |
tom | d40fc7a | 2014-09-04 16:41:10 -0700 | [diff] [blame] | 159 | controller.addListener(listener); |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 160 | controller.addEventListener(listener); |
alshabib | c944fd0 | 2014-09-10 17:55:17 -0700 | [diff] [blame] | 161 | for (OpenFlowSwitch sw : controller.getSwitches()) { |
Yuta HIGUCHI | ac2972a | 2014-11-18 12:58:52 -0800 | [diff] [blame] | 162 | try { |
| 163 | listener.switchAdded(new Dpid(sw.getId())); |
| 164 | } catch (Exception e) { |
| 165 | LOG.warn("Failed initially adding {} : {}", sw.getStringId(), e.getMessage()); |
| 166 | LOG.debug("Error details:", e); |
| 167 | // disconnect to trigger switch-add later |
| 168 | sw.disconnectSwitch(); |
| 169 | } |
Dusan Pajin | bab8a5e | 2015-07-24 17:37:19 +0200 | [diff] [blame] | 170 | PortStatsCollector psc = new PortStatsCollector(sw, portStatsPollFrequency); |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 171 | psc.start(); |
| 172 | collectors.put(new Dpid(sw.getId()), psc); |
alshabib | c944fd0 | 2014-09-10 17:55:17 -0700 | [diff] [blame] | 173 | } |
alshabib | a89cc58 | 2014-09-09 16:43:00 -0700 | [diff] [blame] | 174 | LOG.info("Started"); |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | @Deactivate |
Dusan Pajin | bab8a5e | 2015-07-24 17:37:19 +0200 | [diff] [blame] | 178 | public void deactivate(ComponentContext context) { |
| 179 | cfgService.unregisterProperties(getClass(), false); |
tom | 96dfcab | 2014-08-28 09:26:03 -0700 | [diff] [blame] | 180 | providerRegistry.unregister(this); |
tom | d40fc7a | 2014-09-04 16:41:10 -0700 | [diff] [blame] | 181 | controller.removeListener(listener); |
Thomas Vachuska | 74bcd92 | 2015-06-02 13:08:57 -0700 | [diff] [blame] | 182 | collectors.values().forEach(PortStatsCollector::stop); |
tom | ab21e7c | 2014-08-26 15:23:08 -0700 | [diff] [blame] | 183 | providerService = null; |
alshabib | a89cc58 | 2014-09-09 16:43:00 -0700 | [diff] [blame] | 184 | LOG.info("Stopped"); |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 185 | } |
| 186 | |
Dusan Pajin | bab8a5e | 2015-07-24 17:37:19 +0200 | [diff] [blame] | 187 | @Modified |
| 188 | public void modified(ComponentContext context) { |
| 189 | Dictionary<?, ?> properties = context.getProperties(); |
| 190 | int newPortStatsPollFrequency; |
| 191 | try { |
| 192 | String s = get(properties, "PortStatsPollFrequency"); |
| 193 | newPortStatsPollFrequency = isNullOrEmpty(s) ? portStatsPollFrequency : Integer.parseInt(s.trim()); |
| 194 | |
| 195 | } catch (NumberFormatException | ClassCastException e) { |
| 196 | newPortStatsPollFrequency = portStatsPollFrequency; |
| 197 | } |
| 198 | |
| 199 | if (newPortStatsPollFrequency != portStatsPollFrequency) { |
| 200 | portStatsPollFrequency = newPortStatsPollFrequency; |
| 201 | collectors.values().forEach(psc -> psc.adjustPollInterval(portStatsPollFrequency)); |
| 202 | } |
| 203 | |
| 204 | LOG.info("Settings: portStatsPollFrequency={}", portStatsPollFrequency); |
| 205 | } |
Ayaka Koshibe | e60d452 | 2014-10-28 15:07:00 -0700 | [diff] [blame] | 206 | |
| 207 | @Override |
Yuta HIGUCHI | 5481532 | 2014-10-31 23:17:08 -0700 | [diff] [blame] | 208 | public boolean isReachable(DeviceId deviceId) { |
| 209 | OpenFlowSwitch sw = controller.getSwitch(dpid(deviceId.uri())); |
Yuta HIGUCHI | 69a2735 | 2014-10-31 15:48:37 -0700 | [diff] [blame] | 210 | if (sw == null || !sw.isConnected()) { |
Ayaka Koshibe | e60d452 | 2014-10-28 15:07:00 -0700 | [diff] [blame] | 211 | return false; |
| 212 | } |
| 213 | return true; |
Ayaka Koshibe | e60d452 | 2014-10-28 15:07:00 -0700 | [diff] [blame] | 214 | } |
| 215 | |
tom | ab21e7c | 2014-08-26 15:23:08 -0700 | [diff] [blame] | 216 | @Override |
Ayaka Koshibe | 78bcbc1 | 2014-11-19 14:28:58 -0800 | [diff] [blame] | 217 | public void triggerProbe(DeviceId deviceId) { |
Madan Jampani | c332876 | 2015-05-31 12:39:27 -0700 | [diff] [blame] | 218 | LOG.debug("Triggering probe on device {}", deviceId); |
Ayaka Koshibe | e8708e3 | 2014-10-22 13:40:18 -0700 | [diff] [blame] | 219 | |
Yuta HIGUCHI | 802d0e8 | 2014-10-31 16:07:37 -0700 | [diff] [blame] | 220 | final Dpid dpid = dpid(deviceId.uri()); |
| 221 | OpenFlowSwitch sw = controller.getSwitch(dpid); |
| 222 | if (sw == null || !sw.isConnected()) { |
Ayaka Koshibe | 78bcbc1 | 2014-11-19 14:28:58 -0800 | [diff] [blame] | 223 | LOG.error("Failed to probe device {} on sw={}", deviceId, sw); |
Yuta HIGUCHI | 802d0e8 | 2014-10-31 16:07:37 -0700 | [diff] [blame] | 224 | providerService.deviceDisconnected(deviceId); |
Thomas Vachuska | 74bcd92 | 2015-06-02 13:08:57 -0700 | [diff] [blame] | 225 | return; |
Yuta HIGUCHI | 802d0e8 | 2014-10-31 16:07:37 -0700 | [diff] [blame] | 226 | } else { |
Ayaka Koshibe | 78bcbc1 | 2014-11-19 14:28:58 -0800 | [diff] [blame] | 227 | LOG.trace("Confirmed device {} connection", deviceId); |
Yuta HIGUCHI | 802d0e8 | 2014-10-31 16:07:37 -0700 | [diff] [blame] | 228 | } |
Ayaka Koshibe | e8708e3 | 2014-10-22 13:40:18 -0700 | [diff] [blame] | 229 | |
Ayaka Koshibe | e60d452 | 2014-10-28 15:07:00 -0700 | [diff] [blame] | 230 | // Prompt an update of port information. We can use any XID for this. |
Ayaka Koshibe | e8708e3 | 2014-10-22 13:40:18 -0700 | [diff] [blame] | 231 | OFFactory fact = sw.factory(); |
| 232 | switch (fact.getVersion()) { |
| 233 | case OF_10: |
| 234 | sw.sendMsg(fact.buildFeaturesRequest().setXid(0).build()); |
| 235 | break; |
| 236 | case OF_13: |
| 237 | sw.sendMsg(fact.buildPortDescStatsRequest().setXid(0).build()); |
| 238 | break; |
| 239 | default: |
| 240 | LOG.warn("Unhandled protocol version"); |
| 241 | } |
tom | ab21e7c | 2014-08-26 15:23:08 -0700 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | @Override |
Yuta HIGUCHI | 5481532 | 2014-10-31 23:17:08 -0700 | [diff] [blame] | 245 | public void roleChanged(DeviceId deviceId, MastershipRole newRole) { |
alshabib | f1216ed | 2014-09-03 11:53:54 -0700 | [diff] [blame] | 246 | switch (newRole) { |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 247 | case MASTER: |
Yuta HIGUCHI | 5481532 | 2014-10-31 23:17:08 -0700 | [diff] [blame] | 248 | controller.setRole(dpid(deviceId.uri()), RoleState.MASTER); |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 249 | break; |
| 250 | case STANDBY: |
Yuta HIGUCHI | 5481532 | 2014-10-31 23:17:08 -0700 | [diff] [blame] | 251 | controller.setRole(dpid(deviceId.uri()), RoleState.EQUAL); |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 252 | break; |
| 253 | case NONE: |
Yuta HIGUCHI | 5481532 | 2014-10-31 23:17:08 -0700 | [diff] [blame] | 254 | controller.setRole(dpid(deviceId.uri()), RoleState.SLAVE); |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 255 | break; |
| 256 | default: |
| 257 | LOG.error("Unknown Mastership state : {}", newRole); |
alshabib | f1216ed | 2014-09-03 11:53:54 -0700 | [diff] [blame] | 258 | |
| 259 | } |
Madan Jampani | c332876 | 2015-05-31 12:39:27 -0700 | [diff] [blame] | 260 | LOG.debug("Accepting mastership role change for device {}", deviceId); |
tom | ab21e7c | 2014-08-26 15:23:08 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Thomas Vachuska | 893bf4b | 2015-05-29 18:13:18 -0700 | [diff] [blame] | 263 | private void pushPortMetrics(Dpid dpid, List<OFPortStatsEntry> portStatsEntries) { |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 264 | DeviceId deviceId = DeviceId.deviceId(dpid.uri(dpid)); |
Thomas Vachuska | 893bf4b | 2015-05-29 18:13:18 -0700 | [diff] [blame] | 265 | Collection<PortStatistics> stats = buildPortStatistics(deviceId, portStatsEntries); |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 266 | providerService.updatePortStatistics(deviceId, stats); |
| 267 | } |
| 268 | |
Thomas Vachuska | 893bf4b | 2015-05-29 18:13:18 -0700 | [diff] [blame] | 269 | private Collection<PortStatistics> buildPortStatistics(DeviceId deviceId, |
| 270 | List<OFPortStatsEntry> entries) { |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 271 | HashSet<PortStatistics> stats = Sets.newHashSet(); |
| 272 | |
Thomas Vachuska | 893bf4b | 2015-05-29 18:13:18 -0700 | [diff] [blame] | 273 | for (OFPortStatsEntry entry : entries) { |
Thomas Vachuska | f0397b5 | 2015-05-29 13:50:17 -0700 | [diff] [blame] | 274 | try { |
Thomas Vachuska | 4e6025e | 2015-06-03 11:25:21 -0700 | [diff] [blame] | 275 | if (entry == null || entry.getPortNo() == null || entry.getPortNo().getPortNumber() < 0) { |
Thomas Vachuska | f0397b5 | 2015-05-29 13:50:17 -0700 | [diff] [blame] | 276 | continue; |
| 277 | } |
| 278 | DefaultPortStatistics.Builder builder = DefaultPortStatistics.builder(); |
| 279 | DefaultPortStatistics stat = builder.setDeviceId(deviceId) |
| 280 | .setPort(entry.getPortNo().getPortNumber()) |
| 281 | .setPacketsReceived(entry.getRxPackets().getValue()) |
| 282 | .setPacketsSent(entry.getTxPackets().getValue()) |
| 283 | .setBytesReceived(entry.getRxBytes().getValue()) |
| 284 | .setBytesSent(entry.getTxBytes().getValue()) |
| 285 | .setPacketsRxDropped(entry.getRxDropped().getValue()) |
| 286 | .setPacketsTxDropped(entry.getTxDropped().getValue()) |
| 287 | .setPacketsRxErrors(entry.getRxErrors().getValue()) |
| 288 | .setPacketsTxErrors(entry.getTxErrors().getValue()) |
| 289 | .setDurationSec(entry.getVersion() == OFVersion.OF_10 ? 0 : entry.getDurationSec()) |
| 290 | .setDurationNano(entry.getVersion() == OFVersion.OF_10 ? 0 : entry.getDurationNsec()) |
| 291 | .build(); |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 292 | |
Thomas Vachuska | f0397b5 | 2015-05-29 13:50:17 -0700 | [diff] [blame] | 293 | stats.add(stat); |
| 294 | } catch (Exception e) { |
| 295 | LOG.warn("Unable to process port stats", e); |
| 296 | } |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | return Collections.unmodifiableSet(stats); |
| 300 | |
| 301 | } |
| 302 | |
| 303 | private class InternalDeviceProvider implements OpenFlowSwitchListener, OpenFlowEventListener { |
Thomas Vachuska | 893bf4b | 2015-05-29 18:13:18 -0700 | [diff] [blame] | 304 | |
Srikanth Vavilapalli | 78baf58 | 2015-06-05 11:40:14 -0700 | [diff] [blame] | 305 | private HashMap<Dpid, List<OFPortStatsEntry>> portStatsReplies = new HashMap<>(); |
Thomas Vachuska | 893bf4b | 2015-05-29 18:13:18 -0700 | [diff] [blame] | 306 | |
alshabib | f1216ed | 2014-09-03 11:53:54 -0700 | [diff] [blame] | 307 | @Override |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 308 | public void switchAdded(Dpid dpid) { |
alshabib | 6f5460b | 2014-09-03 14:46:17 -0700 | [diff] [blame] | 309 | if (providerService == null) { |
| 310 | return; |
| 311 | } |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 312 | DeviceId did = deviceId(uri(dpid)); |
alshabib | 6f5460b | 2014-09-03 14:46:17 -0700 | [diff] [blame] | 313 | OpenFlowSwitch sw = controller.getSwitch(dpid); |
| 314 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 315 | ChassisId cId = new ChassisId(dpid.value()); |
Ray Milkey | e53f171 | 2015-01-16 09:17:16 -0800 | [diff] [blame] | 316 | |
Thomas Vachuska | 82041f5 | 2014-11-30 22:14:02 -0800 | [diff] [blame] | 317 | SparseAnnotations annotations = DefaultAnnotations.builder() |
Ray Milkey | e53f171 | 2015-01-16 09:17:16 -0800 | [diff] [blame] | 318 | .set("protocol", sw.factory().getVersion().toString()) |
| 319 | .set("channelId", sw.channelId()) |
| 320 | .build(); |
| 321 | |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 322 | DeviceDescription description = |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 323 | new DefaultDeviceDescription(did.uri(), sw.deviceType(), |
Ray Milkey | d3edd03 | 2015-01-16 11:38:58 -0800 | [diff] [blame] | 324 | sw.manufacturerDescription(), |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 325 | sw.hardwareDescription(), |
| 326 | sw.softwareDescription(), |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 327 | sw.serialNumber(), |
Thomas Vachuska | 82041f5 | 2014-11-30 22:14:02 -0800 | [diff] [blame] | 328 | cId, annotations); |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 329 | providerService.deviceConnected(did, description); |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 330 | providerService.updatePorts(did, buildPortDescriptions(sw)); |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 331 | |
Thomas Vachuska | fc52fec | 2015-05-18 19:13:56 -0700 | [diff] [blame] | 332 | PortStatsCollector psc = |
Dusan Pajin | bab8a5e | 2015-07-24 17:37:19 +0200 | [diff] [blame] | 333 | new PortStatsCollector(controller.getSwitch(dpid), portStatsPollFrequency); |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 334 | psc.start(); |
| 335 | collectors.put(dpid, psc); |
alshabib | 25c8eec | 2014-09-04 16:41:31 -0700 | [diff] [blame] | 336 | } |
| 337 | |
alshabib | f1216ed | 2014-09-03 11:53:54 -0700 | [diff] [blame] | 338 | @Override |
| 339 | public void switchRemoved(Dpid dpid) { |
alshabib | 6f5460b | 2014-09-03 14:46:17 -0700 | [diff] [blame] | 340 | if (providerService == null) { |
| 341 | return; |
| 342 | } |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 343 | providerService.deviceDisconnected(deviceId(uri(dpid))); |
alshabib | f1216ed | 2014-09-03 11:53:54 -0700 | [diff] [blame] | 344 | |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 345 | PortStatsCollector collector = collectors.remove(dpid); |
| 346 | if (collector != null) { |
| 347 | collector.stop(); |
| 348 | } |
| 349 | } |
Ayaka Koshibe | 38594c2 | 2014-10-22 13:36:12 -0700 | [diff] [blame] | 350 | |
| 351 | @Override |
| 352 | public void switchChanged(Dpid dpid) { |
| 353 | if (providerService == null) { |
| 354 | return; |
| 355 | } |
| 356 | DeviceId did = deviceId(uri(dpid)); |
| 357 | OpenFlowSwitch sw = controller.getSwitch(dpid); |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 358 | providerService.updatePorts(did, buildPortDescriptions(sw)); |
Ayaka Koshibe | 38594c2 | 2014-10-22 13:36:12 -0700 | [diff] [blame] | 359 | } |
| 360 | |
alshabib | a14f364 | 2014-09-05 09:31:31 -0700 | [diff] [blame] | 361 | @Override |
| 362 | public void portChanged(Dpid dpid, OFPortStatus status) { |
alshabib | afc514a | 2014-12-01 14:44:05 -0800 | [diff] [blame] | 363 | PortDescription portDescription = buildPortDescription(status); |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 364 | providerService.portStatusChanged(deviceId(uri(dpid)), portDescription); |
alshabib | f1216ed | 2014-09-03 11:53:54 -0700 | [diff] [blame] | 365 | } |
| 366 | |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 367 | @Override |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 368 | public void receivedRoleReply(Dpid dpid, RoleState requested, RoleState response) { |
| 369 | MastershipRole request = roleOf(requested); |
| 370 | MastershipRole reply = roleOf(response); |
| 371 | |
| 372 | providerService.receivedRoleReply(deviceId(uri(dpid)), request, reply); |
| 373 | } |
| 374 | |
| 375 | /** |
| 376 | * Translates a RoleState to the corresponding MastershipRole. |
| 377 | * |
Thomas Vachuska | fc52fec | 2015-05-18 19:13:56 -0700 | [diff] [blame] | 378 | * @param response role state |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 379 | * @return a MastershipRole |
| 380 | */ |
| 381 | private MastershipRole roleOf(RoleState response) { |
| 382 | switch (response) { |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 383 | case MASTER: |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 384 | return MastershipRole.MASTER; |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 385 | case EQUAL: |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 386 | return MastershipRole.STANDBY; |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 387 | case SLAVE: |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 388 | return MastershipRole.NONE; |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 389 | default: |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 390 | LOG.warn("unknown role {}", response); |
| 391 | return null; |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 392 | } |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 393 | } |
| 394 | |
alshabib | a14f364 | 2014-09-05 09:31:31 -0700 | [diff] [blame] | 395 | /** |
| 396 | * Builds a list of port descriptions for a given list of ports. |
tom | ff7eb7c | 2014-09-08 12:49:03 -0700 | [diff] [blame] | 397 | * |
alshabib | a14f364 | 2014-09-05 09:31:31 -0700 | [diff] [blame] | 398 | * @return list of portdescriptions |
| 399 | */ |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 400 | private List<PortDescription> buildPortDescriptions(OpenFlowSwitch sw) { |
| 401 | final List<PortDescription> portDescs = new ArrayList<>(sw.getPorts().size()); |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame^] | 402 | if (!(Device.Type.ROADM.equals(sw.deviceType()))) { |
| 403 | sw.getPorts().forEach(port -> portDescs.add(buildPortDescription(port))); |
| 404 | } |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 405 | |
| 406 | OpenFlowOpticalSwitch opsw; |
| 407 | switch (sw.deviceType()) { |
| 408 | case ROADM: |
| 409 | opsw = (OpenFlowOpticalSwitch) sw; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame^] | 410 | List<OFPortDesc> ports = opsw.getPorts(); |
| 411 | LOG.debug("SW ID {} , ETH- ODU CLT Ports {}", opsw.getId(), ports); |
| 412 | // ODU client ports are reported as ETH |
| 413 | ports.forEach(port -> portDescs.add(buildOduCltPortDescription(port))); |
| 414 | |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 415 | opsw.getPortTypes().forEach(type -> { |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame^] | 416 | List<? extends OFObject> portsOf = opsw.getPortsOf(type); |
| 417 | LOG.debug("Ports Of{}", portsOf); |
| 418 | portsOf.forEach( |
| 419 | op -> { |
| 420 | portDescs.add(buildPortDescription(type, (OFObject) op)); |
| 421 | } |
| 422 | ); |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 423 | }); |
| 424 | break; |
| 425 | case FIBER_SWITCH: |
| 426 | opsw = (OpenFlowOpticalSwitch) sw; |
| 427 | opsw.getPortTypes().forEach(type -> { |
| 428 | opsw.getPortsOf(type).forEach( |
| 429 | op -> { |
| 430 | portDescs.add(buildPortDescription((OFCalientPortDescStatsEntry) op)); |
| 431 | } |
| 432 | ); |
| 433 | }); |
| 434 | break; |
| 435 | default: |
| 436 | break; |
alshabib | 4680bb6 | 2014-09-04 17:15:08 -0700 | [diff] [blame] | 437 | } |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 438 | |
alshabib | 4680bb6 | 2014-09-04 17:15:08 -0700 | [diff] [blame] | 439 | return portDescs; |
| 440 | } |
| 441 | |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame^] | 442 | private PortDescription buildOduCltPortDescription(OFPortDesc port) { |
| 443 | PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); |
| 444 | boolean enabled = !port.getState().contains(OFPortState.LINK_DOWN) && |
| 445 | !port.getConfig().contains(OFPortConfig.PORT_DOWN); |
| 446 | Long portSpeed = portSpeed(port); |
| 447 | OduCltPort.SignalType sigType = null; |
| 448 | |
| 449 | switch (portSpeed.toString()) { |
| 450 | case "1": |
| 451 | sigType = OduCltPort.SignalType.CLT_1GBE; |
| 452 | break; |
| 453 | case "10": |
| 454 | sigType = OduCltPort.SignalType.CLT_10GBE; |
| 455 | break; |
| 456 | case "40": |
| 457 | sigType = OduCltPort.SignalType.CLT_40GBE; |
| 458 | break; |
| 459 | case "100": |
| 460 | sigType = OduCltPort.SignalType.CLT_100GBE; |
| 461 | break; |
| 462 | default: |
| 463 | throw new RuntimeException("Un recognize OduClt speed: " + portSpeed.toString()); |
| 464 | } |
| 465 | |
| 466 | SparseAnnotations annotations = buildOduCltAnnotation(port); |
| 467 | return new OduCltPortDescription(portNo, enabled, sigType, annotations); |
| 468 | } |
| 469 | |
| 470 | private SparseAnnotations buildOduCltAnnotation(OFPortDesc port) { |
| 471 | SparseAnnotations annotations = null; |
| 472 | String portName = Strings.emptyToNull(port.getName()); |
| 473 | if (portName != null) { |
| 474 | annotations = DefaultAnnotations.builder() |
| 475 | .set(AnnotationKeys.PORT_NAME, portName) |
| 476 | .set(AnnotationKeys.STATIC_PORT, Boolean.TRUE.toString()).build(); |
| 477 | } |
| 478 | return annotations; |
| 479 | } |
| 480 | |
| 481 | private PortDescription buildPortDescription(PortDescPropertyType ptype, OFObject port) { |
| 482 | if (port instanceof OFPortOptical) { |
| 483 | return buildPortDescription(ptype, (OFPortOptical) port); |
| 484 | } |
| 485 | return buildPortDescription(ptype, (OFExpPort) port); |
| 486 | } |
| 487 | |
| 488 | /** |
| 489 | * Build a portDescription from a given a port description describing some |
| 490 | * Optical port. |
| 491 | * |
| 492 | * @param ptype description property type. |
| 493 | * @param port the port to build from. |
| 494 | * @return portDescription for the port. |
| 495 | */ |
| 496 | private PortDescription buildPortDescription(PortDescPropertyType ptype, OFExpPort port) { |
| 497 | PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); |
| 498 | boolean enabled = !port.getState().contains(OFPortState.LINK_DOWN) |
| 499 | && !port.getConfig().contains(OFPortConfig.PORT_DOWN); |
| 500 | SparseAnnotations annotations = makePortNameAnnotation(port.getName()); |
| 501 | |
| 502 | OFExpPortDescPropOpticalTransport firstProp = port.getProperties().get(0); |
| 503 | OFPortOpticalTransportSignalType sigType = firstProp.getPortSignalType(); |
| 504 | |
| 505 | DefaultPortDescription portDes = null; |
| 506 | switch (sigType) { |
| 507 | case OMSN: |
| 508 | portDes = new OmsPortDescription(portNo, enabled, FREQ193_1, FREQ193_1.add(FREQ4_4), |
| 509 | FREQ100, annotations); |
| 510 | break; |
| 511 | case OCH: |
| 512 | OFExpPortOpticalTransportLayerEntry entry = firstProp.getFeatures().get(0).getValue().get(0); |
| 513 | OFPortOpticalTransportLayerClass layerClass = entry.getLayerClass(); |
| 514 | if (!OFPortOpticalTransportLayerClass.ODU.equals(layerClass)) { |
| 515 | LOG.error("Unsupported layer Class {} ", layerClass); |
| 516 | return null; |
| 517 | } |
| 518 | |
| 519 | // convert to ONOS OduSignalType |
| 520 | OduSignalType oduSignalType = OpenFlowDeviceValueMapper. |
| 521 | lookupOduSignalType((byte) entry.getSignalType()); |
| 522 | //OchSignal is needed for OchPortDescription constructor, |
| 523 | //yet not relevant for tunable OCH port, creating with default parameters |
| 524 | OchSignal signalId = new OchSignal(GridType.DWDM, ChannelSpacing.CHL_50GHZ, 1, 1); |
| 525 | |
| 526 | portDes = new OchPortDescription(portNo, enabled, |
| 527 | oduSignalType, true, signalId, annotations); |
| 528 | |
| 529 | break; |
| 530 | case OTU2: |
| 531 | case OTU4: |
| 532 | LOG.error("Signal tpye OTU2/4 not supported yet ", port.toString()); |
| 533 | break; |
| 534 | default: |
| 535 | break; |
| 536 | } |
| 537 | |
| 538 | return portDes; |
| 539 | } |
| 540 | |
alshabib | a14f364 | 2014-09-05 09:31:31 -0700 | [diff] [blame] | 541 | /** |
Ray Milkey | e0fade7 | 2015-01-15 13:29:47 -0800 | [diff] [blame] | 542 | * Creates an annotation for the port name if one is available. |
| 543 | * |
| 544 | * @param port description of the port |
| 545 | * @return annotation containing the port name if one is found, |
| 546 | * null otherwise |
| 547 | */ |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 548 | private SparseAnnotations makePortNameAnnotation(String port) { |
Ray Milkey | e0fade7 | 2015-01-15 13:29:47 -0800 | [diff] [blame] | 549 | SparseAnnotations annotations = null; |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 550 | String portName = Strings.emptyToNull(port); |
Ray Milkey | e0fade7 | 2015-01-15 13:29:47 -0800 | [diff] [blame] | 551 | if (portName != null) { |
| 552 | annotations = DefaultAnnotations.builder() |
Thomas Vachuska | b52a014 | 2015-04-21 17:48:15 -0700 | [diff] [blame] | 553 | .set(AnnotationKeys.PORT_NAME, portName).build(); |
Ray Milkey | e0fade7 | 2015-01-15 13:29:47 -0800 | [diff] [blame] | 554 | } |
| 555 | return annotations; |
| 556 | } |
| 557 | |
| 558 | /** |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 559 | * Build a portDescription from a given Ethernet port description. |
tom | ff7eb7c | 2014-09-08 12:49:03 -0700 | [diff] [blame] | 560 | * |
alshabib | a14f364 | 2014-09-05 09:31:31 -0700 | [diff] [blame] | 561 | * @param port the port to build from. |
| 562 | * @return portDescription for the port. |
| 563 | */ |
| 564 | private PortDescription buildPortDescription(OFPortDesc port) { |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 565 | PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); |
| 566 | boolean enabled = |
| 567 | !port.getState().contains(OFPortState.LINK_DOWN) && |
| 568 | !port.getConfig().contains(OFPortConfig.PORT_DOWN); |
| 569 | Port.Type type = port.getCurr().contains(OFPortFeatures.PF_FIBER) ? FIBER : COPPER; |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 570 | SparseAnnotations annotations = makePortNameAnnotation(port.getName()); |
Ray Milkey | e0fade7 | 2015-01-15 13:29:47 -0800 | [diff] [blame] | 571 | return new DefaultPortDescription(portNo, enabled, type, |
| 572 | portSpeed(port), annotations); |
alshabib | a14f364 | 2014-09-05 09:31:31 -0700 | [diff] [blame] | 573 | } |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 574 | |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 575 | /** |
| 576 | * Build a portDescription from a given a port description describing some |
| 577 | * Optical port. |
| 578 | * |
| 579 | * @param port description property type. |
| 580 | * @param port the port to build from. |
| 581 | * @return portDescription for the port. |
| 582 | */ |
| 583 | private PortDescription buildPortDescription(PortDescPropertyType ptype, OFPortOptical port) { |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 584 | checkArgument(port.getDesc().size() >= 1); |
| 585 | |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 586 | // Minimally functional fixture. This needs to be fixed as we add better support. |
| 587 | PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); |
Ayaka Koshibe | 74b5527 | 2015-05-28 15:16:04 -0700 | [diff] [blame] | 588 | |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 589 | boolean enabled = !port.getState().contains(OFPortState.LINK_DOWN) |
| 590 | && !port.getConfig().contains(OFPortConfig.PORT_DOWN); |
| 591 | SparseAnnotations annotations = makePortNameAnnotation(port.getName()); |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 592 | |
| 593 | if (port.getVersion() == OFVersion.OF_13 |
| 594 | && ptype == PortDescPropertyType.OPTICAL_TRANSPORT) { |
| 595 | // At this point, not much is carried in the optical port message. |
Ayaka Koshibe | ae54173 | 2015-05-19 13:37:27 -0700 | [diff] [blame] | 596 | LOG.debug("Optical transport port message {}", port.toString()); |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 597 | } else { |
| 598 | // removable once 1.4+ support complete. |
Ayaka Koshibe | ae54173 | 2015-05-19 13:37:27 -0700 | [diff] [blame] | 599 | LOG.debug("Unsupported optical port properties"); |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 600 | } |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 601 | |
| 602 | OFPortDescPropOpticalTransport desc = port.getDesc().get(0); |
| 603 | switch (desc.getPortSignalType()) { |
| 604 | // FIXME: use constants once loxi has full optical extensions |
| 605 | case 2: // OMS port |
| 606 | // Assume complete optical spectrum and 50 GHz grid |
| 607 | // LINC-OE is only supported optical OF device for now |
| 608 | return new OmsPortDescription(portNo, enabled, |
| 609 | Spectrum.U_BAND_MIN, Spectrum.O_BAND_MAX, Frequency.ofGHz(50), annotations); |
| 610 | case 5: // OCH port |
| 611 | OchSignal signal = new OchSignal(GridType.DWDM, ChannelSpacing.CHL_50GHZ, 0, 4); |
| 612 | return new OchPortDescription(portNo, enabled, OduSignalType.ODU4, |
| 613 | true, signal, annotations); |
| 614 | default: |
| 615 | break; |
| 616 | } |
| 617 | |
Ayaka Koshibe | 74b5527 | 2015-05-28 15:16:04 -0700 | [diff] [blame] | 618 | return new DefaultPortDescription(portNo, enabled, FIBER, 0, annotations); |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 619 | } |
| 620 | |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 621 | /** |
| 622 | * Build a portDescription from a given port description describing a fiber switch optical port. |
| 623 | * |
| 624 | * @param port description property type. |
| 625 | * @param port the port to build from. |
| 626 | * @return portDescription for the port. |
| 627 | */ |
| 628 | private PortDescription buildPortDescription(OFCalientPortDescStatsEntry port) { |
| 629 | PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); |
| 630 | |
| 631 | // FIXME when Calient OF agent reports port status |
| 632 | boolean enabled = true; |
| 633 | SparseAnnotations annotations = makePortNameAnnotation(port.getName()); |
| 634 | |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 635 | // S160 data sheet |
| 636 | // Wavelength range: 1260 - 1630 nm, grid is irrelevant for this type of switch |
| 637 | return new OmsPortDescription(portNo, enabled, |
| 638 | Spectrum.U_BAND_MIN, Spectrum.O_BAND_MAX, Frequency.ofGHz(100), annotations); |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 639 | } |
| 640 | |
alshabib | afc514a | 2014-12-01 14:44:05 -0800 | [diff] [blame] | 641 | private PortDescription buildPortDescription(OFPortStatus status) { |
| 642 | OFPortDesc port = status.getDesc(); |
| 643 | if (status.getReason() != OFPortReason.DELETE) { |
| 644 | return buildPortDescription(port); |
| 645 | } else { |
| 646 | PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); |
| 647 | Port.Type type = port.getCurr().contains(OFPortFeatures.PF_FIBER) ? FIBER : COPPER; |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 648 | SparseAnnotations annotations = makePortNameAnnotation(port.getName()); |
Ray Milkey | e0fade7 | 2015-01-15 13:29:47 -0800 | [diff] [blame] | 649 | return new DefaultPortDescription(portNo, false, type, |
| 650 | portSpeed(port), annotations); |
alshabib | afc514a | 2014-12-01 14:44:05 -0800 | [diff] [blame] | 651 | } |
| 652 | } |
| 653 | |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 654 | private long portSpeed(OFPortDesc port) { |
| 655 | if (port.getVersion() == OFVersion.OF_13) { |
| 656 | return port.getCurrSpeed() / MBPS; |
| 657 | } |
| 658 | |
| 659 | PortSpeed portSpeed = PortSpeed.SPEED_NONE; |
| 660 | for (OFPortFeatures feat : port.getCurr()) { |
| 661 | portSpeed = PortSpeed.max(portSpeed, feat.getPortSpeed()); |
| 662 | } |
Thomas Vachuska | 98eda53 | 2014-10-29 17:31:02 -0700 | [diff] [blame] | 663 | return portSpeed.getSpeedBps() / MBPS; |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 664 | } |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 665 | |
| 666 | @Override |
| 667 | public void handleMessage(Dpid dpid, OFMessage msg) { |
| 668 | switch (msg.getType()) { |
| 669 | case STATS_REPLY: |
| 670 | if (((OFStatsReply) msg).getStatsType() == OFStatsType.PORT) { |
Thomas Vachuska | 893bf4b | 2015-05-29 18:13:18 -0700 | [diff] [blame] | 671 | OFPortStatsReply portStatsReply = (OFPortStatsReply) msg; |
Srikanth Vavilapalli | 78baf58 | 2015-06-05 11:40:14 -0700 | [diff] [blame] | 672 | List<OFPortStatsEntry> portStatsReplyList = portStatsReplies.get(dpid); |
| 673 | if (portStatsReplyList == null) { |
| 674 | portStatsReplyList = Lists.newArrayList(); |
| 675 | } |
| 676 | portStatsReplyList.addAll(portStatsReply.getEntries()); |
| 677 | portStatsReplies.put(dpid, portStatsReplyList); |
Thomas Vachuska | 893bf4b | 2015-05-29 18:13:18 -0700 | [diff] [blame] | 678 | if (!portStatsReply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { |
Srikanth Vavilapalli | 78baf58 | 2015-06-05 11:40:14 -0700 | [diff] [blame] | 679 | pushPortMetrics(dpid, portStatsReplies.get(dpid)); |
| 680 | portStatsReplies.get(dpid).clear(); |
Thomas Vachuska | 893bf4b | 2015-05-29 18:13:18 -0700 | [diff] [blame] | 681 | } |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 682 | } |
| 683 | break; |
| 684 | default: |
| 685 | break; |
| 686 | } |
| 687 | } |
alshabib | f1216ed | 2014-09-03 11:53:54 -0700 | [diff] [blame] | 688 | } |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 689 | } |