Jonathan Hart
Committed by Gerrit Code Review

Remove deprecated openflow host and link providers

Change-Id: I9dbaa28a70998b6265a178bb459a56221f458b75
1 -<?xml version="1.0" encoding="UTF-8"?>
2 -<!--
3 - ~ Copyright 2014 Open Networking Laboratory
4 - ~
5 - ~ Licensed under the Apache License, Version 2.0 (the "License");
6 - ~ you may not use this file except in compliance with the License.
7 - ~ You may obtain a copy of the License at
8 - ~
9 - ~ http://www.apache.org/licenses/LICENSE-2.0
10 - ~
11 - ~ Unless required by applicable law or agreed to in writing, software
12 - ~ distributed under the License is distributed on an "AS IS" BASIS,
13 - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 - ~ See the License for the specific language governing permissions and
15 - ~ limitations under the License.
16 - -->
17 -<project xmlns="http://maven.apache.org/POM/4.0.0"
18 - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19 - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
20 - <modelVersion>4.0.0</modelVersion>
21 -
22 - <parent>
23 - <groupId>org.onosproject</groupId>
24 - <artifactId>onos-of-providers</artifactId>
25 - <version>1.2.0-SNAPSHOT</version>
26 - <relativePath>../pom.xml</relativePath>
27 - </parent>
28 -
29 - <artifactId>onos-of-provider-host</artifactId>
30 - <packaging>bundle</packaging>
31 -
32 - <description>ONOS OpenFlow protocol host provider</description>
33 -
34 -</project>
1 -/*
2 - * Copyright 2014 Open Networking Laboratory
3 - *
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
7 - *
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.
15 - */
16 -package org.onosproject.provider.of.host.impl;
17 -
18 -import org.apache.felix.scr.annotations.Activate;
19 -import org.apache.felix.scr.annotations.Component;
20 -import org.apache.felix.scr.annotations.Deactivate;
21 -import org.apache.felix.scr.annotations.Reference;
22 -import org.apache.felix.scr.annotations.ReferenceCardinality;
23 -import org.onlab.packet.ARP;
24 -import org.onlab.packet.Ethernet;
25 -import org.onlab.packet.IPv4;
26 -import org.onlab.packet.IpAddress;
27 -import org.onlab.packet.VlanId;
28 -import org.onosproject.net.ConnectPoint;
29 -import org.onosproject.net.Host;
30 -import org.onosproject.net.HostId;
31 -import org.onosproject.net.HostLocation;
32 -import org.onosproject.net.host.DefaultHostDescription;
33 -import org.onosproject.net.host.HostDescription;
34 -import org.onosproject.net.host.HostProvider;
35 -import org.onosproject.net.host.HostProviderRegistry;
36 -import org.onosproject.net.host.HostProviderService;
37 -import org.onosproject.net.provider.AbstractProvider;
38 -import org.onosproject.net.provider.ProviderId;
39 -import org.onosproject.net.topology.Topology;
40 -import org.onosproject.net.topology.TopologyService;
41 -import org.onosproject.openflow.controller.Dpid;
42 -import org.onosproject.openflow.controller.OpenFlowController;
43 -import org.onosproject.openflow.controller.OpenFlowPacketContext;
44 -import org.onosproject.openflow.controller.PacketListener;
45 -import org.slf4j.Logger;
46 -
47 -import static org.onosproject.net.DeviceId.deviceId;
48 -import static org.onosproject.net.PortNumber.portNumber;
49 -import static org.slf4j.LoggerFactory.getLogger;
50 -
51 -/**
52 - * Provider which uses an OpenFlow controller to detect network
53 - * end-station hosts.
54 - */
55 -@Component(immediate = true)
56 -@Deprecated
57 -public class OpenFlowHostProvider extends AbstractProvider implements HostProvider {
58 -
59 - private final Logger log = getLogger(getClass());
60 -
61 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
62 - protected HostProviderRegistry providerRegistry;
63 -
64 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
65 - protected OpenFlowController controller;
66 -
67 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
68 - protected TopologyService topologyService;
69 -
70 - private HostProviderService providerService;
71 -
72 - private final InternalHostProvider listener = new InternalHostProvider();
73 -
74 - private boolean ipLearn = true;
75 -
76 - /**
77 - * Creates an OpenFlow host provider.
78 - */
79 - public OpenFlowHostProvider() {
80 - super(new ProviderId("of", "org.onosproject.provider.openflow"));
81 - }
82 -
83 - @Activate
84 - public void activate() {
85 - providerService = providerRegistry.register(this);
86 - controller.addPacketListener(10, listener);
87 - log.info("Started");
88 - }
89 -
90 - @Deactivate
91 - public void deactivate() {
92 - providerRegistry.unregister(this);
93 - controller.removePacketListener(listener);
94 - providerService = null;
95 - log.info("Stopped");
96 - }
97 -
98 - @Override
99 - public void triggerProbe(Host host) {
100 - log.info("Triggering probe on device {}", host);
101 - }
102 -
103 - private class InternalHostProvider implements PacketListener {
104 -
105 - @Override
106 - public void handlePacket(OpenFlowPacketContext pktCtx) {
107 - Ethernet eth = pktCtx.parsed();
108 -
109 - if (eth == null) {
110 - return;
111 - }
112 -
113 - VlanId vlan = VlanId.vlanId(eth.getVlanID());
114 - ConnectPoint heardOn = new ConnectPoint(deviceId(Dpid.uri(pktCtx.dpid())),
115 - portNumber(pktCtx.inPort()));
116 -
117 - // If this is not an edge port, bail out.
118 - Topology topology = topologyService.currentTopology();
119 - if (topologyService.isInfrastructure(topology, heardOn)) {
120 - return;
121 - }
122 -
123 - HostLocation hloc = new HostLocation(deviceId(Dpid.uri(pktCtx.dpid())),
124 - portNumber(pktCtx.inPort()),
125 - System.currentTimeMillis());
126 -
127 - HostId hid = HostId.hostId(eth.getSourceMAC(), vlan);
128 -
129 - // Potentially a new or moved host
130 - if (eth.getEtherType() == Ethernet.TYPE_ARP) {
131 - ARP arp = (ARP) eth.getPayload();
132 - IpAddress ip =
133 - IpAddress.valueOf(IpAddress.Version.INET,
134 - arp.getSenderProtocolAddress());
135 - HostDescription hdescr =
136 - new DefaultHostDescription(eth.getSourceMAC(), vlan, hloc, ip);
137 - providerService.hostDetected(hid, hdescr);
138 -
139 - } else if (ipLearn && eth.getEtherType() == Ethernet.TYPE_IPV4) {
140 - IPv4 pip = (IPv4) eth.getPayload();
141 - IpAddress ip =
142 - IpAddress.valueOf(pip.getSourceAddress());
143 - HostDescription hdescr =
144 - new DefaultHostDescription(eth.getSourceMAC(), vlan, hloc, ip);
145 - providerService.hostDetected(hid, hdescr);
146 -
147 - }
148 -
149 - }
150 -
151 - }
152 -}
1 -/*
2 - * Copyright 2014 Open Networking Laboratory
3 - *
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
7 - *
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.
15 - */
16 -
17 -/**
18 - * Provider that uses OpenFlow controller as a means of host discovery and tracking.
19 - */
20 -package org.onosproject.provider.of.host.impl;
1 -/*
2 - * Copyright 2014 Open Networking Laboratory
3 - *
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
7 - *
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.
15 - */
16 -package org.onosproject.provider.of.host.impl;
17 -
18 -import static org.junit.Assert.assertEquals;
19 -import static org.junit.Assert.assertNotNull;
20 -import static org.junit.Assert.assertNull;
21 -
22 -import java.util.Set;
23 -
24 -import org.junit.After;
25 -import org.junit.Before;
26 -import org.junit.Test;
27 -import org.onosproject.net.ConnectPoint;
28 -import org.onosproject.net.HostId;
29 -import org.onosproject.net.host.HostDescription;
30 -import org.onosproject.net.host.HostProvider;
31 -import org.onosproject.net.host.HostProviderRegistry;
32 -import org.onosproject.net.host.HostProviderService;
33 -import org.onosproject.net.provider.AbstractProviderService;
34 -import org.onosproject.net.provider.ProviderId;
35 -import org.onosproject.net.topology.Topology;
36 -import org.onosproject.net.topology.TopologyServiceAdapter;
37 -import org.onosproject.openflow.controller.Dpid;
38 -import org.onosproject.openflow.controller.OpenFlowPacketContext;
39 -import org.onosproject.openflow.controller.OpenflowControllerAdapter;
40 -import org.onosproject.openflow.controller.PacketListener;
41 -import org.onlab.packet.ARP;
42 -import org.onlab.packet.Ethernet;
43 -import org.onlab.packet.MacAddress;
44 -import org.onlab.packet.VlanId;
45 -import org.projectfloodlight.openflow.protocol.OFMessage;
46 -import org.projectfloodlight.openflow.types.OFPort;
47 -
48 -public class OpenFlowHostProviderTest {
49 -
50 - private static final Integer INPORT = 10;
51 - private static final Dpid DPID1 = new Dpid(100);
52 - private static final Dpid DPID2 = new Dpid(200);
53 - private static final Dpid DPID3 = new Dpid(300);
54 -
55 - private static final VlanId VLAN = VlanId.vlanId();
56 - private static final MacAddress MAC = MacAddress.valueOf("00:00:11:00:00:01");
57 - private static final MacAddress BCMAC = MacAddress.valueOf("ff:ff:ff:ff:ff:ff");
58 - private static final byte[] IP = new byte[]{10, 0, 0, 1};
59 -
60 - private final OpenFlowHostProvider provider = new OpenFlowHostProvider();
61 - private final TestHostRegistry hostService = new TestHostRegistry();
62 - private final TestController controller = new TestController();
63 - private final TestTopologyService topoService = new TestTopologyService();
64 - private TestHostProviderService providerService;
65 -
66 - @Before
67 - public void setUp() {
68 - provider.providerRegistry = hostService;
69 - provider.controller = controller;
70 - provider.topologyService = topoService;
71 - provider.activate();
72 - }
73 -
74 - @Test
75 - public void basics() {
76 - assertNotNull("registration expected", providerService);
77 - assertEquals("incorrect provider", provider, providerService.provider());
78 - }
79 -
80 - @Test
81 - public void events() {
82 - // new host
83 - controller.processPacket(DPID1, null);
84 - assertNotNull("new host expected", providerService.added);
85 - assertNull("host motion unexpected", providerService.moved);
86 -
87 - // the host moved to new switch
88 - controller.processPacket(DPID2, null);
89 - assertNotNull("host motion expected", providerService.moved);
90 -
91 - // the host was misheard on a spine
92 - controller.processPacket(DPID3, null);
93 - assertNull("host misheard on spine switch", providerService.spine);
94 - }
95 -
96 - @After
97 - public void tearDown() {
98 - provider.deactivate();
99 - provider.providerRegistry = null;
100 - provider.controller = null;
101 - }
102 -
103 - private class TestHostRegistry implements HostProviderRegistry {
104 -
105 - @Override
106 - public HostProviderService register(HostProvider provider) {
107 - providerService = new TestHostProviderService(provider);
108 - return providerService;
109 - }
110 -
111 - @Override
112 - public void unregister(HostProvider provider) {
113 - }
114 -
115 - @Override
116 - public Set<ProviderId> getProviders() {
117 - return null;
118 - }
119 -
120 - }
121 -
122 - private class TestHostProviderService
123 - extends AbstractProviderService<HostProvider>
124 - implements HostProviderService {
125 -
126 - Dpid added = null;
127 - Dpid moved = null;
128 - Dpid spine = null;
129 -
130 - protected TestHostProviderService(HostProvider provider) {
131 - super(provider);
132 - }
133 -
134 - @Override
135 - public void hostDetected(HostId hostId, HostDescription hostDescription) {
136 - Dpid descr = Dpid.dpid(hostDescription.location().deviceId().uri());
137 - if (added == null) {
138 - added = descr;
139 - } else if ((moved == null) && !descr.equals(added)) {
140 - moved = descr;
141 - } else {
142 - spine = descr;
143 - }
144 - }
145 -
146 - @Override
147 - public void hostVanished(HostId hostId) {
148 - }
149 -
150 - }
151 -
152 - private class TestController extends OpenflowControllerAdapter {
153 - PacketListener pktListener;
154 -
155 - @Override
156 - public void addPacketListener(int priority, PacketListener listener) {
157 - pktListener = listener;
158 - }
159 -
160 - @Override
161 - public void processPacket(Dpid dpid, OFMessage msg) {
162 - OpenFlowPacketContext ctx = new TestPacketContext(dpid);
163 - pktListener.handlePacket(ctx);
164 - }
165 - }
166 -
167 - private class TestTopologyService extends TopologyServiceAdapter {
168 - @Override
169 - public boolean isInfrastructure(Topology topology,
170 - ConnectPoint connectPoint) {
171 - //simulate DPID3 as an infrastructure switch
172 - if (Dpid.dpid(connectPoint.deviceId().uri()).equals(DPID3)) {
173 - return true;
174 - }
175 - return false;
176 - }
177 - }
178 -
179 - private class TestPacketContext implements OpenFlowPacketContext {
180 -
181 - protected Dpid swid;
182 -
183 - public TestPacketContext(Dpid dpid) {
184 - swid = dpid;
185 - }
186 -
187 - @Override
188 - public boolean block() {
189 - return false;
190 - }
191 -
192 - @Override
193 - public void send() {
194 - }
195 -
196 - @Override
197 - public void build(OFPort outPort) {
198 - }
199 -
200 - @Override
201 - public void build(Ethernet ethFrame, OFPort outPort) {
202 - }
203 -
204 - @Override
205 - public Ethernet parsed() {
206 - // just things we (and serializers) need
207 - ARP arp = new ARP();
208 - arp.setSenderProtocolAddress(IP)
209 - .setSenderHardwareAddress(MAC.toBytes())
210 - .setTargetHardwareAddress(BCMAC.toBytes())
211 - .setTargetProtocolAddress(IP);
212 -
213 - Ethernet eth = new Ethernet();
214 - eth.setEtherType(Ethernet.TYPE_ARP)
215 - .setVlanID(VLAN.toShort())
216 - .setSourceMACAddress(MAC)
217 - .setDestinationMACAddress(BCMAC)
218 - .setPayload(arp);
219 -
220 - return eth;
221 - }
222 -
223 - @Override
224 - public byte[] unparsed() {
225 - return null;
226 - }
227 -
228 - @Override
229 - public Dpid dpid() {
230 - return swid;
231 - }
232 -
233 - @Override
234 - public Integer inPort() {
235 - return INPORT;
236 - }
237 -
238 - @Override
239 - public boolean isHandled() {
240 - return false;
241 - }
242 -
243 - @Override
244 - public boolean isBuffered() {
245 - return false;
246 - }
247 -
248 - }
249 -}
1 -<?xml version="1.0" encoding="UTF-8"?>
2 -<!--
3 - ~ Copyright 2014 Open Networking Laboratory
4 - ~
5 - ~ Licensed under the Apache License, Version 2.0 (the "License");
6 - ~ you may not use this file except in compliance with the License.
7 - ~ You may obtain a copy of the License at
8 - ~
9 - ~ http://www.apache.org/licenses/LICENSE-2.0
10 - ~
11 - ~ Unless required by applicable law or agreed to in writing, software
12 - ~ distributed under the License is distributed on an "AS IS" BASIS,
13 - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 - ~ See the License for the specific language governing permissions and
15 - ~ limitations under the License.
16 - -->
17 -<project xmlns="http://maven.apache.org/POM/4.0.0"
18 - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19 - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
20 - <modelVersion>4.0.0</modelVersion>
21 -
22 - <parent>
23 - <groupId>org.onosproject</groupId>
24 - <artifactId>onos-of-providers</artifactId>
25 - <version>1.2.0-SNAPSHOT</version>
26 - <relativePath>../pom.xml</relativePath>
27 - </parent>
28 -
29 - <artifactId>onos-of-provider-link</artifactId>
30 - <packaging>bundle</packaging>
31 -
32 - <description>ONOS OpenFlow protocol link provider</description>
33 -
34 -</project>
1 -/*
2 - * Copyright 2014 Open Networking Laboratory
3 - *
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
7 - *
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.
15 - */
16 -package org.onosproject.provider.of.link.impl;
17 -
18 -import static org.onosproject.openflow.controller.Dpid.uri;
19 -import static org.slf4j.LoggerFactory.getLogger;
20 -
21 -import java.util.Collections;
22 -import java.util.HashMap;
23 -import java.util.HashSet;
24 -import java.util.Iterator;
25 -import java.util.Map;
26 -import java.util.Set;
27 -import java.util.concurrent.ConcurrentHashMap;
28 -import java.util.concurrent.TimeUnit;
29 -import java.util.concurrent.atomic.AtomicInteger;
30 -
31 -import org.jboss.netty.util.Timeout;
32 -import org.jboss.netty.util.TimerTask;
33 -import org.onosproject.net.ConnectPoint;
34 -import org.onosproject.net.DeviceId;
35 -import org.onosproject.net.Link.Type;
36 -import org.onosproject.net.PortNumber;
37 -import org.onosproject.net.link.DefaultLinkDescription;
38 -import org.onosproject.net.link.LinkDescription;
39 -import org.onosproject.net.link.LinkProviderService;
40 -import org.onosproject.openflow.controller.Dpid;
41 -import org.onosproject.openflow.controller.OpenFlowController;
42 -import org.onosproject.openflow.controller.OpenFlowSwitch;
43 -import org.onlab.packet.Ethernet;
44 -import org.onlab.packet.ONLabLddp;
45 -import org.onlab.packet.ONLabLddp.DPIDandPort;
46 -import org.onlab.util.Timer;
47 -import org.projectfloodlight.openflow.protocol.OFFactory;
48 -import org.projectfloodlight.openflow.protocol.OFMessage;
49 -import org.projectfloodlight.openflow.protocol.OFPacketOut;
50 -import org.projectfloodlight.openflow.protocol.OFPortDesc;
51 -import org.projectfloodlight.openflow.protocol.action.OFAction;
52 -import org.projectfloodlight.openflow.protocol.action.OFActionOutput;
53 -import org.projectfloodlight.openflow.types.OFBufferId;
54 -import org.projectfloodlight.openflow.types.OFPort;
55 -import org.slf4j.Logger;
56 -
57 -
58 -
59 -/**
60 - * Run discovery process from a physical switch. Ports are initially labeled as
61 - * slow ports. When an LLDP is successfully received, label the remote port as
62 - * fast. Every probeRate milliseconds, loop over all fast ports and send an
63 - * LLDP, send an LLDP for a single slow port. Based on FlowVisor topology
64 - * discovery implementation.
65 - */
66 -@Deprecated
67 -public class LinkDiscovery implements TimerTask {
68 -
69 - private final OpenFlowSwitch sw;
70 - // send 1 probe every probeRate milliseconds
71 - private final long probeRate;
72 - private final Set<Integer> slowPorts;
73 - private final Set<Integer> fastPorts;
74 - // number of unacknowledged probes per port
75 - private final Map<Integer, AtomicInteger> portProbeCount;
76 - // number of probes to send before link is removed
77 - private static final short MAX_PROBE_COUNT = 3;
78 - private Iterator<Integer> slowIterator;
79 - private final OFFactory ofFactory;
80 - private final Logger log = getLogger(getClass());
81 - private final ONLabLddp lldpPacket;
82 - private final Ethernet ethPacket;
83 - private Ethernet bddpEth;
84 - private final boolean useBDDP;
85 - private final OpenFlowController ctrl;
86 - private final LinkProviderService linkProvider;
87 - protected final Map<Integer, OFPortDesc> ports;
88 - private Timeout timeout;
89 -
90 - /*
91 - * Instantiates discovery manager for the given physical switch. Creates a
92 - * generic LLDP packet that will be customized for the port it is sent out on.
93 - * Starts the the timer for the discovery process.
94 - *
95 - * @param sw the physical switch
96 - * @param useBDDP flag to also use BDDP for discovery
97 - */
98 - public LinkDiscovery(final OpenFlowSwitch sw,
99 - OpenFlowController ctrl, LinkProviderService providerService, Boolean... useBDDP) {
100 - this.sw = sw;
101 - this.ofFactory = sw.factory();
102 - this.ctrl = ctrl;
103 - this.probeRate = 3000;
104 - this.linkProvider = providerService;
105 - this.slowPorts = Collections.synchronizedSet(new HashSet<Integer>());
106 - this.fastPorts = Collections.synchronizedSet(new HashSet<Integer>());
107 - this.ports = new ConcurrentHashMap<>();
108 - this.portProbeCount = new HashMap<Integer, AtomicInteger>();
109 - this.lldpPacket = new ONLabLddp();
110 - this.lldpPacket.setSwitch(this.sw.getId());
111 - this.ethPacket = new Ethernet();
112 - this.ethPacket.setEtherType(Ethernet.TYPE_LLDP);
113 - this.ethPacket.setDestinationMACAddress(ONLabLddp.LLDP_NICIRA);
114 - this.ethPacket.setPayload(this.lldpPacket);
115 - this.ethPacket.setPad(true);
116 - this.useBDDP = useBDDP.length > 0 ? useBDDP[0] : false;
117 - if (this.useBDDP) {
118 - this.bddpEth = new Ethernet();
119 - this.bddpEth.setPayload(this.lldpPacket);
120 - this.bddpEth.setEtherType(Ethernet.TYPE_BSN);
121 - this.bddpEth.setDestinationMACAddress(ONLabLddp.BDDP_MULTICAST);
122 - this.bddpEth.setPad(true);
123 - log.info("Using BDDP to discover network");
124 - }
125 - for (OFPortDesc port : sw.getPorts()) {
126 - if (port.getPortNo() != OFPort.LOCAL) {
127 - addPort(port);
128 - }
129 - }
130 - timeout = Timer.getTimer().newTimeout(this, 0,
131 - TimeUnit.MILLISECONDS);
132 - this.log.info("Started discovery manager for switch {}",
133 - sw.getId());
134 -
135 - }
136 -
137 - /**
138 - * Add physical port port to discovery process.
139 - * Send out initial LLDP and label it as slow port.
140 - *
141 - * @param port the port
142 - */
143 - public void addPort(final OFPortDesc port) {
144 - // Ignore ports that are not on this switch, or already booted. */
145 - this.ports.put(port.getPortNo().getPortNumber(), port);
146 - synchronized (this) {
147 - this.log.debug("sending init probe to port {}",
148 - port.getPortNo().getPortNumber());
149 - OFPacketOut pkt;
150 -
151 - pkt = this.createLLDPPacketOut(port);
152 - this.sw.sendMsg(pkt);
153 - if (useBDDP) {
154 - OFPacketOut bpkt = this.createBDDPPacketOut(port);
155 - this.sw.sendMsg(bpkt);
156 - }
157 -
158 - this.slowPorts.add(port.getPortNo().getPortNumber());
159 - }
160 -
161 - }
162 -
163 - /**
164 - * Removes physical port from discovery process.
165 - *
166 - * @param port the port
167 - */
168 - public void removePort(final OFPortDesc port) {
169 - // Ignore ports that are not on this switch
170 -
171 - int portnum = port.getPortNo().getPortNumber();
172 - this.ports.remove(portnum);
173 - synchronized (this) {
174 - if (this.slowPorts.contains(portnum)) {
175 - this.slowPorts.remove(portnum);
176 -
177 - } else if (this.fastPorts.contains(portnum)) {
178 - this.fastPorts.remove(portnum);
179 - this.portProbeCount.remove(portnum);
180 - // no iterator to update
181 - } else {
182 - this.log.warn(
183 - "tried to dynamically remove non-existing port {}",
184 - portnum);
185 - }
186 - }
187 - ConnectPoint cp = new ConnectPoint(
188 - DeviceId.deviceId(uri(sw.getId())),
189 - PortNumber.portNumber(port.getPortNo().getPortNumber()));
190 - linkProvider.linksVanished(cp);
191 -
192 - }
193 -
194 - /**
195 - * Method called by remote port to acknowledge receipt of LLDP sent by
196 - * this port. If slow port, updates label to fast. If fast port, decrements
197 - * number of unacknowledged probes.
198 - *
199 - * @param port the port
200 - */
201 - public void ackProbe(final Integer port) {
202 - final int portNumber = port;
203 - synchronized (this) {
204 - if (this.slowPorts.contains(portNumber)) {
205 - this.log.debug("Setting slow port to fast: {}:{}",
206 - this.sw.getId(), portNumber);
207 - this.slowPorts.remove(portNumber);
208 - this.fastPorts.add(portNumber);
209 - this.portProbeCount.put(portNumber, new AtomicInteger(0));
210 - } else {
211 - if (this.fastPorts.contains(portNumber)) {
212 - this.portProbeCount.get(portNumber).set(0);
213 - } else {
214 - this.log.debug(
215 - "Got ackProbe for non-existing port: {}",
216 - portNumber);
217 - }
218 - }
219 - }
220 - }
221 -
222 - /**
223 - * Creates packet_out LLDP for specified output port.
224 - *
225 - * @param port the port
226 - * @return Packet_out message with LLDP data
227 - */
228 - private OFPacketOut createLLDPPacketOut(final OFPortDesc port) {
229 - if (port == null) {
230 - return null;
231 - }
232 - OFPacketOut.Builder packetOut = this.ofFactory.buildPacketOut();
233 - packetOut.setBufferId(OFBufferId.NO_BUFFER);
234 - OFAction act = this.ofFactory.actions().buildOutput()
235 - .setPort(port.getPortNo()).build();
236 - packetOut.setActions(Collections.singletonList(act));
237 - this.lldpPacket.setPort(port.getPortNo().getPortNumber());
238 - this.ethPacket.setSourceMACAddress(port.getHwAddr().getBytes());
239 -
240 - final byte[] lldp = this.ethPacket.serialize();
241 - packetOut.setData(lldp);
242 - return packetOut.build();
243 - }
244 -
245 - /**
246 - * Creates packet_out BDDP for specified output port.
247 - *
248 - * @param port the port
249 - * @return Packet_out message with LLDP data
250 - */
251 - private OFPacketOut createBDDPPacketOut(final OFPortDesc port) {
252 - if (port == null) {
253 - return null;
254 - }
255 - OFPacketOut.Builder packetOut = sw.factory().buildPacketOut();
256 -
257 - packetOut.setBufferId(OFBufferId.NO_BUFFER);
258 -
259 - OFActionOutput.Builder act = sw.factory().actions().buildOutput()
260 - .setPort(port.getPortNo());
261 - OFAction out = act.build();
262 - packetOut.setActions(Collections.singletonList(out));
263 - this.lldpPacket.setPort(port.getPortNo().getPortNumber());
264 - this.bddpEth.setSourceMACAddress(port.getHwAddr().getBytes());
265 -
266 - final byte[] bddp = this.bddpEth.serialize();
267 - packetOut.setData(bddp);
268 -
269 - return packetOut.build();
270 - }
271 -
272 -
273 - private void sendMsg(final OFMessage msg) {
274 - if (msg == null) {
275 - return;
276 - }
277 - this.sw.sendMsg(msg);
278 - }
279 -
280 - public String getName() {
281 - return "LinkDiscovery " + this.sw.getStringId();
282 - }
283 -
284 - /*
285 - * Handles an incoming LLDP packet. Creates link in topology and sends ACK
286 - * to port where LLDP originated.
287 - */
288 - public boolean handleLLDP(final byte[] pkt, Integer inPort) {
289 -
290 - short ethType = ONLabLddp.isOVXLLDP(pkt);
291 - if (ethType == Ethernet.TYPE_LLDP || ethType == Ethernet.TYPE_BSN) {
292 - final Integer dstPort = inPort;
293 - final DPIDandPort dp = ONLabLddp.parseLLDP(pkt);
294 - final OpenFlowSwitch srcSwitch = ctrl.getSwitch(new Dpid(dp.getDpid()));
295 - final Integer srcPort = dp.getPort();
296 - if (srcSwitch == null) {
297 - return true;
298 - }
299 - this.ackProbe(srcPort);
300 - ConnectPoint src = new ConnectPoint(
301 - DeviceId.deviceId(uri(srcSwitch.getId())),
302 - PortNumber.portNumber(srcPort));
303 -
304 - ConnectPoint dst = new ConnectPoint(
305 - DeviceId.deviceId(uri(sw.getId())),
306 - PortNumber.portNumber(dstPort));
307 - LinkDescription ld;
308 - if (ethType == Ethernet.TYPE_BSN) {
309 - ld = new DefaultLinkDescription(src, dst, Type.INDIRECT);
310 - } else {
311 - ld = new DefaultLinkDescription(src, dst, Type.DIRECT);
312 - }
313 - linkProvider.linkDetected(ld);
314 - return true;
315 - } else {
316 - this.log.debug("Ignoring unknown LLDP");
317 - return false;
318 - }
319 - }
320 -
321 - private OFPortDesc findPort(Integer inPort) {
322 - return ports.get(inPort);
323 - }
324 -
325 - /**
326 - * Execute this method every t milliseconds. Loops over all ports
327 - * labeled as fast and sends out an LLDP. Send out an LLDP on a single slow
328 - * port.
329 - *
330 - * @param t timeout
331 - */
332 - @Override
333 - public void run(final Timeout t) {
334 - this.log.debug("sending probes");
335 - synchronized (this) {
336 - final Iterator<Integer> fastIterator = this.fastPorts.iterator();
337 - while (fastIterator.hasNext()) {
338 - final Integer portNumber = fastIterator.next();
339 - OFPortDesc port = findPort(portNumber);
340 - if (port == null) {
341 - // port can be null
342 - // #removePort modifies `ports` outside synchronized block
343 - continue;
344 - }
345 - final int probeCount = this.portProbeCount.get(portNumber)
346 - .getAndIncrement();
347 - if (probeCount < LinkDiscovery.MAX_PROBE_COUNT) {
348 - this.log.debug("sending fast probe to port");
349 -
350 - OFPacketOut pkt = this.createLLDPPacketOut(port);
351 - this.sendMsg(pkt);
352 - if (useBDDP) {
353 - OFPacketOut bpkt = this.createBDDPPacketOut(port);
354 - this.sendMsg(bpkt);
355 - }
356 - } else {
357 - // Update fast and slow ports
358 - fastIterator.remove();
359 - this.slowPorts.add(portNumber);
360 - this.portProbeCount.remove(portNumber);
361 -
362 - // Remove link from topology
363 - final OFPortDesc srcPort = port;
364 -
365 - ConnectPoint cp = new ConnectPoint(
366 - DeviceId.deviceId(uri(sw.getId())),
367 - PortNumber.portNumber(srcPort.getPortNo().getPortNumber()));
368 - linkProvider.linksVanished(cp);
369 - }
370 - }
371 -
372 - // send a probe for the next slow port
373 - if (!this.slowPorts.isEmpty()) {
374 - this.slowIterator = this.slowPorts.iterator();
375 - while (this.slowIterator.hasNext()) {
376 - final int portNumber = this.slowIterator.next();
377 - this.log.debug("sending slow probe to port {}", portNumber);
378 - OFPortDesc port = findPort(portNumber);
379 -
380 - OFPacketOut pkt = this.createLLDPPacketOut(port);
381 - this.sendMsg(pkt);
382 - if (useBDDP) {
383 - OFPacketOut bpkt = this.createBDDPPacketOut(port);
384 - this.sendMsg(bpkt);
385 - }
386 -
387 - }
388 - }
389 - }
390 -
391 - // reschedule timer
392 - timeout = Timer.getTimer().newTimeout(this, this.probeRate,
393 - TimeUnit.MILLISECONDS);
394 - }
395 -
396 - public void removeAllPorts() {
397 - for (OFPortDesc port : ports.values()) {
398 - removePort(port);
399 - }
400 - }
401 -
402 - public void stop() {
403 - timeout.cancel();
404 - removeAllPorts();
405 - }
406 -
407 -}
1 -/*
2 - * Copyright 2014 Open Networking Laboratory
3 - *
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
7 - *
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.
15 - */
16 -package org.onosproject.provider.of.link.impl;
17 -
18 -import static org.slf4j.LoggerFactory.getLogger;
19 -
20 -import java.util.Map;
21 -import java.util.concurrent.ConcurrentHashMap;
22 -
23 -import org.apache.felix.scr.annotations.Activate;
24 -import org.apache.felix.scr.annotations.Component;
25 -import org.apache.felix.scr.annotations.Deactivate;
26 -import org.apache.felix.scr.annotations.Reference;
27 -import org.apache.felix.scr.annotations.ReferenceCardinality;
28 -import org.onosproject.net.DeviceId;
29 -import org.onosproject.net.link.LinkProvider;
30 -import org.onosproject.net.link.LinkProviderRegistry;
31 -import org.onosproject.net.link.LinkProviderService;
32 -import org.onosproject.net.provider.AbstractProvider;
33 -import org.onosproject.net.provider.ProviderId;
34 -import org.onosproject.openflow.controller.Dpid;
35 -import org.onosproject.openflow.controller.OpenFlowController;
36 -import org.onosproject.openflow.controller.OpenFlowPacketContext;
37 -import org.onosproject.openflow.controller.OpenFlowSwitch;
38 -import org.onosproject.openflow.controller.OpenFlowSwitchListener;
39 -import org.onosproject.openflow.controller.PacketListener;
40 -import org.onosproject.openflow.controller.RoleState;
41 -import org.projectfloodlight.openflow.protocol.OFPortConfig;
42 -import org.projectfloodlight.openflow.protocol.OFPortDesc;
43 -import org.projectfloodlight.openflow.protocol.OFPortState;
44 -import org.projectfloodlight.openflow.protocol.OFPortStatus;
45 -import org.slf4j.Logger;
46 -
47 -
48 -/**
49 - * Provider which uses an OpenFlow controller to detect network
50 - * infrastructure links.
51 - */
52 -@Component(immediate = true)
53 -@Deprecated
54 -public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvider {
55 -
56 - private final Logger log = getLogger(getClass());
57 -
58 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
59 - protected LinkProviderRegistry providerRegistry;
60 -
61 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
62 - protected OpenFlowController controller;
63 -
64 - private LinkProviderService providerService;
65 -
66 - private final boolean useBDDP = true;
67 -
68 - private final InternalLinkProvider listener = new InternalLinkProvider();
69 -
70 - protected final Map<Dpid, LinkDiscovery> discoverers = new ConcurrentHashMap<>();
71 -
72 - /**
73 - * Creates an OpenFlow link provider.
74 - */
75 - public OpenFlowLinkProvider() {
76 - super(new ProviderId("of", "org.onosproject.provider.openflow"));
77 - }
78 -
79 - @Activate
80 - public void activate() {
81 - providerService = providerRegistry.register(this);
82 - controller.addListener(listener);
83 - controller.addPacketListener(0, listener);
84 - for (OpenFlowSwitch sw : controller.getSwitches()) {
85 - listener.switchAdded(new Dpid(sw.getId()));
86 - }
87 - log.info("Started");
88 - }
89 -
90 - @Deactivate
91 - public void deactivate() {
92 - for (LinkDiscovery ld : discoverers.values()) {
93 - ld.stop();
94 - }
95 - providerRegistry.unregister(this);
96 - controller.removeListener(listener);
97 - controller.removePacketListener(listener);
98 - providerService = null;
99 -
100 - log.info("Stopped");
101 - }
102 -
103 -
104 - private class InternalLinkProvider implements PacketListener, OpenFlowSwitchListener {
105 -
106 -
107 - @Override
108 - public void handlePacket(OpenFlowPacketContext pktCtx) {
109 - LinkDiscovery ld = discoverers.get(pktCtx.dpid());
110 - if (ld == null) {
111 - return;
112 - }
113 - if (ld.handleLLDP(pktCtx.unparsed(), pktCtx.inPort())) {
114 - pktCtx.block();
115 - }
116 -
117 - }
118 -
119 - @Override
120 - public void switchAdded(Dpid dpid) {
121 - discoverers.put(dpid, new LinkDiscovery(controller.getSwitch(dpid),
122 - controller, providerService, useBDDP));
123 -
124 - }
125 -
126 - @Override
127 - public void switchRemoved(Dpid dpid) {
128 - LinkDiscovery ld = discoverers.remove(dpid);
129 - if (ld != null) {
130 - ld.removeAllPorts();
131 - }
132 - providerService.linksVanished(
133 - DeviceId.deviceId("of:" + Long.toHexString(dpid.value())));
134 - }
135 -
136 -
137 - @Override
138 - public void switchChanged(Dpid dpid) {
139 - //might not need to do anything since DeviceManager is notified
140 - }
141 -
142 - @Override
143 - public void portChanged(Dpid dpid, OFPortStatus status) {
144 - LinkDiscovery ld = discoverers.get(dpid);
145 - if (ld == null) {
146 - return;
147 - }
148 - final OFPortDesc port = status.getDesc();
149 - final boolean enabled = !port.getState().contains(OFPortState.LINK_DOWN) &&
150 - !port.getConfig().contains(OFPortConfig.PORT_DOWN);
151 - if (enabled) {
152 - ld.addPort(port);
153 - } else {
154 - /*
155 - * remove port calls linkVanished
156 - */
157 - ld.removePort(port);
158 - }
159 -
160 - }
161 -
162 - @Override
163 - public void receivedRoleReply(Dpid dpid, RoleState requested,
164 - RoleState response) {
165 - // do nothing for this.
166 - }
167 -
168 - }
169 -
170 -}
1 -/*
2 - * Copyright 2014 Open Networking Laboratory
3 - *
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
7 - *
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.
15 - */
16 -
17 -/**
18 - * Provider that uses OpenFlow controller as a means of infrastructure link inference.
19 - */
20 -package org.onosproject.provider.of.link.impl;
1 -/*
2 - * Copyright 2014 Open Networking Laboratory
3 - *
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
7 - *
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.
15 - */
16 -package org.onosproject.provider.of.link.impl;
17 -
18 -import static org.junit.Assert.assertEquals;
19 -import static org.junit.Assert.assertFalse;
20 -import static org.junit.Assert.assertNotNull;
21 -import static org.junit.Assert.assertNull;
22 -import static org.junit.Assert.assertTrue;
23 -
24 -import java.util.ArrayList;
25 -import java.util.Collections;
26 -import java.util.HashMap;
27 -import java.util.List;
28 -import java.util.Map;
29 -import java.util.Set;
30 -
31 -import org.junit.After;
32 -import org.junit.Before;
33 -import org.junit.Test;
34 -import org.onosproject.net.ConnectPoint;
35 -import org.onosproject.net.DeviceId;
36 -import org.onosproject.net.link.LinkDescription;
37 -import org.onosproject.net.link.LinkProvider;
38 -import org.onosproject.net.link.LinkProviderRegistry;
39 -import org.onosproject.net.link.LinkProviderService;
40 -import org.onosproject.net.provider.AbstractProviderService;
41 -import org.onosproject.net.provider.ProviderId;
42 -import org.onosproject.openflow.controller.Dpid;
43 -import org.onosproject.openflow.controller.OpenFlowPacketContext;
44 -import org.onosproject.openflow.controller.OpenFlowSwitch;
45 -import org.onosproject.openflow.controller.OpenFlowSwitchListener;
46 -import org.onosproject.openflow.controller.OpenflowControllerAdapter;
47 -import org.onosproject.openflow.controller.PacketListener;
48 -import org.onosproject.openflow.controller.RoleState;
49 -import org.onosproject.openflow.controller.OpenFlowSwitch.TableType;
50 -import org.onlab.packet.Ethernet;
51 -import org.onlab.packet.ONLabLddp;
52 -import org.projectfloodlight.openflow.protocol.OFFactory;
53 -import org.projectfloodlight.openflow.protocol.OFMessage;
54 -import org.projectfloodlight.openflow.protocol.OFPortConfig;
55 -import org.projectfloodlight.openflow.protocol.OFPortDesc;
56 -import org.projectfloodlight.openflow.protocol.OFPortReason;
57 -import org.projectfloodlight.openflow.protocol.OFPortStatus;
58 -import org.projectfloodlight.openflow.protocol.ver10.OFFactoryVer10;
59 -import org.projectfloodlight.openflow.types.OFPort;
60 -import org.projectfloodlight.openflow.types.TableId;
61 -
62 -import com.google.common.collect.Lists;
63 -import com.google.common.collect.Maps;
64 -
65 -public class OpenFlowLinkProviderTest {
66 -
67 -
68 - private static final DeviceId DID1 = DeviceId.deviceId("of:0000000000000001");
69 - private static final DeviceId DID2 = DeviceId.deviceId("of:0000000000000002");
70 -
71 - private static final Dpid DPID2 = Dpid.dpid(DID2.uri());
72 - private static final Dpid DPID1 = Dpid.dpid(DID1.uri());
73 -
74 - private static final OFPortDesc PD1 = portDesc(1, true);
75 - private static final OFPortDesc PD2 = portDesc(2, true);
76 - private static final OFPortDesc PD3 = portDesc(1, true);
77 - private static final OFPortDesc PD4 = portDesc(2, true);
78 -
79 - private static final List<OFPortDesc> PLIST1 = Lists.newArrayList(PD1, PD2);
80 - private static final List<OFPortDesc> PLIST2 = Lists.newArrayList(PD3, PD4);
81 -
82 - private static final TestOpenFlowSwitch SW1 = new TestOpenFlowSwitch(DPID1, PLIST1);
83 - private static final TestOpenFlowSwitch SW2 = new TestOpenFlowSwitch(DPID2, PLIST2);
84 -
85 - private final OpenFlowLinkProvider provider = new OpenFlowLinkProvider();
86 - private final TestLinkRegistry linkService = new TestLinkRegistry();
87 - private final TestController controller = new TestController();
88 -
89 - private TestLinkProviderService providerService;
90 - private TestPacketContext pktCtx;
91 -
92 - @Before
93 - public void setUp() {
94 - pktCtx = new TestPacketContext(DPID2);
95 - provider.providerRegistry = linkService;
96 - controller.switchMap.put(DPID1, SW1);
97 - controller.switchMap.put(DPID2, SW2);
98 - provider.controller = controller;
99 - provider.activate();
100 - }
101 -
102 - @Test
103 - public void basics() {
104 - assertNotNull("registration expected", providerService);
105 - assertEquals("incorrect provider", provider, providerService.provider());
106 - }
107 -
108 - @Test
109 - public void switchAdd() {
110 - controller.listener.switchAdded(DPID1);
111 - assertFalse("Device not added", provider.discoverers.isEmpty());
112 - }
113 -
114 - @Test
115 - public void switchRemove() {
116 - controller.listener.switchAdded(DPID1);
117 - controller.listener.switchRemoved(DPID1);
118 -
119 - assertTrue("Discoverer is not gone", provider.discoverers.isEmpty());
120 - assertTrue("Device is not gone.", vanishedDpid(DPID1));
121 - }
122 -
123 - @Test
124 - public void portUp() {
125 - controller.listener.switchAdded(DPID1);
126 - controller.listener.portChanged(DPID1, portStatus(true, 3));
127 -
128 - assertTrue("Port not added to discoverer",
129 - provider.discoverers.get(DPID1).ports.containsKey(3));
130 - }
131 -
132 - @Test
133 - public void portDown() {
134 - controller.listener.switchAdded(DPID1);
135 - controller.listener.portChanged(DPID1, portStatus(false, 1));
136 -
137 - assertFalse("Port added to discoverer",
138 - provider.discoverers.get(DPID1).ports.containsKey(1));
139 - assertTrue("Port is not gone.", vanishedPort((long) 1));
140 - }
141 -
142 - @Test
143 - public void portUnknown() {
144 - controller.listener.switchAdded(DPID1);
145 - controller.listener.portChanged(DPID2, portStatus(false, 1));
146 -
147 - assertNull("DPID exists",
148 - provider.discoverers.get(DPID2));
149 - }
150 -
151 - @Test
152 - public void unknownPktCtx() {
153 - controller.pktListener.handlePacket(pktCtx);
154 -
155 - assertFalse("Context should still be free", pktCtx.isHandled());
156 - }
157 -
158 - @Test
159 - public void knownPktCtx() {
160 - controller.listener.switchAdded(DPID1);
161 - controller.listener.switchAdded(DPID2);
162 -
163 - controller.pktListener.handlePacket(pktCtx);
164 -
165 - assertTrue("Link not detected", detectedLink(DPID1, DPID2));
166 -
167 - }
168 -
169 -
170 - @After
171 - public void tearDown() {
172 - provider.deactivate();
173 - provider.providerRegistry = null;
174 - provider.controller = null;
175 - }
176 -
177 - private OFPortStatus portStatus(boolean up, int port) {
178 - OFPortDesc desc = portDesc(port, up);
179 - OFPortStatus status = OFFactoryVer10.INSTANCE.buildPortStatus()
180 - .setDesc(desc)
181 - .setReason(up ? OFPortReason.ADD : OFPortReason.DELETE).build();
182 - return status;
183 -
184 - }
185 -
186 - private static OFPortDesc portDesc(int port, boolean up) {
187 - OFPortDesc.Builder builder = OFFactoryVer10.INSTANCE.buildPortDesc();
188 - builder.setPortNo(OFPort.of(port));
189 - if (!up) {
190 - builder.setConfig(Collections.singleton(OFPortConfig.PORT_DOWN));
191 - }
192 - return builder.build();
193 - }
194 -
195 - private boolean vanishedDpid(Dpid... dpids) {
196 - for (int i = 0; i < dpids.length; i++) {
197 - if (!providerService.vanishedDpid.contains(dpids[i])) {
198 - return false;
199 - }
200 - }
201 - return true;
202 - }
203 -
204 - private boolean vanishedPort(Long... ports) {
205 - for (int i = 0; i < ports.length; i++) {
206 - if (!providerService.vanishedPort.contains(ports[i])) {
207 - return false;
208 - }
209 - }
210 - return true;
211 - }
212 -
213 - private boolean detectedLink(Dpid src, Dpid dst) {
214 - for (Dpid key : providerService.discoveredLinks.keySet()) {
215 - if (key.equals(src)) {
216 - return providerService.discoveredLinks.get(src).equals(dst);
217 - }
218 - }
219 - return false;
220 - }
221 -
222 -
223 - private class TestLinkRegistry implements LinkProviderRegistry {
224 -
225 - @Override
226 - public LinkProviderService register(LinkProvider provider) {
227 - providerService = new TestLinkProviderService(provider);
228 - return providerService;
229 - }
230 -
231 - @Override
232 - public void unregister(LinkProvider provider) {
233 - }
234 -
235 - @Override
236 - public Set<ProviderId> getProviders() {
237 - return null;
238 - }
239 -
240 - }
241 -
242 - private class TestLinkProviderService
243 - extends AbstractProviderService<LinkProvider>
244 - implements LinkProviderService {
245 -
246 - List<Dpid> vanishedDpid = Lists.newLinkedList();
247 - List<Long> vanishedPort = Lists.newLinkedList();
248 - Map<Dpid, Dpid> discoveredLinks = Maps.newHashMap();
249 -
250 - protected TestLinkProviderService(LinkProvider provider) {
251 - super(provider);
252 - }
253 -
254 - @Override
255 - public void linkDetected(LinkDescription linkDescription) {
256 - Dpid sDpid = Dpid.dpid(linkDescription.src().deviceId().uri());
257 - Dpid dDpid = Dpid.dpid(linkDescription.dst().deviceId().uri());
258 - discoveredLinks.put(sDpid, dDpid);
259 - }
260 -
261 - @Override
262 - public void linkVanished(LinkDescription linkDescription) {
263 - }
264 -
265 - @Override
266 - public void linksVanished(ConnectPoint connectPoint) {
267 - vanishedPort.add(connectPoint.port().toLong());
268 -
269 - }
270 -
271 - @Override
272 - public void linksVanished(DeviceId deviceId) {
273 - vanishedDpid.add(Dpid.dpid(deviceId.uri()));
274 - }
275 -
276 -
277 - }
278 -
279 - private class TestController extends OpenflowControllerAdapter {
280 - PacketListener pktListener;
281 - OpenFlowSwitchListener listener;
282 - Map<Dpid, OpenFlowSwitch> switchMap = new HashMap<Dpid, OpenFlowSwitch>();
283 -
284 - @Override
285 - public void addPacketListener(int priority, PacketListener listener) {
286 - pktListener = listener;
287 - }
288 -
289 - @Override
290 - public void removePacketListener(PacketListener listener) {
291 - pktListener = null;
292 - }
293 -
294 - @Override
295 - public void addListener(OpenFlowSwitchListener listener) {
296 - this.listener = listener;
297 - }
298 -
299 - @Override
300 - public void removeListener(OpenFlowSwitchListener listener) {
301 - this.listener = null;
302 - }
303 -
304 - @Override
305 - public void processPacket(Dpid dpid, OFMessage msg) {
306 - OpenFlowPacketContext ctx = new TestPacketContext(dpid);
307 - pktListener.handlePacket(ctx);
308 - }
309 -
310 - @Override
311 - public Iterable<OpenFlowSwitch> getSwitches() {
312 - return Collections.emptyList();
313 - }
314 -
315 - @Override
316 - public OpenFlowSwitch getSwitch(Dpid dpid) {
317 - return switchMap.get(dpid);
318 - }
319 - }
320 -
321 -
322 -
323 - private class TestPacketContext implements OpenFlowPacketContext {
324 -
325 - protected Dpid swid;
326 - protected boolean blocked = false;
327 -
328 - public TestPacketContext(Dpid dpid) {
329 - swid = dpid;
330 - }
331 -
332 - @Override
333 - public boolean block() {
334 - blocked = true;
335 - return blocked;
336 - }
337 -
338 - @Override
339 - public void send() {
340 - }
341 -
342 - @Override
343 - public void build(OFPort outPort) {
344 - }
345 -
346 - @Override
347 - public void build(Ethernet ethFrame, OFPort outPort) {
348 - }
349 -
350 - @Override
351 - public Ethernet parsed() {
352 - return null;
353 - }
354 -
355 - @Override
356 - public byte[] unparsed() {
357 - ONLabLddp lldp = new ONLabLddp();
358 - lldp.setSwitch(DPID1.value());
359 -
360 - Ethernet ethPacket = new Ethernet();
361 - ethPacket.setEtherType(Ethernet.TYPE_LLDP);
362 - ethPacket.setDestinationMACAddress(ONLabLddp.LLDP_NICIRA);
363 - ethPacket.setPayload(lldp);
364 - ethPacket.setPad(true);
365 -
366 -
367 - lldp.setPort(PD1.getPortNo().getPortNumber());
368 - ethPacket.setSourceMACAddress(PD1.getHwAddr().getBytes());
369 - return ethPacket.serialize();
370 -
371 - }
372 -
373 - @Override
374 - public Dpid dpid() {
375 - return swid;
376 - }
377 -
378 - @Override
379 - public Integer inPort() {
380 - return PD3.getPortNo().getPortNumber();
381 - }
382 -
383 - @Override
384 - public boolean isHandled() {
385 - return blocked;
386 - }
387 -
388 - @Override
389 - public boolean isBuffered() {
390 - return false;
391 - }
392 -
393 - }
394 -
395 - private static class TestOpenFlowSwitch implements OpenFlowSwitch {
396 -
397 - private final List<OFPortDesc> ports;
398 - private final Dpid dpid;
399 -
400 - public TestOpenFlowSwitch(Dpid dpid, List<OFPortDesc> ports) {
401 - this.ports = ports;
402 - this.dpid = dpid;
403 - }
404 -
405 - RoleState state;
406 - List<OFMessage> sent = new ArrayList<OFMessage>();
407 - OFFactory factory = OFFactoryVer10.INSTANCE;
408 -
409 - @Override
410 - public void sendMsg(OFMessage msg) {
411 - sent.add(msg);
412 - }
413 -
414 - @Override
415 - public void sendMsg(List<OFMessage> msgs) {
416 - }
417 -
418 - @Override
419 - public void handleMessage(OFMessage fromSwitch) {
420 - }
421 -
422 - @Override
423 - public void setRole(RoleState role) {
424 - state = role;
425 - }
426 -
427 - @Override
428 - public RoleState getRole() {
429 - return state;
430 - }
431 -
432 - @Override
433 - public List<OFPortDesc> getPorts() {
434 - return ports;
435 - }
436 -
437 - @Override
438 - public OFFactory factory() {
439 - return factory;
440 - }
441 -
442 - @Override
443 - public String getStringId() {
444 - return null;
445 - }
446 -
447 - @Override
448 - public long getId() {
449 - return dpid.value();
450 - }
451 -
452 - @Override
453 - public String manufacturerDescription() {
454 - return null;
455 - }
456 -
457 - @Override
458 - public String datapathDescription() {
459 - return null;
460 - }
461 -
462 - @Override
463 - public String hardwareDescription() {
464 - return null;
465 - }
466 -
467 - @Override
468 - public String softwareDescription() {
469 - return null;
470 - }
471 -
472 - @Override
473 - public String serialNumber() {
474 - return null;
475 - }
476 -
477 - @Override
478 - public boolean isConnected() {
479 - return true;
480 - }
481 -
482 - @Override
483 - public void disconnectSwitch() {
484 - }
485 -
486 - @Override
487 - public boolean isOptical() {
488 - return false;
489 - }
490 -
491 - @Override
492 - public void returnRoleReply(RoleState requested, RoleState reponse) {
493 - }
494 -
495 - @Override
496 - public String channelId() {
497 - return "1.2.3.4:1";
498 - }
499 -
500 - @Override
501 - public TableType getTableType(TableId tid) {
502 - return TableType.NONE;
503 - }
504 -
505 - @Override
506 - public void transformAndSendMsg(OFMessage msg, TableType tableType) {
507 - // TODO Auto-generated method stub
508 - }
509 -
510 - }
511 -}
...@@ -33,8 +33,6 @@ ...@@ -33,8 +33,6 @@
33 33
34 <modules> 34 <modules>
35 <module>device</module> 35 <module>device</module>
36 - <module>link</module>
37 - <module>host</module>
38 <module>packet</module> 36 <module>packet</module>
39 <module>flow</module> 37 <module>flow</module>
40 <module>group</module> 38 <module>group</module>
......
1 -/*
2 - * Copyright 2014 Open Networking Laboratory
3 - *
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
7 - *
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.
15 - */
16 -package org.onlab.packet;
17 -
18 -import java.nio.ByteBuffer;
19 -import java.nio.charset.StandardCharsets;
20 -import java.util.Arrays;
21 -import java.util.LinkedList;
22 -import java.util.List;
23 -
24 -import org.apache.commons.lang.ArrayUtils;
25 -import org.slf4j.Logger;
26 -import org.slf4j.LoggerFactory;
27 -
28 -
29 -/**
30 - * LLDP packets OpenVirteX uses for discovery of physical network topology.
31 - * Refer to IEEE Std 802.1ABTM-2009 for more information.
32 - *
33 - */
34 -@Deprecated
35 -public class ONLabLddp extends LLDP {
36 -
37 - private static final Logger LOG = LoggerFactory.getLogger(ONLabLddp.class);
38 - // ON.Lab OUI and OVX name for organizationally specific TLVs
39 - public static final byte[] ONLAB_OUI = {(byte) 0xa4, 0x23, 0x05};
40 - public static final String OVX_NAME = "OpenVirteX";
41 - public static final byte[] LLDP_NICIRA = {0x01, 0x23, 0x20, 0x00, 0x00,
42 - 0x01};
43 - public static final byte[] LLDP_MULTICAST = {0x01, (byte) 0x80,
44 - (byte) 0xc2, 0x00, 0x00, 0x0e};
45 - public static final byte[] BDDP_MULTICAST = {(byte) 0xff, (byte) 0xff,
46 - (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff};
47 - public static final short ETHERTYPE_VLAN = (short) 0x8100;
48 -
49 - // TLV constants: type, size and subtype
50 - // Organizationally specific TLV also have packet offset and contents of TLV
51 - // header
52 - private static final byte CHASSIS_TLV_TYPE = 1;
53 - private static final byte CHASSIS_TLV_SIZE = 7;
54 - private static final byte CHASSIS_TLV_SUBTYPE = 4;
55 -
56 - private static final byte PORT_TLV_TYPE = 2;
57 - private static final byte PORT_TLV_SIZE = 5;
58 - private static final byte PORT_TLV_SUBTYPE = 2;
59 -
60 - private static final byte TTL_TLV_TYPE = 3;
61 - private static final byte TTL_TLV_SIZE = 2;
62 -
63 - private static final byte NAME_TLV_TYPE = 127;
64 - // 4 = OUI (3) + subtype (1)
65 - private static final byte NAME_TLV_SIZE = (byte) (4 + ONLabLddp.OVX_NAME.length());
66 - private static final byte NAME_TLV_SUBTYPE = 1;
67 - private static final short NAME_TLV_OFFSET = 34;
68 - private static final short NAME_TLV_HEADER = (short) ((NAME_TLV_TYPE << 9) | NAME_TLV_SIZE);
69 - // Contents of full name TLV
70 - private static final byte[] NAME_TLV = ByteBuffer.allocate(NAME_TLV_SIZE + 2)
71 - .putShort(NAME_TLV_HEADER).put(ONLAB_OUI).put(NAME_TLV_SUBTYPE)
72 - .put(OVX_NAME.getBytes(StandardCharsets.UTF_8)).array();
73 -
74 - private static final byte DPID_TLV_TYPE = 127;
75 - private static final byte DPID_TLV_SIZE = (byte) (12); // 12 = OUI (3) + subtype
76 - // (1) + dpid (8)
77 - private static final byte DPID_TLV_SUBTYPE = 2;
78 - private static final short DPID_TLV_HEADER = (short) ((DPID_TLV_TYPE << 9) | DPID_TLV_SIZE);
79 - // Contents of dpid TLV
80 - // Note that this does *not* contain the actual dpid since we cannot match
81 - // on it
82 - private static final byte[] DPID_TLV = ByteBuffer.allocate(DPID_TLV_SIZE + 2 - 8)
83 - .putShort(DPID_TLV_HEADER).put(ONLAB_OUI).put(DPID_TLV_SUBTYPE)
84 - .array();
85 -
86 - // Pre-built contents of both organizationally specific TLVs
87 - private static final byte[] OUI_TLV = ArrayUtils.addAll(NAME_TLV, DPID_TLV);
88 -
89 - // Default switch, port number and TTL
90 - private static final byte[] DEFAULT_DPID = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
91 - 0x00, 0x00 };
92 - private static final int DEFAULT_PORT = 0;
93 - private static final short DEFAULT_TTL = 120; // in seconds
94 -
95 - // Minimum and OVX-generated LLDP packet sizes
96 - private static final short MINIMUM_LLDP_SIZE = 61;
97 - // Add 12 for 2-byte header of each TLV and a single EndOfLLDPTLV
98 - private static final short OVX_LLDP_SIZE = (short) (CHASSIS_TLV_SIZE
99 - + PORT_TLV_SIZE + TTL_TLV_SIZE + NAME_TLV_SIZE + DPID_TLV_SIZE + 12);
100 -
101 - // Field offsets in OVX-generated LLDP
102 - private static final short ETHERTYPE_OFFSET = 12;
103 - private static final short PORT_OFFSET = 26;
104 - private static final short DPID_OFFSET = 56;
105 -
106 - // Private member fields
107 - // Byte arrays for TLV information string
108 - private ByteBuffer bb;
109 - private final byte[] chassisId = new byte[CHASSIS_TLV_SIZE];
110 - private final byte[] portId = new byte[PORT_TLV_SIZE];
111 - private final byte[] ttl = new byte[TTL_TLV_SIZE];
112 - private final byte[] ouiName = new byte[NAME_TLV_SIZE];
113 - private final byte[] ouiDpid = new byte[DPID_TLV_SIZE];
114 -
115 - // TLVs
116 - private final LLDPTLV chassisTLV;
117 - private final LLDPTLV portTLV;
118 - private final LLDPTLV ttlTLV;
119 - private final LLDPTLV ouiNameTLV;
120 - private final LLDPTLV ouiDpidTLV;
121 - private final List<LLDPTLV> optionalTLVList;
122 -
123 - /**
124 - * Instantiates a new OVX LDDP message.
125 - */
126 - public ONLabLddp() {
127 - // Create TLVs
128 - this.chassisTLV = new LLDPTLV();
129 - this.portTLV = new LLDPTLV();
130 - this.ttlTLV = new LLDPTLV();
131 - this.ouiNameTLV = new LLDPTLV();
132 - this.ouiDpidTLV = new LLDPTLV();
133 - this.optionalTLVList = new LinkedList<LLDPTLV>();
134 - this.optionalTLVList.add(this.ouiNameTLV);
135 - this.optionalTLVList.add(this.ouiDpidTLV);
136 -
137 - // Add TLVs to LLDP packet
138 - this.setChassisId(this.chassisTLV);
139 - this.setPortId(this.portTLV);
140 - this.setTtl(this.ttlTLV);
141 - this.setOptionalTLVList(this.optionalTLVList);
142 -
143 - // Set TLVs to default values
144 - this.setChassisTLV(DEFAULT_DPID);
145 - this.setPortTLV(DEFAULT_PORT);
146 - this.setTTLTLV(DEFAULT_TTL);
147 - this.setOUIName(ONLabLddp.OVX_NAME);
148 - this.setOUIDpid(DEFAULT_DPID);
149 - }
150 -
151 - /**
152 - * Sets chassis TLV. Note that we can only put 6 bytes in the chassis ID, so
153 - * we use another organizationally specific TLV to put the full dpid (see
154 - * setOUIDpid()).
155 - *
156 - * @param dpid the switch DPID
157 - */
158 - private void setChassisTLV(final byte[] dpid) {
159 - this.bb = ByteBuffer.wrap(this.chassisId);
160 - this.bb.put(CHASSIS_TLV_SUBTYPE);
161 - for (int i = 2; i < 8; i++) {
162 - bb.put(dpid[i]);
163 - }
164 - this.chassisTLV.setLength(CHASSIS_TLV_SIZE);
165 - this.chassisTLV.setType(CHASSIS_TLV_TYPE);
166 - this.chassisTLV.setValue(this.chassisId);
167 - }
168 -
169 - /**
170 - * Sets port TLV.
171 - *
172 - * @param portNumber the port number
173 - */
174 - private void setPortTLV(final int portNumber) {
175 - this.bb = ByteBuffer.wrap(this.portId);
176 - this.bb.put(PORT_TLV_SUBTYPE);
177 - this.bb.putInt(portNumber);
178 -
179 - this.portTLV.setLength(PORT_TLV_SIZE);
180 - this.portTLV.setType(PORT_TLV_TYPE);
181 - this.portTLV.setValue(this.portId);
182 - }
183 -
184 - /**
185 - * Sets Time To Live TLV.
186 - *
187 - * @param time the time to live
188 - */
189 - private void setTTLTLV(final short time) {
190 - this.bb = ByteBuffer.wrap(this.ttl);
191 - this.bb.putShort(time);
192 -
193 - this.ttlTLV.setLength(TTL_TLV_SIZE);
194 - this.ttlTLV.setType(TTL_TLV_TYPE);
195 - this.ttlTLV.setValue(this.ttl);
196 - }
197 -
198 - /**
199 - * Set. organizationally specific TLV for OVX name (subtype 1).
200 - *
201 - * @param name the name
202 - */
203 - private void setOUIName(final String name) {
204 - this.bb = ByteBuffer.wrap(ouiName);
205 - this.bb.put(ONLabLddp.ONLAB_OUI);
206 - this.bb.put(NAME_TLV_SUBTYPE);
207 - this.bb.put(name.getBytes(StandardCharsets.UTF_8));
208 -
209 - this.ouiNameTLV.setLength(NAME_TLV_SIZE);
210 - this.ouiNameTLV.setType(NAME_TLV_TYPE);
211 - this.ouiNameTLV.setValue(ouiName);
212 - }
213 -
214 - /**
215 - * Sets organizationally specific TLV for OVX full dpid (subtype 2).
216 - *
217 - * @param dpid the switch DPID
218 - */
219 - private void setOUIDpid(final byte[] dpid) {
220 - this.bb = ByteBuffer.wrap(ouiDpid);
221 - this.bb.put(ONLabLddp.ONLAB_OUI);
222 - this.bb.put(DPID_TLV_SUBTYPE);
223 - this.bb.put(dpid);
224 -
225 - this.ouiDpidTLV.setLength(DPID_TLV_SIZE);
226 - this.ouiDpidTLV.setType(DPID_TLV_TYPE);
227 - this.ouiDpidTLV.setValue(ouiDpid);
228 - }
229 -
230 - /**
231 - * Sets switch DPID in LLDP packet.
232 - *
233 - * @param dp the switch instance
234 - */
235 - public void setSwitch(long dp) {
236 - final byte[] dpid = ByteBuffer.allocate(8).putLong(dp)
237 - .array();
238 - this.setChassisTLV(dpid);
239 - this.setOUIDpid(dpid);
240 - }
241 -
242 - /**
243 - * Sets port in LLDP packet.
244 - *
245 - * @param port the port instance
246 - */
247 - public void setPort(int port) {
248 - this.setPortTLV(port);
249 - }
250 -
251 - /**
252 - * Serializes full LLDP packet to byte array. Need to set both switch and
253 - * port before you can serialize.
254 - */
255 - @Override
256 - public byte[] serialize() {
257 - return super.serialize();
258 - }
259 -
260 - /**
261 - * Checks if LLDP packet has correct size, LLDP multicast address, and
262 - * ethertype. Packet assumed to have Ethernet header.
263 - *
264 - * @param packet packet data
265 - * @return true if packet is LLDP, false otherwise
266 - */
267 - public static boolean isLLDP(final byte[] packet) {
268 - // Does packet exist and does it have the mininum size?
269 - if (packet == null || packet.length < MINIMUM_LLDP_SIZE) {
270 - return false;
271 - }
272 -
273 - // Packet has LLDP multicast destination address?
274 - final ByteBuffer bb = ByteBuffer.wrap(packet);
275 - final byte[] dst = new byte[6];
276 - bb.get(dst);
277 -
278 - if (!(Arrays.equals(dst, ONLabLddp.LLDP_NICIRA)
279 - || Arrays.equals(dst, ONLabLddp.LLDP_MULTICAST) || Arrays.equals(
280 - dst, ONLabLddp.BDDP_MULTICAST))) {
281 -
282 - return false;
283 - }
284 -
285 - // Fetch ethertype, skip VLAN tag if it's there
286 - short etherType = bb.getShort(ETHERTYPE_OFFSET);
287 - if (etherType == ETHERTYPE_VLAN) {
288 - etherType = bb.getShort(ETHERTYPE_OFFSET + 4);
289 - }
290 -
291 - // Check ethertype
292 - if (etherType == Ethernet.TYPE_LLDP) {
293 - return true;
294 - }
295 - if (etherType == Ethernet.TYPE_BSN) {
296 - return true;
297 - }
298 -
299 - return false;
300 -
301 - }
302 -
303 - /**
304 - * Checks if packet has size of OVX-generated LLDP, and correctness of two
305 - * organizationally specific TLVs that use ON.Lab's OUI. Assumes packet is
306 - * valid LLDP packet
307 - *
308 - * @param packet packet data
309 - * @return eth type or -1
310 - */
311 - public static short isOVXLLDP(byte[] packet) {
312 - if (packet.length < OVX_LLDP_SIZE) {
313 - return -1;
314 - }
315 -
316 - // Extra offset due to VLAN tag
317 - final ByteBuffer bb = ByteBuffer.wrap(packet);
318 - int offset = 0;
319 - short ethType = bb.getShort(ETHERTYPE_OFFSET);
320 - if (ethType != Ethernet.TYPE_LLDP
321 - && ethType != Ethernet.TYPE_BSN) {
322 - offset = 4;
323 - ethType = bb.getShort(ETHERTYPE_OFFSET + offset);
324 - if (ethType != Ethernet.TYPE_LLDP
325 - && ethType != Ethernet.TYPE_BSN) {
326 - return -1;
327 - }
328 - }
329 -
330 - // Compare packet's organizationally specific TLVs to the expected
331 - // values
332 - for (int i = 0; i < OUI_TLV.length; i++) {
333 - if (packet[NAME_TLV_OFFSET + offset + i] != OUI_TLV[i]) {
334 - return -1;
335 - }
336 - }
337 -
338 - return ethType;
339 - }
340 -
341 - /**
342 - * Extracts dpid and port from OVX-generated LLDP packet.
343 - *
344 - * @param packet packet data
345 - * @return Dpid and port
346 - */
347 - public static DPIDandPort parseLLDP(final byte[] packet) {
348 - final ByteBuffer bb = ByteBuffer.wrap(packet);
349 -
350 - // Extra offset due to VLAN tag
351 - int offset = 0;
352 - if (bb.getShort(ETHERTYPE_OFFSET) != Ethernet.TYPE_LLDP
353 - && bb.getShort(ETHERTYPE_OFFSET) != Ethernet.TYPE_BSN) {
354 - offset = 4;
355 - }
356 -
357 - final int port = bb.getInt(PORT_OFFSET + offset);
358 - final long dpid = bb.getLong(DPID_OFFSET + offset);
359 -
360 - return new DPIDandPort(dpid, port);
361 - }
362 -
363 - public static class DPIDandPort {
364 -
365 - private final long dpid;
366 - private final int port;
367 -
368 - public DPIDandPort(long dpid, int port) {
369 - this.dpid = dpid;
370 - this.port = port;
371 - }
372 -
373 - public long getDpid() {
374 - return this.dpid;
375 - }
376 -
377 - public int getPort() {
378 - return this.port;
379 - }
380 -
381 - }
382 -
383 -}