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