1 package edu.berkeley.fleet.interpreter;
2 import edu.berkeley.fleet.api.*;
3 import edu.berkeley.fleet.api.BenkoBox;
6 /** anything that has a destination address on the switch fabric */
7 public abstract class InterpreterBenkoBox extends BenkoBox implements InterpreterDestination {
9 private final String name;
10 private final InterpreterShip ship;
11 private final Destination[] ports;
12 private final int addr = max_addr++;
14 public InterpreterBenkoBox(InterpreterShip ship, String name, String[] ports) {
17 this.ports = new Destination[ports.length];
18 for(int i=0; i<ports.length; i++)
22 : new InterpreterBenkoBoxDestination(ports[i]);
25 public Iterable<Destination> getDestinations() {
26 HashSet<Destination> ret = new HashSet<Destination>();
27 for(Destination d : ports) ret.add(d);
31 /** adds the included datum to the port from the switch fabric side */
32 public abstract void addDataFromFabric(Packet packet);
34 abstract void service();
36 abstract void shutdown();
38 public Ship getShip() { return ship; }
39 public Fleet getFleet() { return getShip().getFleet(); }
40 public String toString() { return ship+"."+name; }
41 public String getName() { return name; }
42 public int getInstructionFifoLength() { return 4; }
44 Interpreter getInterpreter() { return ((InterpreterShip)getShip()).getInterpreter(); }
46 public long getDestAddr() { return addr; }
48 private static int max_addr;
50 private class InterpreterBenkoBoxDestination implements InterpreterDestination {
52 public long addr = max_addr++;
53 public InterpreterBenkoBoxDestination(String name) { this.name = name; }
54 public String getDestinationName() { return name; }
55 public Ship getShip() { return InterpreterBenkoBox.this.getShip(); }
56 public void addDataFromFabric(Packet packet) { InterpreterBenkoBox.this.addDataFromFabric(packet); }
57 public String toString() { return getShip()+"."+getName(); }
58 public long getDestAddr() { return addr; }