Open Kilda Java Documentation
PathDiscover.java
Go to the documentation of this file.
1 /* Copyright 2017 Telstra Open Source
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package org.openkilda.floodlight.pathverification.web;
17 
19 
20 import org.projectfloodlight.openflow.types.DatapathId;
21 import org.projectfloodlight.openflow.types.OFPort;
22 import org.restlet.resource.Put;
23 import org.restlet.resource.ServerResource;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26 
27 
28 public class PathDiscover extends ServerResource {
29  protected static Logger logger = LoggerFactory.getLogger(PathDiscover.class);
30 
31  @Put("json")
32  public String sendDiscoverPacket() {
34  (IPathVerificationService) getContext().getAttributes().get(IPathVerificationService.class.getCanonicalName());
35 
36  String srcSwitch = (String) getRequestAttributes().get("src_switch");
37  String port = (String) getRequestAttributes().get("src_port");
38  String dstSwitch = (String) getRequestAttributes().get("dst_switch");
39 
40  logger.debug("asking {} to send a discovery packet out port {} with destination {}.", new Object[]{srcSwitch, port, dstSwitch});
41 
42  if (dstSwitch == null) {
43  DatapathId d = DatapathId.of(srcSwitch);
44  int p = Integer.parseInt(port);
45  pvs.sendDiscoveryMessage(d, OFPort.of(p));
46  } else {
47  pvs.sendDiscoveryMessage(DatapathId.of(srcSwitch), OFPort.of(new Integer(port)), DatapathId.of(dstSwitch));
48  }
49  return null;
50  }
51 }
boolean sendDiscoveryMessage(DatapathId srcSwId, OFPort port)