Open Kilda Java Documentation
SwitchUtils.java
Go to the documentation of this file.
1 /* Copyright 2018 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;
17 
18 import net.floodlightcontroller.core.IOFSwitch;
19 import net.floodlightcontroller.core.internal.IOFSwitchService;
20 import org.projectfloodlight.openflow.types.DatapathId;
21 import org.projectfloodlight.openflow.types.MacAddress;
22 
23 import java.util.Arrays;
24 
25 public class SwitchUtils {
26  private final IOFSwitchService switchService;
27 
28  public SwitchUtils(IOFSwitchService switchService) {
29  this.switchService = switchService;
30  }
31 
39  public IOFSwitch lookupSwitch(DatapathId dpId) {
40  IOFSwitch swInfo = switchService.getSwitch(dpId);
41  if (swInfo == null) {
42  throw new IllegalArgumentException(String.format("Switch %s not found", dpId));
43  }
44  return swInfo;
45  }
46 
47  public MacAddress dpIdToMac(final IOFSwitch sw) {
48  return this.dpIdToMac(sw.getId());
49  }
50 
51  public MacAddress dpIdToMac(final DatapathId dpId) {
52  return MacAddress.of(Arrays.copyOfRange(dpId.getBytes(), 2, 8));
53  }
54 }
MacAddress dpIdToMac(final IOFSwitch sw)
MacAddress dpIdToMac(final DatapathId dpId)
IOFSwitch lookupSwitch(DatapathId dpId)
SwitchUtils(IOFSwitchService switchService)
net
Definition: plan-b.py:46