private VlanId getVlan(JsonNode node) { VlanId vlan = VlanId.NONE; if (!node.path(VLAN).isMissingNode()) { vlan = VlanId.vlanId(node.path(VLAN).asText()); } return vlan; }
private static Set<VlanId> getEntireVlans() { return IntStream.range(0, MAX_VLAN_ID) .filter(x -> !EXCLUDED.contains(x)) .mapToObj(x -> VlanId.vlanId((short) x)) .collect(GuavaCollectors.toImmutableSet()); }
@Override public VlanId vlan() { return VlanId.vlanId(eth.getVlanID()); }
@Override public Criterion decodeCriterion(ObjectNode json) { short vlanId = (short) nullIsIllegal(json.get(CriterionCodec.VLAN_ID), CriterionCodec.VLAN_ID + MISSING_MEMBER_MESSAGE).asInt(); return Criteria.matchVlanId(VlanId.vlanId(vlanId)); } }
@Override public Criterion decodeCriterion(ObjectNode json) { short vlanId = (short) nullIsIllegal(json.get(CriterionCodec.INNER_VLAN_ID), CriterionCodec.INNER_VLAN_ID + MISSING_MEMBER_MESSAGE).asInt(); return Criteria.matchInnerVlanId(VlanId.vlanId(vlanId)); } }
/** * Creates a VLAN identifier Object using the supplied VLAN identifier. * * @param value VLAN identifier expressed as string * @return VLAN identifier */ public static VlanId vlanId(String value) { if (value.equals(STRING_NONE) || value.equals(STRING_NUMERIC_NONE)) { return new VlanId(); } if (value.equals(STRING_ANY)) { return new VlanId(ANY_VALUE); } try { return VlanId.vlanId(Short.parseShort(value)); } catch (NumberFormatException e) { throw new IllegalArgumentException(e); } }
/** * Gets the access device configuration for this device. * * @return access device configuration */ public AccessDeviceData getOlt() { PortNumber uplink = PortNumber.portNumber(node.path(UPLINK).asText()); VlanId vlan = VlanId.vlanId(Short.parseShort(node.path(VLAN).asText())); JsonNode defaultVlanNode = node.path(DEFAULT_VLAN); Optional<VlanId> defaultVlan; if (defaultVlanNode.isMissingNode()) { defaultVlan = Optional.empty(); } else { defaultVlan = Optional.of(VlanId.vlanId(Short.parseShort(defaultVlanNode.asText()))); } return new AccessDeviceData(subject(), uplink, vlan, defaultVlan); } }
private void addTrunkModeToIntf(InterfaceConfig config) { List<VlanId> vlanIds = new ArrayList<>(); for (String vlanString : trunkVlanStrings) { vlanIds.add(VlanId.vlanId(Short.parseShort(vlanString))); } if (config.addTrunkMode(portName, vlanIds)) { print(CONFIG_TRUNK_SUCCESS, vlanIds, uri, portName); } else { print(CONFIG_TRUNK_FAILURE, vlanIds, uri, portName); } }
/** * Gets the access device configuration for this device. * * @return access device configuration */ public AccessDeviceData getAccessDevice() { PortNumber uplink = PortNumber.portNumber(node.path(UPLINK).asText()); VlanId vlan = VlanId.vlanId(Short.parseShort(node.path(VLAN).asText())); JsonNode defaultVlanNode = node.path(DEFAULT_VLAN); Optional<VlanId> defaultVlan; if (defaultVlanNode.isMissingNode()) { defaultVlan = Optional.empty(); } else { defaultVlan = Optional.of(VlanId.vlanId(Short.parseShort(defaultVlanNode.asText()))); } return new AccessDeviceData(subject(), uplink, vlan, defaultVlan); } }
/** * Deserialize circuit id from byte string. * * @param circuitId the circuit id byte string * @return a Circuit Id */ public static CircuitId deserialize(byte[] circuitId) { String cIdString = new String(circuitId, StandardCharsets.US_ASCII); List<String> splittedCircuitId = Lists.newArrayList(cIdString.split(SEPARATOR)); checkArgument(splittedCircuitId.size() > 1, "Illegal circuit id."); // remove last element (vlan id) String vlanId = splittedCircuitId.remove(splittedCircuitId.size() - 1); // Reconstruct device Id String connectPoint = String.join(SEPARATOR, splittedCircuitId); String[] splittedConnectPoint = connectPoint.split(DEVICE_PORT_SEPARATOR); // Check connect point is valid or not checkArgument(splittedConnectPoint.length == 2, "Connect point must be in \"deviceUri/portNumber\" format"); // Check the port number is a number or not UnsignedLongs.decode(splittedConnectPoint[1]); return new CircuitId(connectPoint, VlanId.vlanId(vlanId)); }
@Override public OfdpaSetVlanVid decode(ObjectNode json, CodecContext context) { if (json == null || !json.isObject()) { return null; } // parse ofdpa set vlan vid short vlanVid = (short) nullIsIllegal(json.get(VLAN_ID), VLAN_ID + MISSING_MEMBER_MESSAGE).asInt(); return new OfdpaSetVlanVid(VlanId.vlanId(vlanVid)); } }
@Override public OfdpaMatchVlanVid decode(ObjectNode json, CodecContext context) { if (json == null || !json.isObject()) { return null; } // parse ofdpa match vlan vid short vlanVid = (short) nullIsIllegal(json.get(VLAN_ID), VLAN_ID + MISSING_MEMBER_MESSAGE).asInt(); return new OfdpaMatchVlanVid(VlanId.vlanId(vlanVid)); } }
private void addAccessModeToIntf(InterfaceConfig config) { VlanId accessVlanId = VlanId.vlanId(Short.parseShort(accessVlanString)); if (config.addAccessMode(portName, accessVlanId)) { print(CONFIG_VLAN_SUCCESS, accessVlanId, uri, portName); } else { print(CONFIG_VLAN_FAILURE, accessVlanId, uri, portName); } }
@Override protected void doExecute() { InterfaceAdminService interfaceService = get(InterfaceAdminService.class); List<InterfaceIpAddress> ipAddresses = Lists.newArrayList(); if (ips != null) { for (String strIp : ips) { ipAddresses.add(InterfaceIpAddress.valueOf(strIp)); } } MacAddress macAddr = mac == null ? null : MacAddress.valueOf(mac); VlanId vlanId = vlan == null ? VlanId.NONE : VlanId.vlanId(Short.parseShort(vlan)); Interface intf = new Interface(name, ConnectPoint.deviceConnectPoint(connectPoint), ipAddresses, macAddr, vlanId); interfaceService.add(intf); print("Interface added"); }
@Override public ExtensionTreatment mapAction(OFAction action) throws UnsupportedOperationException { if (action.getType().equals(OFActionType.SET_FIELD)) { OFActionSetField setFieldAction = (OFActionSetField) action; OFOxm<?> oxm = setFieldAction.getField(); switch (oxm.getMatchField().id) { case VLAN_VID: OFOxmVlanVid vlanVid = (OFOxmVlanVid) oxm; return new OfdpaSetVlanVid(VlanId.vlanId(vlanVid.getValue().getRawVid())); default: throw new UnsupportedOperationException( "Driver does not support extension type " + oxm.getMatchField().id); } } throw new UnsupportedOperationException( "Unexpected OFAction: " + action.toString()); }
@Override protected void execute() { NetworkConfigService configService = get(NetworkConfigService.class); CoreService coreService = get(CoreService.class); ApplicationId appId = coreService.getAppId(RoutingService.ROUTER_APP_ID); BgpConfig config = configService.addConfig(appId, BgpConfig.class); if (name != null) { BgpConfig.BgpSpeakerConfig speaker = config.getSpeakerWithName(name); if (speaker != null) { log.debug("Speaker already exists: {}", name); return; } } if (vlanId == null || vlanId.isEmpty()) { vlanIdObj = VlanId.NONE; } else { vlanIdObj = VlanId.vlanId(Short.valueOf(vlanId)); } addSpeakerToConf(config); configService.applyConfig(appId, BgpConfig.class, config.node()); print(SPEAKER_ADD_SUCCESS); }
private FilteredConnectPoint output(DeviceId did, String portNumberStr, String vlanStr) { ConnectPoint cp = new ConnectPoint(did, PortNumber.fromString(portNumberStr)); if (deviceService.getPort(cp) == null) { print("Unknown port: %s", cp); } if (vlanStr == null) { return new FilteredConnectPoint(cp); } else { VlanId vlan = VlanId.vlanId(vlanStr); TrafficSelector sel = DefaultTrafficSelector.builder() .matchVlanId(vlan) .build(); return new FilteredConnectPoint(cp, sel); } }
private int createPeerGroup(MacAddress srcMac, MacAddress dstMac, VlanId vlanId, DeviceId deviceId, PortNumber port) { int nextId = flowObjectiveService.allocateNextId(); NextObjective.Builder nextObjBuilder = DefaultNextObjective.builder() .withId(nextId) .withType(NextObjective.Type.SIMPLE) .fromApp(appId); TrafficTreatment.Builder ttBuilder = DefaultTrafficTreatment.builder(); ttBuilder.setEthSrc(srcMac); ttBuilder.setEthDst(dstMac); ttBuilder.setOutput(port); nextObjBuilder.addTreatment(ttBuilder.build()); TrafficSelector.Builder metabuilder = DefaultTrafficSelector.builder(); VlanId matchVlanId = (vlanId.equals(VlanId.NONE)) ? VlanId.vlanId(SingleSwitchFibInstaller.ASSIGNED_VLAN) : vlanId; metabuilder.matchVlanId(matchVlanId); nextObjBuilder.withMeta(metabuilder.build()); flowObjectiveService.next(deviceId, nextObjBuilder.add()); return nextId; }
private void createMcastFilteringObjective(boolean install, Interface intf) { VlanId assignedVlan = (egressVlan().equals(VlanId.NONE)) ? VlanId.vlanId(ASSIGNED_VLAN) : egressVlan(); FilteringObjective.Builder fob = DefaultFilteringObjective.builder(); // first add filter for the interface fob.withKey(Criteria.matchInPort(intf.connectPoint().port())) .addCondition(Criteria.matchEthDstMasked(MacAddress.IPV4_MULTICAST, MacAddress.IPV4_MULTICAST_MASK)) .addCondition(Criteria.matchVlanId(ingressVlan())); fob.withPriority(PRIORITY_OFFSET); TrafficTreatment tt = DefaultTrafficTreatment.builder() .pushVlan().setVlanId(assignedVlan).build(); fob.withMeta(tt); fob.permit().fromApp(routerAppId); sendFilteringObjective(install, fob, intf); }
private void createFilteringObjective(boolean install, Interface intf) { VlanId assignedVlan = (egressVlan().equals(VlanId.NONE)) ? VlanId.vlanId(ASSIGNED_VLAN) : egressVlan(); FilteringObjective.Builder fob = DefaultFilteringObjective.builder(); // first add filter for the interface fob.withKey(Criteria.matchInPort(intf.connectPoint().port())) .addCondition(Criteria.matchEthDst(intf.mac())) .addCondition(Criteria.matchVlanId(intf.vlan())); fob.withPriority(PRIORITY_OFFSET); if (intf.vlan() == VlanId.NONE) { TrafficTreatment tt = DefaultTrafficTreatment.builder() .pushVlan().setVlanId(assignedVlan).build(); fob.withMeta(tt); } fob.permit().fromApp(routerAppId); sendFilteringObjective(install, fob, intf); if (controlPlaneConnectPoint != null) { // then add the same mac/vlan filters for control-plane connect point fob.withKey(Criteria.matchInPort(controlPlaneConnectPoint.port())); sendFilteringObjective(install, fob, intf); } }